mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Merge topic/actor-system throug a squashed commit.
This commit is contained in:
parent
7a6f5020f6
commit
fe7e1ee7f0
466 changed files with 12559 additions and 9655 deletions
98
testing/btest/broker/remote_event_auto.bro
Normal file
98
testing/btest/broker/remote_event_auto.bro
Normal file
|
@ -0,0 +1,98 @@
|
|||
# @TEST-SERIALIZE: comm
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run recv "bro -b ../recv.bro >recv.out"
|
||||
# @TEST-EXEC: btest-bg-run send "bro -b ../send.bro >send.out"
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-wait 20
|
||||
# @TEST-EXEC: btest-diff recv/recv.out
|
||||
# @TEST-EXEC: btest-diff send/send.out
|
||||
|
||||
@TEST-START-FILE send.bro
|
||||
|
||||
redef Broker::default_connect_retry=1secs;
|
||||
redef Broker::default_listen_retry=1secs;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global event_count = 0;
|
||||
|
||||
global ping: event(msg: string, c: count);
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Broker::subscribe("bro/event/my_topic");
|
||||
Broker::auto_publish("bro/event/my_topic", ping);
|
||||
Broker::peer("127.0.0.1");
|
||||
}
|
||||
|
||||
function send_event()
|
||||
{
|
||||
event ping("my-message", ++event_count);
|
||||
}
|
||||
|
||||
event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string)
|
||||
{
|
||||
print fmt("sender added peer: endpoint=%s msg=%s", endpoint$network$address, msg);
|
||||
send_event();
|
||||
}
|
||||
|
||||
event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string)
|
||||
{
|
||||
print fmt("sender lost peer: endpoint=%s msg=%s", endpoint$network$address, msg);
|
||||
terminate();
|
||||
}
|
||||
|
||||
event pong(msg: string, n: count)
|
||||
{
|
||||
print fmt("sender got pong: %s, %s", msg, n);
|
||||
send_event();
|
||||
}
|
||||
|
||||
@TEST-END-FILE
|
||||
|
||||
|
||||
@TEST-START-FILE recv.bro
|
||||
|
||||
redef Broker::default_connect_retry=1secs;
|
||||
redef Broker::default_listen_retry=1secs;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
const events_to_recv = 5;
|
||||
|
||||
global handler: event(msg: string, c: count);
|
||||
global auto_handler: event(msg: string, c: count);
|
||||
|
||||
global pong: event(msg: string, c: count);
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Broker::subscribe("bro/event/my_topic");
|
||||
Broker::auto_publish("bro/event/my_topic", pong);
|
||||
Broker::listen("127.0.0.1");
|
||||
}
|
||||
|
||||
event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string)
|
||||
{
|
||||
print fmt("receiver added peer: endpoint=%s msg=%s",
|
||||
endpoint$network$address, msg);
|
||||
}
|
||||
|
||||
event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string)
|
||||
{
|
||||
print fmt("receiver lost peer: endpoint=%s msg=%s",
|
||||
endpoint$network$address, msg);
|
||||
}
|
||||
|
||||
event ping(msg: string, n: count)
|
||||
{
|
||||
print fmt("receiver got ping: %s, %s", msg, n);
|
||||
|
||||
if ( n == events_to_recv )
|
||||
{
|
||||
terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
event pong(msg, n);
|
||||
}
|
||||
|
||||
@TEST-END-FILE
|
Loading…
Add table
Add a link
Reference in a new issue