@@ -24,7 +24,12 @@ public class SharkNetMessengerAppSupportingDistributedTesting extends SharkNetMe
2424 public static final String TEST_SCRIPT_FORMAT = "snm/testScript" ;
2525 public static final CharSequence TEST_SCRIPT_CHANNEL = "snm://testScripts" ;
2626
27- public final PeerHostingEnvironmentDescription myEnvironment ;
27+ private PeerHostingEnvironmentDescription myEnvironment ;
28+
29+ private String getLocalIPAddress () throws UnknownHostException {
30+ if (this .myEnvironment == null ) this .myEnvironment = new PeerHostingEnvironmentDescription (this .getPeerName ());
31+ return this .myEnvironment .ipAddress ;
32+ }
2833
2934 public SharkNetMessengerAppSupportingDistributedTesting (String peerName , PrintStream out , PrintStream err )
3035 throws SharkException , IOException {
@@ -38,8 +43,6 @@ public SharkNetMessengerAppSupportingDistributedTesting(String peerName, int syn
3843 // add listener that notifies about test related messages
3944 this .getSharkMessengerComponent ().addSharkMessagesReceivedListener (
4045 new SNMDistributedTestsMessageReceivedListener (this ));
41-
42- this .myEnvironment = new PeerHostingEnvironmentDescription (this .getPeerName ());
4346 }
4447
4548 public String produceStringForMessage (CharSequence contentType , byte [] content ) {
@@ -134,9 +137,10 @@ public void becomeTestPeer() throws IOException, SharkException {
134137
135138 private int lastReceivedScriptIndex = -1 ;
136139 // peers willing to execute test script sent its environment description
137- public void testScriptReceived (CharSequence testScriptChannel ) {
140+ public void receivedTestScript (CharSequence testScriptChannel ) {
138141 if (!this .beTestPeer ) {
139- this .tellUI ("test script received but no tester peer - ignore" );
142+ this .tellUI ("test script received but no tester peer - ignored" );
143+ return ;
140144 }
141145 // add information of this new volunteer and see if we have enough participant for one new test
142146 try {
@@ -157,7 +161,7 @@ public void testScriptReceived(CharSequence testScriptChannel) {
157161 Integer .toString (testScriptDescription .peerIndex ),
158162 Integer .toString (testScriptDescription .testNumber ),
159163 testScriptDescription .script ).start ();
160- this .tellUI ("running script" + testScriptDescription .script );
164+ this .tellUI ("running script: " + testScriptDescription .script );
161165 } else {
162166 this .tellUI ("test script received, not for me though. Index: " + scriptIndex );
163167 }
@@ -214,7 +218,7 @@ public void orchestrateTest(List<PeerHostingEnvironmentDescription> requiredPeer
214218
215219 private int lastScriptRQIndex = -1 ;
216220 // peers willing to execute test script sent its environment description
217- public void scriptRQReceived (CharSequence scriptRQChannel ) {
221+ public void receivedScriptRQ (CharSequence scriptRQChannel ) {
218222 if (!this .beTestOrchestrator ) {
219223 this .tellUI ("script request received - ignore - not a test orchestrator" );
220224 } else {
@@ -298,7 +302,8 @@ private class OrchestratedTestLauncher extends Thread {
298302 public static final String LAUNCH_TEST_TAG_PREAMBLE = "launchTest_" ;
299303 public final static int FINAL_WAIT_PERIODE_BEFORE_LAUNCH = 1000 ;
300304
301- private static String scriptStart_OpenTCP = null ;
305+ private static String scriptStartOrchestrator_SyncWithPeers = null ;
306+ private static String scriptStartPeer_SyncWithOrchestator = null ;
302307 private static String scriptEnd_Exit = null ;
303308
304309 OrchestratedTestLauncher (OrchestratedTest test2run ) throws UnknownHostException {
@@ -307,14 +312,26 @@ private class OrchestratedTestLauncher extends Thread {
307312 this .testNumber = nextTestNumber ++;
308313 }
309314 // init class member
310- if (OrchestratedTestLauncher .scriptStart_OpenTCP == null ) {
315+ if (OrchestratedTestLauncher .scriptStartOrchestrator_SyncWithPeers == null ) {
311316 StringBuilder sb = new StringBuilder ();
312317 sb .append (TestLanguageCompiler .CLI_OPEN_TCP );
313318 sb .append (TestLanguageCompiler .CLI_SPACE );
314319 sb .append (ORCHESTRATOR_PORT );
315320 sb .append (TestLanguageCompiler .LANGUAGE_SEPARATOR );
316- OrchestratedTestLauncher .scriptStart_OpenTCP = sb .toString ();
321+ OrchestratedTestLauncher .scriptStartOrchestrator_SyncWithPeers = sb .toString ();
317322 }
323+
324+ if (OrchestratedTestLauncher .scriptStartPeer_SyncWithOrchestator == null ) {
325+ StringBuilder sb = new StringBuilder ();
326+ sb .append (TestLanguageCompiler .CLI_CONNECT_TCP );
327+ sb .append (TestLanguageCompiler .CLI_SPACE );
328+ sb .append (SharkNetMessengerAppSupportingDistributedTesting .this .getLocalIPAddress ());
329+ sb .append (TestLanguageCompiler .CLI_SPACE );
330+ sb .append (ORCHESTRATOR_PORT );
331+ sb .append (TestLanguageCompiler .LANGUAGE_SEPARATOR );
332+ OrchestratedTestLauncher .scriptStartPeer_SyncWithOrchestator = sb .toString ();
333+ }
334+
318335 if (OrchestratedTestLauncher .scriptEnd_Exit == null ) {
319336 StringBuilder sb = new StringBuilder ();
320337 sb .append (TestLanguageCompiler .LANGUAGE_SEPARATOR );
@@ -333,17 +350,17 @@ public void run() {
333350
334351 // produce orchestrator script - sync and collect data
335352 StringBuilder sb = new StringBuilder ();
336- sb .append (OrchestratedTestLauncher .scriptStart_OpenTCP );
353+ sb .append (OrchestratedTestLauncher .scriptStartOrchestrator_SyncWithPeers );
337354 // wait for each peer to settle
338355 for (int peerIndex = 0 ; peerIndex < this .test2run .scripts .size (); peerIndex ++) {
339356 sb .append (TestLanguageCompiler .CLI_BLOCK );
340357 sb .append (TestLanguageCompiler .CLI_SPACE );
341- // wait for peer to settle - handshake way 1
358+ // wait for peer until settled
342359 sb .append (SETTLED_TAG_PREAMBLE );
343360 sb .append (this .getBlockTag4Peer (peerIndex ));
344361 sb .append (TestLanguageCompiler .CLI_SEPARATOR );
345362 }
346- // release block for each peer
363+ // tell peers to start test
347364 sb .append (TestLanguageCompiler .CLI_RELEASE );
348365 sb .append (TestLanguageCompiler .CLI_SPACE );
349366 // release tag - tell peers to start - handshake way 2
@@ -361,6 +378,10 @@ public void run() {
361378 String [] effectiveScripts = new String [this .test2run .scripts .size ()];
362379 for (int peerIndex = 0 ; peerIndex < this .test2run .scripts .size (); peerIndex ++) {
363380 sb = new StringBuilder ();
381+ // add open connection to orchestrator
382+ sb .append (scriptStartPeer_SyncWithOrchestator );
383+
384+ // tell orchestrator settled:
364385 sb .append (TestLanguageCompiler .CLI_RELEASE );
365386 sb .append (TestLanguageCompiler .CLI_SPACE );
366387 // handshake way 1 - tell orchestrator settled
0 commit comments