Split sync and async into separate script-land namespaces

This commit is contained in:
Tim Wojtulewicz 2025-03-01 15:16:57 -07:00
parent e8074c40d4
commit 28951dccf1
24 changed files with 465 additions and 303 deletions

View file

@ -3,7 +3,7 @@
# @TEST-EXEC: btest-diff out
# @TEST-EXEC: btest-diff .stderr
@load base/frameworks/storage
@load base/frameworks/storage/sync
@load policy/frameworks/storage/backend/sqlite
type Color: enum {
@ -64,11 +64,11 @@ event zeek_init() {
value[2] = "b";
value[3] = "c";
local b = Storage::open_backend(Storage::SQLITE, opts, Rec, tbl);
local b = Storage::Sync::open_backend(Storage::SQLITE, opts, Rec, tbl);
local res = Storage::put(b, [$key=key, $value=value, $async_mode=F]);
local res = Storage::Sync::put(b, [$key=key, $value=value]);
print "put result", res;
local res2 = Storage::get(b, key, F);
local res2 = Storage::Sync::get(b, key);
print "get result", res2;
}

View file

@ -4,7 +4,7 @@
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
@load base/frameworks/storage
@load base/frameworks/storage/sync
@load policy/frameworks/storage/backend/sqlite
# Create a typename here that can be passed down into get().
@ -20,14 +20,14 @@ event zeek_init() {
# Test inserting/retrieving a key/value pair that we know won't be in
# the backend yet.
local b = Storage::open_backend(Storage::SQLITE, opts, str, str);
local b = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str);
local res = Storage::erase(b, key, F);
local res = Storage::Sync::erase(b, key);
print "erase result", res;
local res2 = Storage::get(b, key, F);
local res2 = Storage::Sync::get(b, key);
if ( res2?$error )
print "get result", res2$error;
Storage::close_backend(b);
Storage::Sync::close_backend(b);
}

View file

@ -3,7 +3,7 @@
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
@load base/frameworks/storage
@load base/frameworks/storage/sync
@load policy/frameworks/storage/backend/sqlite
redef Storage::expire_interval = 2 secs;
@ -19,11 +19,11 @@ global value: string = "value7890";
event check_removed() {
# This should return an error from the sqlite backend that there aren't any more
# rows available.
local res2 = Storage::get(backend, key, F);
local res2 = Storage::Sync::get(backend, key);
if ( res2?$error )
print "get result", res2$error;
Storage::close_backend(backend);
Storage::Sync::close_backend(backend);
terminate();
}
@ -32,12 +32,12 @@ event setup_test() {
opts$database_path = "storage-test.sqlite";
opts$table_name = "testing";
backend = Storage::open_backend(Storage::SQLITE, opts, str, str);
backend = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str);
local res = Storage::put(backend, [$key=key, $value=value, $expire_time=2 secs, $async_mode=F]);
local res = Storage::Sync::put(backend, [$key=key, $value=value, $expire_time=2 secs]);
print "put result", res;
local res2 = Storage::get(backend, key, F);
local res2 = Storage::Sync::get(backend, key);
print "get result", res2;
if ( res2?$val )
print "get result same as inserted", value == (res2$val as string);

View file

@ -4,7 +4,7 @@
# @TEST-EXEC: btest-diff out
# @TEST-EXEC: btest-diff .stderr
@load base/frameworks/storage
@load base/frameworks/storage/sync
@load policy/frameworks/storage/backend/sqlite
# Create a typename here that can be passed down into get().
@ -18,15 +18,15 @@ event zeek_init() {
local key = "key1234";
local value = "value7890";
local b = Storage::open_backend(Storage::SQLITE, opts, str, str);
local b = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str);
local res = Storage::put(b, [$key=key, $value=value, $async_mode=F]);
local res = Storage::Sync::put(b, [$key=key, $value=value]);
print "put result", res;
local res2 = Storage::get(b, key, F);
local res2 = Storage::Sync::get(b, key);
print "get result", res2;
if ( res2?$val )
print "get result same as inserted", value == (res2$val as string);
Storage::close_backend(b);
Storage::Sync::close_backend(b);
}

View file

@ -12,7 +12,8 @@
# @TEST-EXEC: btest-diff out
@load base/frameworks/storage
@load base/frameworks/storage/sync
@load base/frameworks/storage/async
@load policy/frameworks/storage/backend/redis
# Create a typename here that can be passed down into open_backend()
@ -28,17 +29,17 @@ event zeek_init() {
local key = "key1234";
local value = "value5678";
local b = Storage::open_backend(Storage::REDIS, opts, str, str);
local b = Storage::Sync::open_backend(Storage::REDIS, opts, str, str);
when [b, key, value] ( local res = Storage::put(b, [$key=key, $value=value]) ) {
when [b, key, value] ( local res = Storage::Async::put(b, [$key=key, $value=value]) ) {
print "put result", res;
when [b, key, value] ( local res2 = Storage::get(b, key) ) {
when [b, key, value] ( local res2 = Storage::Async::get(b, key) ) {
print "get result", res2;
if ( res2?$val )
print "get result same as inserted", value == (res2$val as string);
Storage::close_backend(b);
Storage::Sync::close_backend(b);
}
timeout 5 sec {
print "get requeest timed out";

View file

@ -12,7 +12,8 @@
# @TEST-EXEC: btest-diff out
@load base/frameworks/storage
@load base/frameworks/storage/async
@load base/frameworks/storage/sync
@load policy/frameworks/storage/backend/redis
redef exit_only_after_terminate = T;
@ -30,17 +31,17 @@ event zeek_init() {
local key = "key1234";
local value = "value5678";
local b = Storage::open_backend(Storage::REDIS, opts, str, str);
local b = Storage::Sync::open_backend(Storage::REDIS, opts, str, str);
when [b, key, value] ( local res = Storage::put(b, [$key=key, $value=value]) ) {
when [b, key, value] ( local res = Storage::Async::put(b, [$key=key, $value=value]) ) {
print "put result", res;
when [b, key, value] ( local res2 = Storage::get(b, key) ) {
when [b, key, value] ( local res2 = Storage::Async::get(b, key) ) {
print "get result", res2;
if ( res2?$val )
print "get result same as inserted", value == (res2$val as string);
Storage::close_backend(b);
Storage::Sync::close_backend(b);
terminate();
}

View file

@ -19,7 +19,7 @@
# @TEST-EXEC: btest-diff worker-2/.stdout
# @TEST-EXEC:
@load base/frameworks/storage
@load base/frameworks/storage/sync
@load base/frameworks/cluster
@load policy/frameworks/storage/backend/redis
@load policy/frameworks/cluster/experimental
@ -46,14 +46,14 @@ event zeek_init() {
opts$key_prefix = "testing";
opts$async_mode = F;
backend = Storage::open_backend(Storage::REDIS, opts, str, str);
backend = Storage::Sync::open_backend(Storage::REDIS, opts, str, str);
}
event redis_data_written() {
print "redis_data_written";
local res = Storage::get(backend, "1234", F);
local res = Storage::Sync::get(backend, "1234");
print Cluster::node, res;
Storage::close_backend(backend);
Storage::Sync::close_backend(backend);
terminate();
}
@ -77,7 +77,7 @@ event redis_data_written() {
@if ( Cluster::node == "worker-1" )
event Cluster::Experimental::cluster_started() {
local res = Storage::put(backend, [$key="1234", $value="5678", $async_mode=F]);
local res = Storage::Sync::put(backend, [$key="1234", $value="5678"]);
print Cluster::node, "put result", res;
local e = Cluster::make_event(redis_data_written);

View file

@ -12,7 +12,7 @@
# @TEST-EXEC: btest-diff out
@load base/frameworks/storage
@load base/frameworks/storage/sync
@load policy/frameworks/storage/backend/redis
redef Storage::expire_interval = 2 secs;
@ -26,10 +26,10 @@ global key: string = "key1234";
global value: string = "value7890";
event check_removed() {
local res2 = Storage::get(b, key, F);
local res2 = Storage::Sync::get(b, key);
print "get result after expiration", res2;
Storage::close_backend(b);
Storage::Sync::close_backend(b);
terminate();
}
@ -40,12 +40,12 @@ event setup_test() {
opts$key_prefix = "testing";
opts$async_mode = F;
b = Storage::open_backend(Storage::REDIS, opts, str, str);
b = Storage::Sync::open_backend(Storage::REDIS, opts, str, str);
local res = Storage::put(b, [$key=key, $value=value, $async_mode=F, $expire_time=2 secs]);
local res = Storage::Sync::put(b, [$key=key, $value=value, $expire_time=2 secs]);
print "put result", res;
local res2 = Storage::get(b, key, F);
local res2 = Storage::Sync::get(b, key);
print "get result", res2;
if ( res2?$val )
print "get result same as inserted", value == (res2$val as string);

View file

@ -12,7 +12,7 @@
# @TEST-EXEC: btest-diff out
@load base/frameworks/storage
@load base/frameworks/storage/sync
@load policy/frameworks/storage/backend/redis
# Create a typename here that can be passed down into open_backend()
@ -28,24 +28,24 @@ event zeek_init() {
local key = "key1234";
local value = "value1234";
local b = Storage::open_backend(Storage::REDIS, opts, str, str);
local b = Storage::Sync::open_backend(Storage::REDIS, opts, str, str);
local res = Storage::put(b, [$key=key, $value=value, $async_mode=F]);
local res = Storage::Sync::put(b, [$key=key, $value=value]);
print "put result", res;
local res2 = Storage::get(b, key, F);
local res2 = Storage::Sync::get(b, key);
print "get result", res2;
if ( res2?$val )
print "get result same as inserted", value == (res2$val as string);
local value2 = "value5678";
res = Storage::put(b, [$key=key, $value=value2, $overwrite=T, $async_mode=F]);
res = Storage::Sync::put(b, [$key=key, $value=value2, $overwrite=T]);
print "overwrite put result", res;
res2 = Storage::get(b, key, F);
res2 = Storage::Sync::get(b, key);
print "get result", res2;
if ( res2?$val )
print "get result same as inserted", value2 == (res2$val as string);
Storage::close_backend(b);
Storage::Sync::close_backend(b);
}

View file

@ -3,7 +3,8 @@
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
@load base/frameworks/storage
@load base/frameworks/storage/async
@load base/frameworks/storage/sync
@load policy/frameworks/storage/backend/sqlite
redef exit_only_after_terminate = T;
@ -22,17 +23,17 @@ event zeek_init() {
# Test inserting/retrieving a key/value pair that we know won't be in
# the backend yet.
local b = Storage::open_backend(Storage::SQLITE, opts, str, str);
local b = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str);
when [b, key, value] ( local res = Storage::put(b, [$key=key, $value=value]) ) {
when [b, key, value] ( local res = Storage::Async::put(b, [$key=key, $value=value]) ) {
print "put result", res;
when [b, key, value] ( local res2 = Storage::get(b, key) ) {
when [b, key, value] ( local res2 = Storage::Async::get(b, key) ) {
print "get result", res2;
if ( res2?$val )
print "get result same as inserted", value == (res2$val as string);
Storage::close_backend(b);
Storage::Sync::close_backend(b);
terminate();
}

View file

@ -3,7 +3,7 @@
# @TEST-EXEC: btest-diff out
# @TEST-EXEC: btest-diff .stderr
@load base/frameworks/storage
@load base/frameworks/storage/async
@load policy/frameworks/storage/backend/sqlite
redef exit_only_after_terminate = T;
@ -22,18 +22,18 @@ event zeek_init() {
# Test inserting/retrieving a key/value pair that we know won't be in
# the backend yet.
when [opts, key, value] ( local b = Storage::open_backend(Storage::SQLITE, opts, str, str, T) ) {
when [opts, key, value] ( local b = Storage::Async::open_backend(Storage::SQLITE, opts, str, str) ) {
print "open successful";
when [b, key, value] ( local put_res = Storage::put(b, [$key=key, $value=value]) ) {
when [b, key, value] ( local put_res = Storage::Async::put(b, [$key=key, $value=value]) ) {
print "put result", put_res;
when [b, key, value] ( local get_res = Storage::get(b, key) ) {
when [b, key, value] ( local get_res = Storage::Async::get(b, key) ) {
print "get result", get_res;
if ( get_res?$val )
print "get result same as inserted", value == (get_res$val as string);
when [b] ( local close_res = Storage::close_backend(b, T) ) {
when [b] ( local close_res = Storage::Async::close_backend(b) ) {
print "closed succesfully";
terminate();
} timeout 5 sec {

View file

@ -3,7 +3,7 @@
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
@load base/frameworks/storage
@load base/frameworks/storage/sync
@load base/frameworks/reporter
@load policy/frameworks/storage/backend/sqlite
@ -17,18 +17,18 @@ event zeek_init() {
opts$table_name = "testing";
# This should report an error in .stderr and reporter.log
local b = Storage::open_backend(Storage::SQLITE, opts, str, str);
local b = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str);
# Open a valid database file
opts$database_path = "test.sqlite";
b = Storage::open_backend(Storage::SQLITE, opts, str, str);
b = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str);
local bad_key: count = 12345;
local value = "abcde";
Storage::put(b, [$key=bad_key, $value=value, $async_mode=F]);
Storage::Sync::put(b, [$key=bad_key, $value=value]);
# Close the backend and then attempt to use the closed handle
Storage::close_backend(b);
local res = Storage::put(b, [$key="a", $value="b", $async_mode=F]);
Storage::Sync::close_backend(b);
local res = Storage::Sync::put(b, [$key="a", $value="b"]);
print fmt("Put result on closed handle: %d", res);
}