mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
SQLite: Handle automated expiration
This commit is contained in:
parent
e95784db16
commit
ec49f5d550
5 changed files with 88 additions and 9 deletions
|
@ -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
|
|
@ -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
|
|
@ -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() };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue