66import java .nio .file .Path ;
77import java .nio .file .Paths ;
88import java .util .List ;
9+ import net .sharksystem .asp3 .ASP3Chunk2Send ;
910import net .sharksystem .asp3 .ASP3Engine ;
1011import net .sharksystem .asp3 .ASP3EngineFS ;
1112import net .sharksystem .asp3 .ASP3Exception ;
1213import net .sharksystem .util .localloop .TCPChannel ;
1314import org .junit .Test ;
1415import net .sharksystem .asp3 .ASP3ChunkStorage ;
16+ import net .sharksystem .asp3 .ASP3ReceivedChunkListener ;
17+ import net .sharksystem .asp3 .ASP3Storage ;
1518import org .junit .Assert ;
1619
1720/**
@@ -94,14 +97,15 @@ public void usage() throws IOException, ASP3Exception, InterruptedException {
9497 aliceChannel .waitForConnection ();
9598 bobChannel .waitForConnection ();
9699
97- // twist and run
100+ // run
98101 ASP3EngineThread aliceEngineThread = new ASP3EngineThread (aliceEngine ,
99102 aliceChannel .getInputStream (),
100- aliceChannel .getOutputStream ());
103+ aliceChannel .getOutputStream (), null );
101104
102105 aliceEngineThread .start ();
103106
104- bobEngine .handleConnection (bobChannel .getInputStream (), bobChannel .getOutputStream ());
107+ bobEngine .handleConnection (bobChannel .getInputStream (),
108+ bobChannel .getOutputStream (), null );
105109
106110 Thread .sleep (10000 );
107111
@@ -124,7 +128,7 @@ public void usage() throws IOException, ASP3Exception, InterruptedException {
124128 }
125129
126130 @ Test
127- public void androidUsage () throws IOException , ASP3Exception {
131+ public void androidUsage () throws IOException , ASP3Exception , InterruptedException {
128132 this .removeDirectory (ALICE_FOLDER ); // clean previous version before
129133 this .removeDirectory (BOB_FOLDER ); // clean previous version before
130134
@@ -145,18 +149,63 @@ public void androidUsage() throws IOException, ASP3Exception {
145149
146150 ASP3Engine bobEngine = ASP3EngineFS .getASP3Engine ("Bob" , BOB_FOLDER );
147151
148- /*
152+ ASP3ChunkReceiverTester aliceListener = new ASP3ChunkReceiverTester ();
153+ ASP3ChunkReceiverTester bobListener = new ASP3ChunkReceiverTester ();
154+
155+ // create connections for both sides
149156 TCPChannel aliceChannel = new TCPChannel (7777 , true , "a2b" );
150157 TCPChannel bobChannel = new TCPChannel (7777 , false , "b2a" );
151158
152159 aliceChannel .start ();
153160 bobChannel .start ();
154161
162+ // wait to connect
155163 aliceChannel .waitForConnection ();
156164 bobChannel .waitForConnection ();
157- */
158-
165+
166+ // run engine as thread
167+ ASP3EngineThread aliceEngineThread = new ASP3EngineThread (aliceEngine ,
168+ aliceChannel .getInputStream (),
169+ aliceChannel .getOutputStream (),
170+ aliceListener );
171+
172+ aliceEngineThread .start ();
173+
174+ // and better debugging - no new thread
175+ bobEngine .handleConnection (bobChannel .getInputStream (),
176+ bobChannel .getOutputStream (), bobListener );
177+
178+ // wait until communication end
179+ Thread .sleep (10000 );
180+
181+ // listener must have been informed about new messages
182+ Assert .assertTrue (aliceListener .chunkReceived ());
183+ Assert .assertTrue (bobListener .chunkReceived ());
184+
185+ // get message alice received
186+ ASP3Storage aliceSenderStored =
187+ aliceStorage .getReceivedChunkStorage (aliceListener .getSender ());
188+
189+ ASP3Chunk2Send aliceReceivedChunk =
190+ aliceSenderStored .getChunk (aliceListener .getUri (),
191+ aliceListener .getEra ());
192+
193+ CharSequence aliceReceivedMessage =
194+ aliceReceivedChunk .getMessages ().next ();
195+
196+ Assert .assertEquals (BOB2ALICE_MESSAGE , aliceReceivedMessage );
159197
198+ // get message bob received
199+ ASP3Storage bobSenderStored =
200+ bobStorage .getReceivedChunkStorage (bobListener .getSender ());
201+
202+ ASP3Chunk2Send bobReceivedChunk =
203+ bobSenderStored .getChunk (bobListener .getUri (),
204+ bobListener .getEra ());
205+
206+ CharSequence bobReceivedMessage =
207+ bobReceivedChunk .getMessages ().next ();
160208
209+ Assert .assertEquals (ALICE2BOB_MESSAGE , bobReceivedMessage );
161210 }
162211}
0 commit comments