mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 03:58:20 +00:00
Zeek/Brokerstore updates: first working end-to-end test
This commit fixes a few more loose ends to actually make the Zeek Table<->brokerstore syncing work. This mostly slightly changes the TableVal assign/remove operators to prevent loops when a remote change arrives. The tests inserts a value into a table on the manager, and it pops out in a table on a clone - which is the easiest case. Timeouts are still not handled at all; the behavior when inserting into a clone is untested.
This commit is contained in:
parent
62f208086c
commit
65c12ba6e9
6 changed files with 166 additions and 62 deletions
|
@ -0,0 +1,19 @@
|
|||
Peer added
|
||||
{
|
||||
[b] = 3,
|
||||
[whatever] = 5,
|
||||
[a] = 3
|
||||
}
|
||||
{
|
||||
hi
|
||||
}
|
||||
{
|
||||
[b] = [a=2, b=d, c={
|
||||
elem1,
|
||||
elem2
|
||||
}],
|
||||
[a] = [a=1, b=c, c={
|
||||
elem1,
|
||||
elem2
|
||||
}]
|
||||
}
|
109
testing/btest/broker/store/brokerstore-attr-simple.zeek
Normal file
109
testing/btest/broker/store/brokerstore-attr-simple.zeek
Normal file
|
@ -0,0 +1,109 @@
|
|||
# @TEST-PORT: BROKER_PORT
|
||||
|
||||
# @TEST-EXEC: btest-bg-run master "zeek -B broker -b ../master.zeek >../master.out"
|
||||
# @TEST-EXEC: btest-bg-run clone "zeek -B broker -b ../clone.zeek >../clone.out"
|
||||
# @TEST-EXEC: btest-bg-wait 15
|
||||
#
|
||||
# @TEST-EXEC: btest-diff clone.out
|
||||
|
||||
@TEST-START-FILE master.zeek
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
module TestModule;
|
||||
|
||||
global tablestore: opaque of Broker::Store;
|
||||
global setstore: opaque of Broker::Store;
|
||||
global recordstore: opaque of Broker::Store;
|
||||
|
||||
type testrec: record {
|
||||
a: count;
|
||||
b: string;
|
||||
c: set[string];
|
||||
};
|
||||
|
||||
global t: table[string] of count &broker_store="table";
|
||||
global s: set[string] &broker_store="set";
|
||||
global r: table[string] of testrec &broker_store="rec";
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
Broker::listen("127.0.0.1", to_port(getenv("BROKER_PORT")));
|
||||
tablestore = Broker::create_master("table");
|
||||
setstore = Broker::create_master("set");
|
||||
recordstore = Broker::create_master("rec");
|
||||
}
|
||||
|
||||
event insert_stuff()
|
||||
{
|
||||
print "Inserting stuff";
|
||||
t["a"] = 5;
|
||||
delete t["a"];
|
||||
add s["hi"];
|
||||
t["a"] = 2;
|
||||
t["a"] = 3;
|
||||
t["b"] = 3;
|
||||
t["c"] = 4;
|
||||
t["whatever"] = 5;
|
||||
delete t["c"];
|
||||
r["a"] = testrec($a=1, $b="b", $c=set("elem1", "elem2"));
|
||||
r["a"] = testrec($a=1, $b="c", $c=set("elem1", "elem2"));
|
||||
r["b"] = testrec($a=2, $b="d", $c=set("elem1", "elem2"));
|
||||
print t;
|
||||
print s;
|
||||
print r;
|
||||
}
|
||||
|
||||
event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string)
|
||||
{
|
||||
print "Peer added ", endpoint;
|
||||
schedule 3secs { insert_stuff() };
|
||||
}
|
||||
|
||||
event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
@TEST-END-FILE
|
||||
|
||||
@TEST-START-FILE clone.zeek
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
module TestModule;
|
||||
|
||||
global tablestore: opaque of Broker::Store;
|
||||
global setstore: opaque of Broker::Store;
|
||||
global recordstore: opaque of Broker::Store;
|
||||
|
||||
type testrec: record {
|
||||
a: count;
|
||||
b: string;
|
||||
c: set[string];
|
||||
};
|
||||
|
||||
global t: table[string] of count &broker_store="table";
|
||||
global s: set[string] &broker_store="set";
|
||||
global r: table[string] of testrec &broker_store="rec";
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
Broker::peer("127.0.0.1", to_port(getenv("BROKER_PORT")));
|
||||
}
|
||||
|
||||
event dump_tables()
|
||||
{
|
||||
print t;
|
||||
print s;
|
||||
print r;
|
||||
terminate();
|
||||
}
|
||||
|
||||
event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string)
|
||||
{
|
||||
print "Peer added";
|
||||
tablestore = Broker::create_clone("table");
|
||||
setstore = Broker::create_clone("set");
|
||||
recordstore = Broker::create_clone("rec");
|
||||
schedule 5secs { dump_tables() };
|
||||
}
|
||||
@TEST-END-FILE
|
|
@ -1,34 +0,0 @@
|
|||
# @TEST-EXEC: zeek %INPUT >output
|
||||
# @TEST-EXEC: btest-diff output
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
module TestModule;
|
||||
|
||||
global tablestore: opaque of Broker::Store;
|
||||
#global tabletwostore: opaque of Broker::Store;
|
||||
global setstore: opaque of Broker::Store;
|
||||
|
||||
global t: table[string] of count &broker_store="table";
|
||||
#global ct: table[string, string] of count &broker_store="table2";
|
||||
global s: set[string] &broker_store="set";
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
tablestore = Broker::create_master("table");
|
||||
#tabletwostore = Broker::create_master("table2");
|
||||
setstore = Broker::create_master("set");
|
||||
print "inserting";
|
||||
t["a"] = 5;
|
||||
delete t["a"];
|
||||
#add s["hi"];
|
||||
#print "changing";
|
||||
t["a"] = 2;
|
||||
t["a"] = 3;
|
||||
t["b"] = 3;
|
||||
t["c"] = 4;
|
||||
t["whatever"] = 5;
|
||||
#print "deleting";
|
||||
#delete t["a"];
|
||||
#delete s["hi"];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue