mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Allow sync methods to be called from when conditions, add related btest
This commit is contained in:
parent
a40db844eb
commit
d0741c8001
3 changed files with 82 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
received termination signal
|
|
@ -0,0 +1,6 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
open result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<opaque of BackendHandleVal>]
|
||||||
|
put result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
||||||
|
get result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=value5678]
|
||||||
|
get result same as inserted, T
|
||||||
|
closed succesfully
|
|
@ -0,0 +1,74 @@
|
||||||
|
# @TEST-DOC: Basic functionality for storage: opening/closing an sqlite backend, storing/retrieving data, using sync methods in when conditions
|
||||||
|
# @TEST-EXEC: zeek -b %INPUT > out
|
||||||
|
# @TEST-EXEC: btest-diff out
|
||||||
|
# @TEST-EXEC: btest-diff .stderr
|
||||||
|
|
||||||
|
@load base/frameworks/storage/sync
|
||||||
|
@load policy/frameworks/storage/backend/sqlite
|
||||||
|
|
||||||
|
redef exit_only_after_terminate = T;
|
||||||
|
|
||||||
|
# Create a typename here that can be passed down into get().
|
||||||
|
type str: string;
|
||||||
|
|
||||||
|
event Storage::backend_opened(tag: string, config: any) {
|
||||||
|
print "Storage::backend_opened", tag, config;
|
||||||
|
}
|
||||||
|
|
||||||
|
event zeek_init()
|
||||||
|
{
|
||||||
|
# Create a database file in the .tmp directory with a 'testing' table
|
||||||
|
local opts: Storage::BackendOptions;
|
||||||
|
opts$sqlite = [ $database_path="test.sqlite", $table_name="testing" ];
|
||||||
|
|
||||||
|
local key = "key1234";
|
||||||
|
local value = "value5678";
|
||||||
|
|
||||||
|
# Test inserting/retrieving a key/value pair that we know won't be in
|
||||||
|
# the backend yet.
|
||||||
|
when [opts, key, value] ( local open_res = Storage::Sync::open_backend(
|
||||||
|
Storage::SQLITE, opts, str, str) )
|
||||||
|
{
|
||||||
|
print "open result", open_res;
|
||||||
|
local b = open_res$value;
|
||||||
|
|
||||||
|
when [b, key, value] ( local put_res = Storage::Sync::put(b, [ $key=key,
|
||||||
|
$value=value ]) )
|
||||||
|
{
|
||||||
|
print "put result", put_res;
|
||||||
|
|
||||||
|
when [b, key, value] ( local get_res = Storage::Sync::get(b, key) )
|
||||||
|
{
|
||||||
|
print "get result", get_res;
|
||||||
|
if ( get_res$code == Storage::SUCCESS && get_res?$value )
|
||||||
|
print "get result same as inserted", value == ( get_res$value as string );
|
||||||
|
|
||||||
|
when [b] ( local close_res = Storage::Sync::close_backend(b) )
|
||||||
|
{
|
||||||
|
print "closed succesfully";
|
||||||
|
terminate();
|
||||||
|
}
|
||||||
|
timeout 5sec
|
||||||
|
{
|
||||||
|
print "close request timed out";
|
||||||
|
terminate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timeout 5sec
|
||||||
|
{
|
||||||
|
print "get request timed out";
|
||||||
|
terminate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timeout 5sec
|
||||||
|
{
|
||||||
|
print "put request timed out";
|
||||||
|
terminate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timeout 5sec
|
||||||
|
{
|
||||||
|
print "open request timed out";
|
||||||
|
terminate();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue