Skip to content

Commit fbcb3ff

Browse files
committed
Add a typical publish+notify scenario
1 parent 26c3e8f commit fbcb3ff

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
-module(dynamic_domains_pep).
2+
3+
-moduledoc """
4+
Each user performs the following steps:
5+
- Create the domain dynamically when needed (there is one creator per domain)
6+
- Log in to the static/dynamic domain (see dynamic_domains.erl)
7+
- Send presence: available with entity capabilities (see amoc_xmpp_presence.erl)
8+
- Subscribe to next users' presence in order to receive notifications from their nodes
9+
(see amoc_xmpp_presence.erl for details and variables)
10+
- For each owned node, periodically publish items
11+
- Send presence: unavailable and disconnect
12+
13+
See the configuration variables for intervals/delays/item counts.
14+
During the test, incoming PEP item notifications are received, counted, and measured
15+
(see amoc_xmpp_pep.erl)
16+
""".
17+
18+
-include_lib("kernel/include/logger.hrl").
19+
20+
-define(V(X), (fun amoc_config_validation:X/1)).
21+
22+
-required_variable(
23+
[#{name => items_published_per_node, default_value => 60, verification => ?V(nonnegative_integer),
24+
description => "Number of items published for each node"},
25+
#{name => publish_interval, default_value => 10, verification => ?V(nonnegative_integer),
26+
description => "Interval (in seconds) between publishing consecutive items to each node"},
27+
#{name => delay_before_publishing, default_value => 60, verification => ?V(nonnegative_integer),
28+
description => "Delay before publishing the first item (in seconds)"},
29+
#{name => delay_after_publishing, default_value => 60, verification => ?V(nonnegative_integer),
30+
description => "Delay after publishing the last item (in seconds)"}
31+
]).
32+
33+
-behaviour(amoc_scenario).
34+
35+
-export([init/0, start/1]).
36+
37+
-type pep_event() :: {publish_item, binary()}.
38+
39+
-spec init() -> ok.
40+
init() ->
41+
?LOG_INFO("init metrics"),
42+
dynamic_domains:init(),
43+
amoc_xmpp_presence:init(),
44+
amoc_xmpp_pep:init(),
45+
ok.
46+
47+
-spec start(amoc_scenario:user_id()) -> any().
48+
start(MyId) ->
49+
Spec = amoc_xmpp_handlers:make_props(received_handler_spec(), sent_handler_spec()),
50+
{ok, Client, _} = dynamic_domains:connect_or_exit(MyId, Spec),
51+
Nodes = amoc_xmpp_pep:nodes_to_publish(),
52+
start_presence(MyId, Client, Nodes),
53+
do(MyId, Client, Nodes),
54+
amoc_xmpp_presence:stop(Client).
55+
56+
-spec start_presence(amoc_scenario:user_id(), escalus:client(), [binary()]) -> ok.
57+
start_presence(MyId, Client, Nodes) ->
58+
amoc_xmpp_presence:send_presence_available_with_caps(Client, Nodes),
59+
amoc_xmpp_presence:subscribe_to_next_users(Client, MyId).
60+
61+
-spec do(amoc_scenario:user_id(), escalus:client(), [binary()]) -> ok.
62+
do(_MyId, Client, Nodes) ->
63+
escalus_connection:wait(Client, cfg(delay_before_publishing)),
64+
publish_items(Client, Nodes),
65+
escalus_connection:wait(Client, cfg(delay_after_publishing)).
66+
67+
-spec publish_items(escalus:client(), [binary()]) -> ok.
68+
publish_items(Client, Nodes) ->
69+
timetable:do(Client, fun publish_stanza/2, publish_timetable(Nodes)).
70+
71+
-spec publish_timetable([binary()]) -> timetable:timetable(pep_event()).
72+
publish_timetable(Nodes) ->
73+
timetable:merge([node_publish_timetable(Node) || Node <- Nodes]).
74+
75+
-spec node_publish_timetable(binary()) -> timetable:timetable(pep_event()).
76+
node_publish_timetable(Node) ->
77+
timetable:new({publish_item, Node}, cfg(items_published_per_node), cfg(publish_interval)).
78+
79+
-spec publish_stanza(escalus:client(), pep_event()) -> ok.
80+
publish_stanza(Client, {publish_item, Node}) ->
81+
amoc_xmpp_pep:publish_item(Client, Node).
82+
83+
%% Stanza handlers
84+
85+
-spec sent_handler_spec() -> [amoc_xmpp_handlers:handler_spec()].
86+
sent_handler_spec() ->
87+
amoc_xmpp_presence:sent_handler_spec() ++
88+
amoc_xmpp_ping:sent_handler_spec().
89+
90+
-spec received_handler_spec() -> [amoc_xmpp_handlers:handler_spec()].
91+
received_handler_spec() ->
92+
amoc_xmpp_pep:received_handler_spec() ++
93+
amoc_xmpp_presence:received_handler_spec() ++
94+
amoc_xmpp_ping:received_handler_spec().
95+
96+
%% Config helpers
97+
98+
cfg(Name) ->
99+
convert(Name, amoc_config:get(Name)).
100+
101+
convert(delay_before_publishing, V) -> timer:seconds(V);
102+
convert(delay_after_publishing, V) -> timer:seconds(V);
103+
convert(publish_interval, V) -> timer:seconds(V);
104+
convert(_Name, V) -> V.

0 commit comments

Comments
 (0)