mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 02:58:20 +00:00
broker integration: add unit test for store clones
This commit is contained in:
parent
05a865a907
commit
441c46df76
9 changed files with 205 additions and 30 deletions
5
testing/btest/Baseline/comm.clone_store/clone.clone.out
Normal file
5
testing/btest/Baseline/comm.clone_store/clone.clone.out
Normal file
|
@ -0,0 +1,5 @@
|
|||
clone keys, [status=Store::SUCCESS, result=[d=broker::data{[one, two, myset, myvec]}]]
|
||||
lookup, one, [status=Store::SUCCESS, result=[d=broker::data{111}]]
|
||||
lookup, two, [status=Store::SUCCESS, result=[d=broker::data{222}]]
|
||||
lookup, myset, [status=Store::SUCCESS, result=[d=broker::data{{a, c, d}}]]
|
||||
lookup, myvec, [status=Store::SUCCESS, result=[d=broker::data{[delta, alpha, beta, gamma, omega]}]]
|
114
testing/btest/comm/clone_store.bro
Normal file
114
testing/btest/comm/clone_store.bro
Normal file
|
@ -0,0 +1,114 @@
|
|||
# @TEST_SERIALIZE: brokercomm
|
||||
# @TEST_REQUIRES: grep -q ENABLE_BROKER $BUILD/CMakeCache.txt
|
||||
|
||||
# @TEST-EXEC: btest-bg-run clone "bro -b ../clone.bro >clone.out"
|
||||
# @TEST-EXEC: btest-bg-run master "bro -b ../master.bro >master.out"
|
||||
|
||||
# @TEST-EXEC: btest-bg-wait 20
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff clone/clone.out
|
||||
# @TEST-EXEC: btest-diff master/master.out
|
||||
|
||||
@TEST-START-FILE clone.bro
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of Store::Handle;
|
||||
global expected_key_count = 4;
|
||||
global key_count = 0;
|
||||
|
||||
event done()
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
function do_lookup(key: string)
|
||||
{
|
||||
when ( local res = Store::lookup(h, Comm::data(key)) )
|
||||
{
|
||||
++key_count;
|
||||
print "lookup", key, res;
|
||||
|
||||
if ( key_count == expected_key_count )
|
||||
event done();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event ready()
|
||||
{
|
||||
h = Store::create_clone("mystore");
|
||||
|
||||
when ( local res = Store::keys(h) )
|
||||
{
|
||||
print "clone keys", res;
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 0)));
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 1)));
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 2)));
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 3)));
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::listen(9999/tcp, "127.0.0.1");
|
||||
Comm::subscribe_to_events("bro/event/ready");
|
||||
Comm::auto_event("bro/event/done", done);
|
||||
}
|
||||
|
||||
@TEST-END-FILE
|
||||
|
||||
@TEST-START-FILE master.bro
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of Store::Handle;
|
||||
|
||||
function dv(d: Comm::Data): Comm::DataVector
|
||||
{
|
||||
local rval: Comm::DataVector;
|
||||
rval[0] = d;
|
||||
return rval;
|
||||
}
|
||||
|
||||
global ready: event();
|
||||
|
||||
event done()
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
event Comm::remote_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
local myset: set[string] = {"a", "b", "c"};
|
||||
local myvec: vector of string = {"alpha", "beta", "gamma"};
|
||||
h = Store::create_master("mystore");
|
||||
Store::insert(h, Comm::data("one"), Comm::data(110));
|
||||
Store::insert(h, Comm::data("two"), Comm::data(223));
|
||||
Store::insert(h, Comm::data("myset"), Comm::data(myset));
|
||||
Store::insert(h, Comm::data("myvec"), Comm::data(myvec));
|
||||
Store::increment(h, Comm::data("one"));
|
||||
Store::decrement(h, Comm::data("two"));
|
||||
Store::add_to_set(h, Comm::data("myset"), Comm::data("d"));
|
||||
Store::remove_from_set(h, Comm::data("myset"), Comm::data("b"));
|
||||
Store::push_left(h, Comm::data("myvec"), dv(Comm::data("delta")));
|
||||
Store::push_right(h, Comm::data("myvec"), dv(Comm::data("omega")));
|
||||
|
||||
when ( local res = Store::size(h) )
|
||||
{ event ready(); }
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::connect("127.0.0.1", 9999/tcp, 1secs);
|
||||
Comm::auto_event("bro/event/ready", ready);
|
||||
Comm::subscribe_to_events("bro/event/done");
|
||||
}
|
||||
|
||||
@TEST-END-FILE
|
Loading…
Add table
Add a link
Reference in a new issue