SQLite: Handle automated expiration

This commit is contained in:
Tim Wojtulewicz 2024-08-12 13:23:24 -07:00
parent e95784db16
commit ec49f5d550
5 changed files with 88 additions and 9 deletions

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in /Users/tim/Desktop/projects/storage-framework/testing/btest/.tmp/scripts.base.frameworks.storage.expiration/expiration.zeek, line 20: Failed to retrieve data: Failed to find row for key: no more rows available (Storage::get(backend, to_any_coerce key, F))
received termination signal

View file

@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
put result, T
get result, value7890
get result same as inserted, T
get result, F

View file

@ -0,0 +1,42 @@
# @TEST-DOC: Automatic expiration of stored data
# @TEST-EXEC: zcat <$TRACES/echo-connections.pcap.gz | zeek -b %INPUT > out
# @TEST-EXEC: btest-diff out
# @TEST-EXEC: btest-diff .stderr
@load base/frameworks/storage
@load policy/frameworks/storage/backend/sqlite
redef Storage::expire_interval = 5 secs;
redef exit_only_after_terminate = T;
# Create a typename here that can be passed down into get().
type str: string;
global backend: opaque of Storage::BackendHandle;
global key: string = "key1234";
global value: string = "value7890";
event check_removed() {
local res2 = Storage::get(backend, key, F);
print "get result", res2;
Storage::close_backend(backend);
terminate();
}
event zeek_init() {
local opts : Storage::Backend::SQLite::Options;
opts$database_path = "storage-test.sqlite";
opts$table_name = "testing";
backend = Storage::open_backend(Storage::SQLITE, opts, str, str);
local res = Storage::put(backend, [$key=key, $value=value, $overwrite=T, $expire_time=2 secs, $async_mode=F]);
print "put result", res;
local res2 = Storage::get(backend, key, F);
print "get result", res2;
print "get result same as inserted", value == (res2 as string);
schedule 5 secs { check_removed() };
}