mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 02:28:21 +00:00
Simplify btests using cluster_started event.
This commit is contained in:
parent
4ddf7562b9
commit
342d88fbd4
30 changed files with 92 additions and 405 deletions
|
@ -10,15 +10,13 @@
|
|||
# @TEST-EXEC: btest-bg-wait 45
|
||||
# @TEST-EXEC: btest-diff manager-1/.stdout
|
||||
|
||||
@load base/frameworks/cluster
|
||||
@load policy/frameworks/cluster/experimental
|
||||
|
||||
@TEST-START-FILE cluster-layout.zeek
|
||||
redef Cluster::nodes = {
|
||||
["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))],
|
||||
["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"],
|
||||
["proxy-2"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1"],
|
||||
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT4")), $manager="manager-1", $interface="eth0"],
|
||||
["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT5")), $manager="manager-1", $interface="eth1"],
|
||||
};
|
||||
@TEST-END-FILE
|
||||
|
||||
|
@ -43,8 +41,6 @@ event zeek_init()
|
|||
my_pool = Cluster::register_pool(my_pool_spec);
|
||||
}
|
||||
|
||||
global proxy_count = 0;
|
||||
|
||||
event go_away()
|
||||
{
|
||||
terminate();
|
||||
|
@ -78,20 +74,14 @@ function print_stuff(heading: string)
|
|||
}
|
||||
}
|
||||
|
||||
event Cluster::node_up(name: string, id: string)
|
||||
event Cluster::Experimental::cluster_started()
|
||||
{
|
||||
if ( Cluster::node != "manager-1" )
|
||||
return;
|
||||
|
||||
if ( name == "proxy-1" || name == "proxy-2" )
|
||||
++proxy_count;
|
||||
|
||||
if ( proxy_count == 2 )
|
||||
{
|
||||
print_stuff("1st stuff");
|
||||
local e = Broker::make_event(go_away);
|
||||
Broker::publish(Cluster::node_topic("proxy-1"), e);
|
||||
}
|
||||
print_stuff("1st stuff");
|
||||
local e = Broker::make_event(go_away);
|
||||
Broker::publish(Cluster::node_topic("proxy-1"), e);
|
||||
}
|
||||
|
||||
event Cluster::node_down(name: string, id: string)
|
||||
|
|
|
@ -10,15 +10,13 @@
|
|||
# @TEST-EXEC: btest-bg-wait 45
|
||||
# @TEST-EXEC: btest-diff manager-1/.stdout
|
||||
|
||||
@load base/frameworks/cluster
|
||||
@load policy/frameworks/cluster/experimental
|
||||
|
||||
@TEST-START-FILE cluster-layout.zeek
|
||||
redef Cluster::nodes = {
|
||||
["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))],
|
||||
["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"],
|
||||
["proxy-2"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1"],
|
||||
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT4")), $manager="manager-1", $interface="eth0"],
|
||||
["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT5")), $manager="manager-1", $interface="eth1"],
|
||||
};
|
||||
@TEST-END-FILE
|
||||
|
||||
|
@ -43,8 +41,6 @@ event zeek_init()
|
|||
my_pool = Cluster::register_pool(my_pool_spec);
|
||||
}
|
||||
|
||||
global proxy_count = 0;
|
||||
|
||||
event go_away()
|
||||
{
|
||||
terminate();
|
||||
|
@ -78,20 +74,14 @@ function print_stuff(heading: string)
|
|||
}
|
||||
}
|
||||
|
||||
event Cluster::node_up(name: string, id: string)
|
||||
event Cluster::Experimental::cluster_started()
|
||||
{
|
||||
if ( Cluster::node != "manager-1" )
|
||||
return;
|
||||
|
||||
if ( name == "proxy-1" || name == "proxy-2" )
|
||||
++proxy_count;
|
||||
|
||||
if ( proxy_count == 2 )
|
||||
{
|
||||
print_stuff("1st stuff");
|
||||
local e = Broker::make_event(go_away);
|
||||
Broker::publish(Cluster::node_topic("proxy-1"), e);
|
||||
}
|
||||
print_stuff("1st stuff");
|
||||
local e = Broker::make_event(go_away);
|
||||
Broker::publish(Cluster::node_topic("proxy-1"), e);
|
||||
}
|
||||
|
||||
event Cluster::node_down(name: string, id: string)
|
||||
|
|
|
@ -1,39 +1,25 @@
|
|||
# @TEST-PORT: BROKER_PORT1
|
||||
# @TEST-PORT: BROKER_PORT2
|
||||
# @TEST-PORT: BROKER_PORT3
|
||||
# @TEST-PORT: BROKER_PORT4
|
||||
# @TEST-PORT: BROKER_PORT5
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run manager-1 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=manager-1 zeek -b %INPUT
|
||||
# @TEST-EXEC: btest-bg-run proxy-1 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=proxy-1 zeek -b %INPUT
|
||||
# @TEST-EXEC: btest-bg-run proxy-2 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=proxy-2 zeek -b %INPUT
|
||||
# @TEST-EXEC: btest-bg-run manager-1 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=manager-1 zeek -B broker -b %INPUT
|
||||
# @TEST-EXEC: btest-bg-run worker-1 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=worker-1 zeek -b %INPUT
|
||||
# @TEST-EXEC: btest-bg-run worker-2 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=worker-2 zeek -b %INPUT
|
||||
# @TEST-EXEC: btest-bg-wait 45
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff manager-1/.stdout
|
||||
# @TEST-EXEC: btest-diff proxy-1/.stdout
|
||||
# @TEST-EXEC: btest-diff proxy-2/.stdout
|
||||
# @TEST-EXEC: btest-diff manager-1/.stdout
|
||||
# @TEST-EXEC: btest-diff worker-1/.stdout
|
||||
# @TEST-EXEC: btest-diff worker-2/.stdout
|
||||
|
||||
@load base/frameworks/cluster
|
||||
@load policy/frameworks/cluster/experimental
|
||||
|
||||
@TEST-START-FILE cluster-layout.zeek
|
||||
redef Cluster::nodes = {
|
||||
["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))],
|
||||
["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"],
|
||||
["proxy-2"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1"],
|
||||
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT4")), $manager="manager-1", $interface="eth0"],
|
||||
["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT5")), $manager="manager-1", $interface="eth1"],
|
||||
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1", $interface="eth0"],
|
||||
["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1", $interface="eth1"],
|
||||
};
|
||||
@TEST-END-FILE
|
||||
|
||||
global fully_connected: event();
|
||||
|
||||
global peer_count = 0;
|
||||
global peers_lost = 0;
|
||||
global fully_connected_nodes = 0;
|
||||
|
||||
redef Broker::forward_messages = T;
|
||||
|
||||
event forwarded_event()
|
||||
|
@ -46,33 +32,17 @@ event forwarded_event()
|
|||
terminate();
|
||||
}
|
||||
|
||||
event ready()
|
||||
event Cluster::Experimental::cluster_started()
|
||||
{
|
||||
# note that the publishing node, worker-1, will not receive the forwarded
|
||||
# event as Broker's forwarding prevents the message going back to the
|
||||
# immediate sender.
|
||||
Broker::publish("test_topic", forwarded_event);
|
||||
}
|
||||
|
||||
event fully_connected()
|
||||
{
|
||||
if ( ! is_remote_event() )
|
||||
return;
|
||||
|
||||
print "Got fully_connected event";
|
||||
fully_connected_nodes = fully_connected_nodes + 1;
|
||||
|
||||
if ( Cluster::node == "manager-1" )
|
||||
{
|
||||
if ( peer_count == 4 && fully_connected_nodes == 4 )
|
||||
Broker::publish(Cluster::node_topic("worker-1"), ready);
|
||||
}
|
||||
if ( Cluster::node == "worker-1" )
|
||||
Broker::publish("test_topic", forwarded_event);
|
||||
}
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
Broker::auto_publish(Cluster::manager_topic, fully_connected);
|
||||
|
||||
if ( Cluster::node == "manager-1" )
|
||||
Broker::forward("test_topic");
|
||||
if ( Cluster::node == "worker-1" )
|
||||
|
@ -81,33 +51,7 @@ event zeek_init()
|
|||
Broker::subscribe("test_topic");
|
||||
}
|
||||
|
||||
event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string)
|
||||
{
|
||||
print "Connected to a peer";
|
||||
peer_count = peer_count + 1;
|
||||
|
||||
if ( Cluster::node == "manager-1" )
|
||||
{
|
||||
if ( peer_count == 4 && fully_connected_nodes == 4 )
|
||||
Broker::publish(Cluster::node_topic("worker-1"), ready);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( peer_count == 3 )
|
||||
event fully_connected();
|
||||
}
|
||||
}
|
||||
|
||||
event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string)
|
||||
{
|
||||
++peers_lost;
|
||||
|
||||
if ( Cluster::node == "manager-1" )
|
||||
{
|
||||
if ( peers_lost == 2 )
|
||||
# Both workers terminated
|
||||
terminate();
|
||||
}
|
||||
else
|
||||
terminate();
|
||||
terminate();
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# @TEST-EXEC: btest-diff logger-1/test.log
|
||||
# @TEST-EXEC: btest-diff logger-10/test.log
|
||||
|
||||
@load base/frameworks/cluster
|
||||
@load policy/frameworks/cluster/experimental
|
||||
|
||||
@TEST-START-FILE cluster-layout.zeek
|
||||
redef Cluster::manager_is_logger = F;
|
||||
|
@ -42,7 +42,6 @@ event zeek_init() &priority=5
|
|||
Log::create_stream(Test::LOG, [$columns=Info, $path="test"]);
|
||||
}
|
||||
|
||||
global peer_count = 0;
|
||||
global c = 0;
|
||||
|
||||
event go_away()
|
||||
|
@ -63,23 +62,17 @@ event do_count()
|
|||
schedule 0.01sec { do_count() };
|
||||
}
|
||||
|
||||
event Cluster::node_up(name: string, id: string)
|
||||
event Cluster::Experimental::cluster_started()
|
||||
{
|
||||
print "node_up", name;
|
||||
++peer_count;
|
||||
if ( Cluster::node != "worker-1" )
|
||||
return;
|
||||
|
||||
if ( Cluster::node == "worker-1" && peer_count == 3 )
|
||||
{
|
||||
Cluster::logger_pool$rr_key_seq["Cluster::rr_log_topic"] = 0;
|
||||
schedule 0.25sec { do_count() };
|
||||
}
|
||||
Cluster::logger_pool$rr_key_seq["Cluster::rr_log_topic"] = 0;
|
||||
schedule 0.25sec { do_count() };
|
||||
}
|
||||
|
||||
event Cluster::node_down(name: string, id: string)
|
||||
{
|
||||
print "node_down", name;
|
||||
--peer_count;
|
||||
|
||||
if ( name == "worker-1" )
|
||||
schedule 2sec { go_away() };
|
||||
}
|
||||
|
|
|
@ -10,20 +10,16 @@
|
|||
# @TEST-EXEC: btest-bg-wait 40
|
||||
# @TEST-EXEC: btest-diff manager-1/.stdout
|
||||
|
||||
@load base/frameworks/cluster
|
||||
@load policy/frameworks/cluster/experimental
|
||||
|
||||
@TEST-START-FILE cluster-layout.zeek
|
||||
redef Cluster::nodes = {
|
||||
["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))],
|
||||
["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"],
|
||||
["proxy-2"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1"],
|
||||
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT4")), $manager="manager-1", $interface="eth0"],
|
||||
["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT5")), $manager="manager-1", $interface="eth1"],
|
||||
};
|
||||
@TEST-END-FILE
|
||||
|
||||
global proxy_count = 0;
|
||||
|
||||
event go_away()
|
||||
{
|
||||
terminate();
|
||||
|
@ -48,20 +44,14 @@ function print_stuff(heading: string)
|
|||
print "hrw", v[i], Cluster::hrw_topic(Cluster::proxy_pool, v[i]);
|
||||
}
|
||||
|
||||
event Cluster::node_up(name: string, id: string)
|
||||
event Cluster::Experimental::cluster_started()
|
||||
{
|
||||
if ( Cluster::node != "manager-1" )
|
||||
return;
|
||||
|
||||
if ( name == "proxy-1" || name == "proxy-2" )
|
||||
++proxy_count;
|
||||
|
||||
if ( proxy_count == 2 )
|
||||
{
|
||||
print_stuff("1st stuff");
|
||||
local e = Broker::make_event(go_away);
|
||||
Broker::publish(Cluster::node_topic("proxy-1"), e);
|
||||
}
|
||||
print_stuff("1st stuff");
|
||||
local e = Broker::make_event(go_away);
|
||||
Broker::publish(Cluster::node_topic("proxy-1"), e);
|
||||
}
|
||||
|
||||
event Cluster::node_down(name: string, id: string)
|
||||
|
|
|
@ -12,19 +12,16 @@
|
|||
# @TEST-EXEC: btest-diff proxy-1/.stdout
|
||||
# @TEST-EXEC: btest-diff proxy-2/.stdout
|
||||
|
||||
@load base/frameworks/cluster
|
||||
@load policy/frameworks/cluster/experimental
|
||||
|
||||
@TEST-START-FILE cluster-layout.zeek
|
||||
redef Cluster::nodes = {
|
||||
["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))],
|
||||
["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"],
|
||||
["proxy-2"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1"],
|
||||
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT4")), $manager="manager-1", $interface="eth0"],
|
||||
["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT5")), $manager="manager-1", $interface="eth1"],
|
||||
};
|
||||
@TEST-END-FILE
|
||||
|
||||
global proxy_count = 0;
|
||||
global q = 0;
|
||||
|
||||
event go_away()
|
||||
|
@ -59,20 +56,14 @@ function send_stuff(heading: string)
|
|||
distributed_event_rr, v[i]);
|
||||
}
|
||||
|
||||
event Cluster::node_up(name: string, id: string)
|
||||
event Cluster::Experimental::cluster_started()
|
||||
{
|
||||
if ( Cluster::node != "manager-1" )
|
||||
return;
|
||||
|
||||
if ( name == "proxy-1" || name == "proxy-2" )
|
||||
++proxy_count;
|
||||
|
||||
if ( proxy_count == 2 )
|
||||
{
|
||||
send_stuff("1st stuff");
|
||||
local e = Broker::make_event(go_away);
|
||||
Broker::publish(Cluster::node_topic("proxy-1"), e);
|
||||
}
|
||||
send_stuff("1st stuff");
|
||||
local e = Broker::make_event(go_away);
|
||||
Broker::publish(Cluster::node_topic("proxy-1"), e);
|
||||
}
|
||||
|
||||
event Cluster::node_down(name: string, id: string)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue