Skip to content

Commit 4c22dd7

Browse files
committed
snapshot - still working on orchestrated tests; more complex test work - there is progress.
1 parent 1f7c7f9 commit 4c22dd7

8 files changed

Lines changed: 117 additions & 13 deletions

File tree

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/net/sharksystem/ui/messenger/cli/ProductionUI.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public ProductionUI(String[] args) throws SharkException, IOException {
154154
smUI.addCommand(new UICommandScriptRQ(snmTestSupport, smUI, "scriptRQ", false));
155155
smUI.addCommand(new UICommandRelease(snmTestSupport, smUI, TestLanguageCompiler.CLI_RELEASE, false));
156156
smUI.addCommand(new UICommandOrchestrateTest(snmTestSupport, smUI, "orchestrateTest", false));
157+
smUI.addCommand(new UICommandTimeBomb(snmTestSupport, smUI, TestLanguageCompiler.CLI_TIME_BOMB, false));
157158

158159
smUI.addCommand(new UICommandSaveLog(sharkMessengerApp, smUI, "saveLog", false));
159160
smUI.addCommand(new UICommandShowLog(sharkMessengerApp, smUI, "showLog", false));

src/net/sharksystem/ui/messenger/cli/SharkNetMessengerAppSupportingDistributedTesting.java

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.sharksystem.asap.ASAPException;
99
import net.sharksystem.ui.messenger.cli.commands.testing.*;
1010
import net.sharksystem.ui.messenger.cli.testlanguage.TestLanguageCompiler;
11+
import net.sharksystem.utils.Log;
1112
import net.sharksystem.utils.SerializationHelper;
1213

1314
import java.io.IOException;
@@ -136,9 +137,11 @@ public void becomeTestPeer() throws IOException, SharkException {
136137
false // no encryption
137138
);
138139
this.tellUI("script request sent: " + scriptRQMessage);
140+
Log.writeLog(this, "script request sent: " + scriptRQMessage);
139141
}
140142

141143
private int lastReceivedScriptIndex = -1;
144+
private List<TestScriptDescription> handledScripts = new ArrayList<>();
142145
// peers willing to execute test script sent its environment description
143146
public void receivedTestScript(CharSequence testScriptChannel) {
144147
if(!this.beTestPeer) {
@@ -149,7 +152,7 @@ public void receivedTestScript(CharSequence testScriptChannel) {
149152
try {
150153
SharkNetMessageList scriptMessages =
151154
this.getSharkMessengerComponent().getChannel(testScriptChannel).getMessages();
152-
for (int scriptIndex = this.lastScriptRQIndex + 1; scriptIndex < scriptMessages.size(); scriptIndex++) {
155+
for (int scriptIndex = this.lastReceivedScriptIndex + 1; scriptIndex < scriptMessages.size(); scriptIndex++) {
153156
this.lastReceivedScriptIndex = scriptIndex; // update each round - before possible exceptions
154157

155158
SharkNetMessage testSharkMessage = scriptMessages.getSharkMessage(scriptIndex, false);
@@ -159,6 +162,23 @@ public void receivedTestScript(CharSequence testScriptChannel) {
159162
// for me?
160163
if(testScriptDescription.peerID.equalsIgnoreCase(this.getSharkPeer().getPeerID().toString())) {
161164
this.tellUI("test script received - prepare script runner" + testScriptDescription);
165+
Log.writeLog(this, "test script addressed to me received: " + testScriptDescription);
166+
167+
// this is script is for - alright. Is it a copy?
168+
boolean copy = false;
169+
for(TestScriptDescription oldScript : this.handledScripts) {
170+
Log.writeLog(this, "copy? " + testScriptDescription + " | " + oldScript);
171+
if(TestScriptDescription.same(oldScript, testScriptDescription)) {
172+
copy = true;
173+
break;
174+
}
175+
}
176+
if(copy) {
177+
String log = "received copy of an already handled test case, ignore: " + testScriptDescription;
178+
Log.writeLog(this, log);
179+
this.tellUI(log);
180+
continue;
181+
}
162182

163183
/*
164184
// produce test running thread
@@ -173,12 +193,17 @@ public void receivedTestScript(CharSequence testScriptChannel) {
173193
Integer.toString(testScriptDescription.testNumber),
174194
testScriptDescription.script).start();
175195
this.tellUI("running script: " + testScriptDescription.script);
196+
Log.writeLog(this, "script running, remember to avoid redo it: " + testScriptDescription);
197+
this.handledScripts.add(testScriptDescription);
176198
} else {
177-
this.tellUI("test script received, not for me though. Index: " + scriptIndex);
199+
this.tellUI("test script received, not for me though. Index: " + testScriptDescription);
200+
Log.writeLog(this, "test script received, not for me: " + testScriptDescription);
178201
}
179202
}
180203
} catch (IOException | SharkException e) {
181-
this.tellUIError("problems handling test script received channel: " + e.getLocalizedMessage());
204+
String log = "problems handling test script received channel: " + e.getLocalizedMessage();
205+
this.tellUIError(log);
206+
Log.writeLogErr(this, log);
182207
}
183208
}
184209

@@ -234,6 +259,7 @@ public void receivedScriptRQ(CharSequence scriptRQChannel) {
234259
this.tellUI("script request received - ignore - not a test orchestrator");
235260
return;
236261
} else {
262+
Log.writeLog(this, "script request received - try to stage a test");
237263
this.tellUI("script request received - try to stage a test");
238264
}
239265
// add information of this new volunteer and see if we have enough participant for one new test
@@ -250,12 +276,16 @@ public void receivedScriptRQ(CharSequence scriptRQChannel) {
250276

251277
// add or replace information
252278
this.availablePeers.put(peerHostDescription.peerID, peerHostDescription);
279+
String log = "added volunteering peer: " + peerHostDescription;
280+
this.tellUI(log);
281+
Log.writeLog(this, log);
253282

254283
// try to set up a test(s).
255284
this.stageTests();
256285
}
257286
} catch (SharkNetMessengerException | IOException | ASAPException e) {
258287
this.tellUIError("problems handling script RQ channel: " + e.getLocalizedMessage());
288+
Log.writeLogErr(this, "problems handling script RQ channel: " + e.getLocalizedMessage());
259289
}
260290
}
261291
}
@@ -266,6 +296,9 @@ private void stageTests() throws UnknownHostException {
266296
do {
267297
testEnsemble = this.findFittingPeers();
268298
if (testEnsemble != null) {
299+
String log = "found enough peers for a new test run: test#" + testEnsemble.waitingTestIndex;
300+
this.tellUI(log);
301+
Log.writeLog(this, log);
269302
// we found an ensemble to run a test
270303
OrchestratedTest waitingTest = this.orchestratedTestsWaiting.get(testEnsemble.waitingTestIndex);
271304
// add actual test ensemble
@@ -292,9 +325,11 @@ private void stageTests() throws UnknownHostException {
292325
if(!this.orchestratedTestsReady.isEmpty()) {
293326
// launch tests
294327
this.tellUI("test staged .. going to launch");
328+
Log.writeLog(this, "test(s) staged .. going to launch");
295329
this.launchTests();
296330
} else {
297331
this.tellUI("couldn't stage a test - not enough peers");
332+
Log.writeLog(this, "couldn't stage a test - not enough peers");
298333
}
299334
}
300335

@@ -313,10 +348,14 @@ private class OrchestratedTestLauncher extends Thread {
313348
public static final String ORCHESTRATOR_PEER_NAME = "orchest";
314349
public static final String LAUNCH_TEST_TAG_PREAMBLE = "launchTest_";
315350
public final static int FINAL_WAIT_PERIODE_BEFORE_LAUNCH = 1000;
351+
public final static int MAX_TEST_DURATION_IN_MILLIS = 10000;
316352

317353
private static String scriptStartOrchestrator_SyncWithPeers = null;
318354
private static String scriptStartPeer_SyncWithOrchestator = null;
319355
private static String scriptEnd_Exit = null;
356+
private static String scriptSetTimeBomb =
357+
TestLanguageCompiler.CLI_TIME_BOMB + TestLanguageCompiler.CLI_SPACE
358+
+ MAX_TEST_DURATION_IN_MILLIS + TestLanguageCompiler.LANGUAGE_SEPARATOR;
320359

321360
OrchestratedTestLauncher(OrchestratedTest test2run) throws UnknownHostException {
322361
this.test2run = test2run;
@@ -390,6 +429,10 @@ public void run() {
390429
String[] effectiveScripts = new String[this.test2run.scripts.size()];
391430
for(int peerIndex = 0; peerIndex < this.test2run.scripts.size(); peerIndex++) {
392431
sb = new StringBuilder();
432+
// set time bomb to avoid orphan processes
433+
SharkNetMessengerAppSupportingDistributedTesting.
434+
this.tellUI("WARNING: set timeBock in each peer script. Adopt this code for longer lasting test scenarios. <<<< WARNING");
435+
sb.append(scriptSetTimeBomb);
393436
// add open connection to orchestrator
394437
sb.append(scriptStartPeer_SyncWithOrchestator);
395438

@@ -420,15 +463,16 @@ public void run() {
420463
}
421464

422465
// run orchestrator script first - wait to collect logs
466+
Log.writeLog(this, "launching orchestrator: ");
423467
try {
424468
ScriptRunnerProcess scriptRunnerProcess =
425469
scriptRunnerProcess = new ScriptRunnerProcess(ORCHESTRATOR_PEER_NAME,
426470
Integer.toString(this.testNumber), orchestratorScript);
427471
scriptRunnerProcess.start();
428472
} catch (IOException e) {
429-
SharkNetMessengerAppSupportingDistributedTesting.
430-
this.tellUIError("could not start orchestrator process / don't send scripts to peers: "
431-
+ e.getStackTrace());
473+
String log = "could not start orchestrator process / don't send scripts to peers: " + e.getStackTrace();
474+
SharkNetMessengerAppSupportingDistributedTesting.this.tellUIError(log);
475+
Log.writeLogErr(this, log);
432476
return;
433477
}
434478

@@ -447,6 +491,7 @@ public void run() {
447491
try { Thread.sleep(1000); } catch (InterruptedException e) {}
448492

449493
SharkNetMessengerAppSupportingDistributedTesting.this.tellUI("sending test scripts to peers");
494+
Log.writeLog(this, "sending test scripts to peers");
450495

451496
try {
452497
for (int i = 0; i < this.test2run.peerEnvironment.size(); i++) {
@@ -468,9 +513,13 @@ public void run() {
468513
false, // no signing
469514
false // no encryption
470515
);
516+
Log.writeLog(this, "sent script: ip | test# | script"
517+
+ peerEnvironment.peerID + " | "
518+
+ this.testNumber + " | "
519+
+ effectiveScripts[i]);
471520

472521
SharkNetMessengerAppSupportingDistributedTesting.this.
473-
tellUI("test scripts sent to " + peerEnvironment.ipAddress);
522+
tellUI("test scripts sent to " + peerEnvironment.peerID + "@" + peerEnvironment.ipAddress);
474523
}
475524
}
476525
catch(IOException | SharkNetMessengerException ioe) {
@@ -487,7 +536,6 @@ private void launchTests() throws UnknownHostException {
487536
while(!this.orchestratedTestsReady.isEmpty()) {
488537
OrchestratedTest readyTest = this.orchestratedTestsReady.remove(0);
489538
OrchestratedTestLauncher readyTestLauncher = new OrchestratedTestLauncher(readyTest);
490-
491539
readyTestLauncher.start();
492540
}
493541
}

src/net/sharksystem/ui/messenger/cli/commands/testing/ScriptRunnerProcess.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@
1010

1111
public class ScriptRunnerProcess {
1212
private final ProcessBuilder pb;
13-
private String command;
1413

1514
public ScriptRunnerProcess(String peerName, String testName, String script) throws IOException {
1615
// produce command line to launch a new SNM CLI
1716
peerName = Helper.getFriendlyPeerName(peerName);
17+
peerName = peerName + "_" + testName;
18+
19+
Log.writeLog(this, "building process: " + peerName + " | " + script);
1820

1921
List<String> args = new ArrayList<>();
2022
args.add("java");
2123
args.add("-jar");
2224
args.add(Helper.SNM_CLI_JAR_FILENAME);
23-
args.add(peerName + "_" + testName);
25+
args.add(peerName);
2426
args.add(String.valueOf(ASAPHubManager.DEFAULT_WAIT_INTERVAL_IN_SECONDS));
25-
args.add("sendMessage Hi;exit");
27+
args.add(script);
2628
this.pb = new ProcessBuilder(args);
2729

2830
File log = new File(peerName + "_uiOutErr.txt");

src/net/sharksystem/ui/messenger/cli/commands/testing/TestScriptDescription.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ public class TestScriptDescription {
1414
public final int testNumber;
1515
public final String peerID;
1616

17+
public static boolean same(TestScriptDescription a, TestScriptDescription b) {
18+
return a.testNumber == b.testNumber
19+
&& a.peerIndex == b.peerIndex
20+
&& a.ipAddress.equalsIgnoreCase(b.ipAddress)
21+
&& a.peerID.equalsIgnoreCase(b.peerID);
22+
}
23+
1724
public TestScriptDescription(String ipAddress, int peerIndex, String script, int testNumber, String peerID) {
1825
this.ipAddress = ipAddress;
1926
this.peerIndex = peerIndex;
@@ -46,6 +53,8 @@ public byte[] getMessageBytes() throws IOException {
4653

4754
public String toString() {
4855
return "ip: " + this.ipAddress + " | peerIndex: " + this.peerIndex
49-
+ " | peerID: " + this.peerID + " | script: " + this.script;
56+
+ " | peerID: " + this.peerID
57+
+ " | test#: " + this.testNumber
58+
+ " | script: " + this.script;
5059
}
5160
}

src/net/sharksystem/ui/messenger/cli/commands/testing/UICommandOrchestrateTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ protected void execute() throws Exception {
4545
scripts.add(script0_A);
4646
scripts.add(script0_B);
4747
*/
48+
4849
scripts.add(script1_A);
4950
scripts.add(script1_B);
5051

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package net.sharksystem.ui.messenger.cli.commands.testing;
2+
3+
import net.sharksystem.SharkException;
4+
import net.sharksystem.ui.messenger.cli.SharkNetMessengerApp;
5+
import net.sharksystem.ui.messenger.cli.SharkNetMessengerUI;
6+
import net.sharksystem.ui.messenger.cli.commands.helper.AbstractCommandNoParameter;
7+
import net.sharksystem.ui.messenger.cli.commands.helper.AbstractCommandWithSingleInteger;
8+
9+
/**
10+
* Command for terminating the messenger.
11+
*/
12+
public class UICommandTimeBomb extends AbstractCommandWithSingleInteger {
13+
public UICommandTimeBomb(SharkNetMessengerApp sharkMessengerApp, SharkNetMessengerUI sharkMessengerUI,
14+
String identifier, boolean rememberCommand) {
15+
super(sharkMessengerApp, sharkMessengerUI, identifier, rememberCommand);
16+
}
17+
18+
@Override
19+
public void execute() throws Exception {
20+
int millis = this.getIntegerArgument();
21+
this.getSharkMessengerApp().tellUI("going to kill this process in " + millis +" ms");
22+
23+
new Thread(new Runnable() {
24+
@Override
25+
public void run() {
26+
try {
27+
Thread.sleep(UICommandTimeBomb.this.getIntegerArgument());
28+
UICommandTimeBomb.this.getSharkMessengerApp().tellUI("max time ended: end CLI for peer " +
29+
UICommandTimeBomb.this.getSharkMessengerApp().getSharkPeer().getPeerID());
30+
} catch (SharkException | InterruptedException e) {
31+
UICommandTimeBomb.this.getSharkMessengerApp().tellUI("max time ended: end CLI");
32+
}
33+
System.exit(0);
34+
}
35+
}).start();
36+
}
37+
38+
@Override
39+
public String getDescription() {
40+
return "Terminates the messenger after some milliseconds";
41+
}
42+
}

src/net/sharksystem/ui/messenger/cli/testlanguage/TestLanguageCompiler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class TestLanguageCompiler {
2020
public static final String CLI_RELEASE = "release";
2121
public static final String CLI_EXIT = "exit";
2222
public static final String CLI_WAIT = "wait";
23+
public static final String CLI_TIME_BOMB = "timeBomb";
2324

2425
/**
2526
* sentence -> command SEPARATOR command

0 commit comments

Comments
 (0)