@@ -51,7 +51,7 @@ public static void removePreviousTestFolder() {
5151 ASAPEngineFS .removeFolder (TestConstants .ROOT_DIRECTORY + TEST_FOLDER );
5252 }
5353
54- private ASAPTestPeerFS aliceTestPeer , bobTestPeer ;
54+ private ASAPTestPeerFS aliceTestPeer , bobTestPeer , claraTestPeer ;
5555
5656 @ BeforeEach
5757 public void setUp () throws IOException , ASAPException {
@@ -65,6 +65,8 @@ public void setUp() throws IOException, ASAPException {
6565 TestConstants .ALICE_ID , rootfolder + "/" + TestConstants .ALICE_NAME , formats );
6666 this .bobTestPeer = new ASAPTestPeerFS (
6767 TestConstants .BOB_ID , rootfolder + "/" + TestConstants .BOB_NAME , formats );
68+ this .claraTestPeer = new ASAPTestPeerFS (
69+ TestConstants .CLARA_ID , rootfolder + "/" + TestConstants .CLARA_NAME , formats );
6870 }
6971
7072 @ Test
@@ -195,6 +197,49 @@ public void multiEncounter_completelyDifferentURIs() throws InterruptedException
195197 TestConstants .ALICE_ID , exchangedUris [era ][aliceIndex ], era ));
196198 }
197199 }
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+ }
198243
199244 public void simpleEncounterWithMessageExchange (String uriAlice , String uriBob )
200245 throws IOException , ASAPException , InterruptedException {
@@ -206,6 +251,14 @@ public void simpleEncounterWithMessageExchange(String uriAlice, String uriBob)
206251 public void simpleEncounterWithMessageExchange (String uriAlice , String uriBob , int encounterNumber )
207252 throws IOException , ASAPException , InterruptedException {
208253
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+
209262 // simulate ASAP first encounter with full ASAP protocol stack and engines
210263 System .out .println ("+++++++++++++++++++ encounter #" + encounterNumber + " starts soon ++++++++++++++++++++" );
211264 Thread .sleep (50 );
@@ -214,12 +267,12 @@ public void simpleEncounterWithMessageExchange(String uriAlice, String uriBob, i
214267 ASAPMessageReceivedListenerExample aliceMessageReceivedListenerExample =
215268 new ASAPMessageReceivedListenerExample ();
216269
217- aliceTestPeer .addASAPMessageReceivedListener (EXAMPLE_APP_FORMAT , aliceMessageReceivedListenerExample );
270+ peerA .addASAPMessageReceivedListener (EXAMPLE_APP_FORMAT , aliceMessageReceivedListenerExample );
218271
219272 // example - this should be produced by your application
220273 byte [] serializedData = TestUtils .serializeExample (42 , "from alice" , true );
221274
222- aliceTestPeer .sendASAPMessage (EXAMPLE_APP_FORMAT , uriAlice , serializedData );
275+ peerA .sendASAPMessage (EXAMPLE_APP_FORMAT , uriAlice , serializedData );
223276
224277 ///////////////// BOB //////////////////////////////////////////////////////////////
225278
@@ -228,23 +281,23 @@ public void simpleEncounterWithMessageExchange(String uriAlice, String uriBob, i
228281 new ASAPMessageReceivedListenerExample ();
229282
230283 // register your listener (or that mock) with asap connection mock
231- bobTestPeer .addASAPMessageReceivedListener (EXAMPLE_APP_FORMAT , asapMessageReceivedListenerExample );
284+ peerB .addASAPMessageReceivedListener (EXAMPLE_APP_FORMAT , asapMessageReceivedListenerExample );
232285
233286 // bob writes something
234- bobTestPeer .sendASAPMessage (EXAMPLE_APP_FORMAT , uriBob ,
287+ peerB .sendASAPMessage (EXAMPLE_APP_FORMAT , uriBob ,
235288 TestUtils .serializeExample (43 , "from bob" , false ));
236- bobTestPeer .sendASAPMessage (EXAMPLE_APP_FORMAT , uriBob ,
289+ peerB .sendASAPMessage (EXAMPLE_APP_FORMAT , uriBob ,
237290 TestUtils .serializeExample (44 , "from bob again" , false ));
238291
239292 // give your app a moment to process
240293 Thread .sleep (500 );
241294 // start actual encounter
242- aliceTestPeer .startEncounter (TestHelper .getPortNumber (), bobTestPeer );
295+ peerA .startEncounter (TestHelper .getPortNumber (), peerB );
243296
244297 // give your app a moment to process
245298 Thread .sleep (1000 );
246299 // stop encounter
247- bobTestPeer .stopEncounter (aliceTestPeer );
300+ peerB .stopEncounter (peerA );
248301 // give your app a moment to process
249302 Thread .sleep (1000 );
250303 }
0 commit comments