@@ -51,7 +51,7 @@ public static void removePreviousTestFolder() {
51
51
ASAPEngineFS .removeFolder (TestConstants .ROOT_DIRECTORY + TEST_FOLDER );
52
52
}
53
53
54
- private ASAPTestPeerFS aliceTestPeer , bobTestPeer ;
54
+ private ASAPTestPeerFS aliceTestPeer , bobTestPeer , claraTestPeer ;
55
55
56
56
@ BeforeEach
57
57
public void setUp () throws IOException , ASAPException {
@@ -65,6 +65,8 @@ public void setUp() throws IOException, ASAPException {
65
65
TestConstants .ALICE_ID , rootfolder + "/" + TestConstants .ALICE_NAME , formats );
66
66
this .bobTestPeer = new ASAPTestPeerFS (
67
67
TestConstants .BOB_ID , rootfolder + "/" + TestConstants .BOB_NAME , formats );
68
+ this .claraTestPeer = new ASAPTestPeerFS (
69
+ TestConstants .CLARA_ID , rootfolder + "/" + TestConstants .CLARA_NAME , formats );
68
70
}
69
71
70
72
@ Test
@@ -195,6 +197,49 @@ public void multiEncounter_completelyDifferentURIs() throws InterruptedException
195
197
TestConstants .ALICE_ID , exchangedUris [era ][aliceIndex ], era ));
196
198
}
197
199
}
200
+
201
+ @ Test
202
+ public void bugReport_multiHop () throws IOException , ASAPException , InterruptedException {
203
+ simpleEncounterWithMessageExchange (TIGER_URI , ANIMAL );
204
+
205
+ simpleEncounterWithMessageExchange (ANIMAL , ELEPHANT_URI );
206
+
207
+ simpleEncounterWithMessageExchange (HELLO_URI , ANIMAL );
208
+
209
+ simpleEncounterWithMessageExchange (ANIMAL , HELLO_URI );
210
+
211
+ // as always, alice and bob should have received all four messages
212
+ Assertions .assertTrue (senderEraShouldExist (aliceTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , ANIMAL , 0 ));
213
+ Assertions .assertTrue (senderEraShouldExist (aliceTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , ELEPHANT_URI , 1 ));
214
+ Assertions .assertTrue (senderEraShouldExist (aliceTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , ANIMAL , 2 ));
215
+ Assertions .assertTrue (senderEraShouldExist (aliceTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , HELLO_URI , 3 ));
216
+
217
+ Assertions .assertTrue (senderEraShouldExist (bobTestPeer , EXAMPLE_APP_FORMAT , TestConstants .ALICE_ID , TIGER_URI , 0 ));
218
+ Assertions .assertTrue (senderEraShouldExist (bobTestPeer , EXAMPLE_APP_FORMAT , TestConstants .ALICE_ID , ANIMAL , 1 ));
219
+ Assertions .assertTrue (senderEraShouldExist (bobTestPeer , EXAMPLE_APP_FORMAT , TestConstants .ALICE_ID , HELLO_URI , 2 ));
220
+ Assertions .assertTrue (senderEraShouldExist (bobTestPeer , EXAMPLE_APP_FORMAT , TestConstants .ALICE_ID , ANIMAL , 3 ));
221
+
222
+ // check if routing is allowed (should be by default)
223
+ Assertions .assertTrue (aliceTestPeer .isASAPRoutingAllowed (EXAMPLE_APP_FORMAT ));
224
+ // exchange between alice and clara
225
+ simpleEncounterWithMessageExchange (aliceTestPeer , claraTestPeer , "HelloToClara" , "FromClara" , 5 );
226
+ // Alice should have received message from Clara
227
+ Assertions .assertTrue (senderEraShouldExist (aliceTestPeer , EXAMPLE_APP_FORMAT , TestConstants .CLARA_ID , "FromClara" , 0 ));
228
+
229
+ // all messages from Alice should have arrived at Clara
230
+ Assertions .assertTrue (senderEraShouldExist (claraTestPeer , EXAMPLE_APP_FORMAT , TestConstants .ALICE_ID , TIGER_URI , 0 ));
231
+ Assertions .assertTrue (senderEraShouldExist (claraTestPeer , EXAMPLE_APP_FORMAT , TestConstants .ALICE_ID , ANIMAL , 1 ));
232
+ Assertions .assertTrue (senderEraShouldExist (claraTestPeer , EXAMPLE_APP_FORMAT , TestConstants .ALICE_ID , HELLO_URI , 2 ));
233
+ Assertions .assertTrue (senderEraShouldExist (claraTestPeer , EXAMPLE_APP_FORMAT , TestConstants .ALICE_ID , ANIMAL , 3 ));
234
+ Assertions .assertTrue (senderEraShouldExist (claraTestPeer , EXAMPLE_APP_FORMAT ,TestConstants .ALICE_ID , "HelloToClara" , 4 ));
235
+
236
+ // all messages from Bob, which Alice had previously received, should have arrived at Clara
237
+ // BUG: only the first message is routed
238
+ Assertions .assertTrue (senderEraShouldExist (claraTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , ANIMAL , 0 ));
239
+ Assertions .assertTrue (senderEraShouldExist (claraTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , ELEPHANT_URI , 1 ));
240
+ Assertions .assertTrue (senderEraShouldExist (claraTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , ANIMAL , 2 ));
241
+ Assertions .assertTrue (senderEraShouldExist (claraTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , HELLO_URI , 3 ));
242
+ }
198
243
199
244
public void simpleEncounterWithMessageExchange (String uriAlice , String uriBob )
200
245
throws IOException , ASAPException , InterruptedException {
@@ -206,6 +251,14 @@ public void simpleEncounterWithMessageExchange(String uriAlice, String uriBob)
206
251
public void simpleEncounterWithMessageExchange (String uriAlice , String uriBob , int encounterNumber )
207
252
throws IOException , ASAPException , InterruptedException {
208
253
254
+ simpleEncounterWithMessageExchange (aliceTestPeer , bobTestPeer , uriAlice , uriBob , encounterNumber );
255
+ }
256
+
257
+ // send messages with given uri, starts and then stops the encounter
258
+ // message content is irrelevant, we don't test for it
259
+ public void simpleEncounterWithMessageExchange (ASAPTestPeerFS peerA , ASAPTestPeerFS peerB , String uriAlice , String uriBob , int encounterNumber )
260
+ throws IOException , ASAPException , InterruptedException {
261
+
209
262
// simulate ASAP first encounter with full ASAP protocol stack and engines
210
263
System .out .println ("+++++++++++++++++++ encounter #" + encounterNumber + " starts soon ++++++++++++++++++++" );
211
264
Thread .sleep (50 );
@@ -214,12 +267,12 @@ public void simpleEncounterWithMessageExchange(String uriAlice, String uriBob, i
214
267
ASAPMessageReceivedListenerExample aliceMessageReceivedListenerExample =
215
268
new ASAPMessageReceivedListenerExample ();
216
269
217
- aliceTestPeer .addASAPMessageReceivedListener (EXAMPLE_APP_FORMAT , aliceMessageReceivedListenerExample );
270
+ peerA .addASAPMessageReceivedListener (EXAMPLE_APP_FORMAT , aliceMessageReceivedListenerExample );
218
271
219
272
// example - this should be produced by your application
220
273
byte [] serializedData = TestUtils .serializeExample (42 , "from alice" , true );
221
274
222
- aliceTestPeer .sendASAPMessage (EXAMPLE_APP_FORMAT , uriAlice , serializedData );
275
+ peerA .sendASAPMessage (EXAMPLE_APP_FORMAT , uriAlice , serializedData );
223
276
224
277
///////////////// BOB //////////////////////////////////////////////////////////////
225
278
@@ -228,23 +281,23 @@ public void simpleEncounterWithMessageExchange(String uriAlice, String uriBob, i
228
281
new ASAPMessageReceivedListenerExample ();
229
282
230
283
// register your listener (or that mock) with asap connection mock
231
- bobTestPeer .addASAPMessageReceivedListener (EXAMPLE_APP_FORMAT , asapMessageReceivedListenerExample );
284
+ peerB .addASAPMessageReceivedListener (EXAMPLE_APP_FORMAT , asapMessageReceivedListenerExample );
232
285
233
286
// bob writes something
234
- bobTestPeer .sendASAPMessage (EXAMPLE_APP_FORMAT , uriBob ,
287
+ peerB .sendASAPMessage (EXAMPLE_APP_FORMAT , uriBob ,
235
288
TestUtils .serializeExample (43 , "from bob" , false ));
236
- bobTestPeer .sendASAPMessage (EXAMPLE_APP_FORMAT , uriBob ,
289
+ peerB .sendASAPMessage (EXAMPLE_APP_FORMAT , uriBob ,
237
290
TestUtils .serializeExample (44 , "from bob again" , false ));
238
291
239
292
// give your app a moment to process
240
293
Thread .sleep (500 );
241
294
// start actual encounter
242
- aliceTestPeer .startEncounter (TestHelper .getPortNumber (), bobTestPeer );
295
+ peerA .startEncounter (TestHelper .getPortNumber (), peerB );
243
296
244
297
// give your app a moment to process
245
298
Thread .sleep (1000 );
246
299
// stop encounter
247
- bobTestPeer .stopEncounter (aliceTestPeer );
300
+ peerB .stopEncounter (peerA );
248
301
// give your app a moment to process
249
302
Thread .sleep (1000 );
250
303
}
0 commit comments