Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added second use case for remote groups

  • Loading branch information...
commit 1f1418cf895be9f6532f8ac73eb39ac8b3231919 1 parent 1d78533
Dominik Charousset authored

Showing 1 changed file with 70 additions and 32 deletions. Show diff stats Hide diff stats

  1. +70 32 unit_testing/test__remote_actor.cpp
102 unit_testing/test__remote_actor.cpp
@@ -46,6 +46,67 @@ struct reflector : public event_based_actor {
46 46 }
47 47 };
48 48
  49 +// receive seven reply messages (2 local, 5 remote)
  50 +void spawn5_server(actor_ptr client, bool inverted) {
  51 + group_ptr grp;
  52 + if (!inverted) {
  53 + grp = group::get("local", "foobar");
  54 + }
  55 + else {
  56 + send(client, atom("GetGroup"));
  57 + receive (
  58 + on_arg_match >> [&](const group_ptr& remote_group) {
  59 + grp = remote_group;
  60 + }
  61 + );
  62 + }
  63 + spawn_in_group<reflector>(grp);
  64 + spawn_in_group<reflector>(grp);
  65 + receive_response (sync_send(client, atom("Spawn5"), grp)) (
  66 + on(atom("ok")) >> [&] {
  67 + send(grp, "Hello reflectors!", 5.0);
  68 + },
  69 + after(std::chrono::seconds(10)) >> [&] {
  70 + throw std::runtime_error("timeout");
  71 + }
  72 + );
  73 + // receive seven reply messages (2 local, 5 remote)
  74 + int x = 0;
  75 + receive_for(x, 7) (
  76 + on("Hello reflectors!", 5.0) >> [] { },
  77 + others() >> [&] {
  78 + cout << "unexpected message; "
  79 + << __FILE__ << " line " << __LINE__ << ": "
  80 + << to_string(self->last_dequeued())
  81 + << endl;
  82 + }
  83 + );
  84 + // wait for locally spawned reflectors
  85 + await_all_others_done();
  86 + send(client, atom("Spawn5Done"));
  87 +}
  88 +
  89 +void spawn5_client() {
  90 + bool spawned_reflectors = false;
  91 + do_receive (
  92 + on(atom("Spawn5"), arg_match) >> [&](const group_ptr& grp) {
  93 + for (int i = 0; i < 5; ++i) {
  94 + spawn_in_group<reflector>(grp);
  95 + }
  96 + reply(atom("ok"));
  97 + spawned_reflectors = true;
  98 + },
  99 + on(atom("GetGroup")) >> [] {
  100 + reply(group::get("local", "foobar"));
  101 + }
  102 + ).until(gref(spawned_reflectors));
  103 + await_all_others_done();
  104 + // wait for server
  105 + receive (
  106 + on(atom("Spawn5Done")) >> [] { }
  107 + );
  108 +}
  109 +
49 110 int client_part(const std::vector<string_pair>& args) {
50 111 CPPA_TEST(test__remote_actor_client_part);
51 112 auto i = std::find_if(args.begin(), args.end(),
@@ -104,28 +165,8 @@ int client_part(const std::vector<string_pair>& args) {
104 165 }
105 166 );
106 167 }
107   - // test group communication
108   - auto grp = group::anonymous();
109   - spawn_in_group<reflector>(grp);
110   - spawn_in_group<reflector>(grp);
111   - receive_response (sync_send(server, atom("Spawn5"), grp)) (
112   - on(atom("ok")) >> [&] {
113   - send(grp, "Hello reflectors!", 5.0);
114   - },
115   - after(std::chrono::seconds(10)) >> [&] {
116   - CPPA_ERROR("unexpected timeout!");
117   - }
118   - );
119   - // receive seven reply messages (2 local, 5 remote)
120   - int x = 0;
121   - receive_for(x, 7) (
122   - on("Hello reflectors!", 5.0) >> [] { },
123   - others() >> [&] {
124   - CPPA_ERROR("unexpected message; "
125   - << __FILE__ << " line " << __LINE__ << ": "
126   - << to_string(self->last_dequeued()));
127   - }
128   - );
  168 + spawn5_server(server, false);
  169 + spawn5_client();
129 170 // wait for locally spawned reflectors
130 171 await_all_others_done();
131 172 send(server, atom("farewell"));
@@ -136,6 +177,7 @@ int client_part(const std::vector<string_pair>& args) {
136 177 } // namespace <anonymous>
137 178
138 179 int main(int argc, char** argv) {
  180 + std::cout.unsetf(std::ios_base::unitbuf);
139 181 std::string app_path = argv[0];
140 182 bool run_remote_actor = true;
141 183 if (argc > 1) {
@@ -180,8 +222,10 @@ int main(int argc, char** argv) {
180 222 cout << "actor published at port " << port << endl;
181 223 }
182 224 //cout << "await SpawnPing message" << endl;
  225 + actor_ptr remote_client;
183 226 receive (
184   - on(atom("SpawnPing")) >> []() {
  227 + on(atom("SpawnPing")) >> [&]() {
  228 + remote_client = self->last_sender();
185 229 reply(atom("PingPtr"), spawn_event_based_ping(10));
186 230 }
187 231 );
@@ -214,15 +258,9 @@ int main(int argc, char** argv) {
214 258 );
215 259 cout << "test group communication via network" << endl;
216 260 // group test
217   - receive (
218   - on(atom("Spawn5"), arg_match) >> [](const group_ptr& grp) {
219   - for (int i = 0; i < 5; ++i) {
220   - spawn_in_group<reflector>(grp);
221   - }
222   - reply(atom("ok"));
223   - }
224   - );
225   - await_all_others_done();
  261 + spawn5_client();
  262 + cout << "test group communication via network (inverted setup)" << endl;
  263 + spawn5_server(remote_client, true);
226 264 cout << "wait for a last goodbye" << endl;
227 265 receive (
228 266 on(atom("farewell")) >> [] { }

0 comments on commit 1f1418c

Please sign in to comment.
Something went wrong with that request. Please try again.