Skip to content

Commit 6351f24

Browse files
committed
snapshot - still working on orchestrated tests; using processes instead of threads now.
1 parent a28e858 commit 6351f24

14 files changed

Lines changed: 180 additions & 128 deletions

src/net/sharksystem/app/messenger/SharkNetMessengerComponentImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public SharkPKIComponent getSharkPKI() {
200200
}
201201

202202
/////////////////////////////////////////////////////////////////////////////////////////////
203-
// act on received messages //
203+
// act on received asap messages //
204204
/////////////////////////////////////////////////////////////////////////////////////////////
205205

206206
@Override

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@ public void run() {
2525
}
2626
else if(uri.toString().equalsIgnoreCase(
2727
SharkNetMessengerAppSupportingDistributedTesting.SCRIPT_RQ_CHANNEL.toString())) {
28-
new Thread(new Runnable() {
29-
@Override
30-
public void run() {
31-
SNMDistributedTestsMessageReceivedListener.this.sharkMessengerAppTestingVersion.
32-
receivedScriptRQ(SharkNetMessengerAppSupportingDistributedTesting.SCRIPT_RQ_CHANNEL);
33-
}
34-
}).start();
28+
// no need for a thread - is already created in asap core
29+
SNMDistributedTestsMessageReceivedListener.this.sharkMessengerAppTestingVersion.
30+
receivedScriptRQ(SharkNetMessengerAppSupportingDistributedTesting.SCRIPT_RQ_CHANNEL);
3531
}
3632
else if(uri.toString().equalsIgnoreCase(
3733
SharkNetMessengerAppSupportingDistributedTesting.TEST_SCRIPT_CHANNEL.toString())) {

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
import net.sharksystem.app.messenger.SharkNetMessengerChannel;
77
import net.sharksystem.app.messenger.SharkNetMessengerException;
88
import net.sharksystem.asap.ASAPException;
9-
import net.sharksystem.ui.messenger.cli.commands.testing.PeerHostingEnvironmentDescription;
10-
import net.sharksystem.ui.messenger.cli.commands.testing.ScriptRunnerThread;
11-
import net.sharksystem.ui.messenger.cli.commands.testing.TestScriptDescription;
9+
import net.sharksystem.ui.messenger.cli.commands.testing.*;
1210
import net.sharksystem.ui.messenger.cli.testlanguage.TestLanguageCompiler;
1311
import net.sharksystem.utils.SerializationHelper;
1412

@@ -70,18 +68,23 @@ else if(contentType.toString().equalsIgnoreCase(TEST_SCRIPT_FORMAT)) {
7068
private List<Thread> blockedThreads = new ArrayList<>(); // a thread can wait for more labels - useful or not
7169
public void block(String label) {
7270
// check if already released
71+
this.tellUI("looking for release label " + label);
7372
while(true) {
7473
for(String receivedLabel : this.receivedLabels) {
7574
if (receivedLabel.equalsIgnoreCase(label)) {
75+
this.tellUI("release label received: " + label);
7676
return; // block released
7777
}
7878
}
7979
try {
8080
this.blockedThreads.add(Thread.currentThread());
81+
this.tellUI("threads sleeps and waits for release label " + label);
8182
Thread.sleep(Long.MAX_VALUE);
8283
} catch (InterruptedException e) {
8384
// new message received - try again
8485
}
86+
this.tellUI("threads woke up - check if release label arrived " + label);
87+
this.blockedThreads.remove(Thread.currentThread());
8588
}
8689
}
8790

@@ -156,11 +159,19 @@ public void receivedTestScript(CharSequence testScriptChannel) {
156159
// for me?
157160
if(testScriptDescription.peerID.equalsIgnoreCase(this.getSharkPeer().getPeerID().toString())) {
158161
this.tellUI("test script received - prepare script runner" + testScriptDescription);
162+
163+
/*
159164
// produce test running thread
160165
new ScriptRunnerThread(
161166
Integer.toString(testScriptDescription.peerIndex),
162167
Integer.toString(testScriptDescription.testNumber),
163168
testScriptDescription.script).start();
169+
*/
170+
// produce test running process
171+
new ScriptRunnerProcess(
172+
Integer.toString(testScriptDescription.peerIndex),
173+
Integer.toString(testScriptDescription.testNumber),
174+
testScriptDescription.script).start();
164175
this.tellUI("running script: " + testScriptDescription.script);
165176
} else {
166177
this.tellUI("test script received, not for me though. Index: " + scriptIndex);
@@ -409,12 +420,26 @@ public void run() {
409420
}
410421

411422
// run orchestrator script first - wait to collect logs
423+
try {
424+
ScriptRunnerProcess scriptRunnerProcess =
425+
scriptRunnerProcess = new ScriptRunnerProcess(ORCHESTRATOR_PEER_NAME,
426+
Integer.toString(this.testNumber), orchestratorScript);
427+
scriptRunnerProcess.start();
428+
} catch (IOException e) {
429+
SharkNetMessengerAppSupportingDistributedTesting.
430+
this.tellUIError("could not start orchestrator process / don't send scripts to peers: "
431+
+ e.getStackTrace());
432+
return;
433+
}
434+
435+
/*
412436
ScriptRunnerThread scriptRunnerThread =
413437
new ScriptRunnerThread(ORCHESTRATOR_PEER_NAME,
414438
Integer.toString(this.testNumber), orchestratorScript);
415439
SharkNetMessengerAppSupportingDistributedTesting.this.tellUI(
416440
"running script as peer " + ORCHESTRATOR_PEER_NAME + ": " + orchestratorScript);
417441
scriptRunnerThread.start();
442+
*/
418443

419444
// now - send script to each peer
420445

src/net/sharksystem/ui/messenger/cli/commands/tcp/UICommandConnectTCP.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ protected UICommandQuestionnaire specifyCommandStructure() {
6262
protected void execute() throws Exception {
6363
try {
6464
this.getSharkMessengerApp().connectTCP(this.hostName.getValue(), this.portNumber.getValue());
65+
this.getSharkMessengerApp().tellUI("connected to "
66+
+ this.hostName.getValue() + ":" + this.portNumber.getValue());
6567
} catch (IOException e) {
6668
this.printErrorMessage(e.getLocalizedMessage());
6769
}

src/net/sharksystem/ui/messenger/cli/commands/tcp/UICommandOpenTCP.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public UICommandOpenTCP(SharkNetMessengerApp sharkMessengerApp, SharkNetMessenge
2020
protected void execute() throws Exception {
2121
try {
2222
this.getSharkMessengerApp().openTCPConnection(this.getIntegerArgument());
23+
this.getSharkMessengerApp().tellUI("TCP port opened: " + this.getIntegerArgument());
2324
} catch (IOException e) {
2425
this.printErrorMessage(e.getLocalizedMessage());
2526
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package net.sharksystem.ui.messenger.cli.commands.testing;
2+
3+
class Helper {
4+
public static final String SNM_CLI_JAR_FILENAME = "SharkNetMessengerCLI.jar";
5+
6+
static String getFriendlyPeerName(String peerName) {
7+
if(peerName.length() != 1) return peerName; // already friendly - hopefully
8+
9+
switch (peerName) {
10+
case "0":
11+
case "A":
12+
return "Alice";
13+
case "1":
14+
case "B":
15+
return "Bob";
16+
case "2":
17+
case "C":
18+
return "Clara";
19+
case "3":
20+
case "D":
21+
return "David";
22+
case "4":
23+
case "E":
24+
return "Eve";
25+
default: return peerName;
26+
}
27+
}
28+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package net.sharksystem.ui.messenger.cli.commands.testing;
2+
3+
import net.sharksystem.hub.peerside.ASAPHubManager;
4+
import net.sharksystem.ui.messenger.cli.ProductionUI;
5+
import net.sharksystem.utils.Log;
6+
7+
import java.io.File;
8+
import java.io.IOException;
9+
10+
public class ScriptRunnerProcess {
11+
private String command;
12+
13+
public ScriptRunnerProcess(String peerName, String testName, String script) throws IOException {
14+
// produce command line to launch a new SNM CLI
15+
peerName = Helper.getFriendlyPeerName(peerName);
16+
17+
StringBuilder sb = new StringBuilder();
18+
sb.append("java -jar ");
19+
sb.append(Helper.SNM_CLI_JAR_FILENAME);
20+
sb.append(" ");
21+
sb.append(peerName + "_" + testName);
22+
sb.append(" ");
23+
sb.append(String.valueOf(ASAPHubManager.DEFAULT_WAIT_INTERVAL_IN_SECONDS));
24+
sb.append(" \"");
25+
sb.append(script);
26+
sb.append("\"");
27+
28+
// a specified system command.
29+
this.command = sb.toString();
30+
}
31+
public void start() throws IOException {
32+
/*
33+
array of strings, each element of which has environment variable settings in the format name=value,
34+
or null if the subprocess should inherit the environment of the current process.
35+
*/
36+
String[] env = null;
37+
38+
/*
39+
the working directory of the subprocess,
40+
or null if the subprocess should inherit the working directory of the current process.
41+
*/
42+
File workingDir = null;
43+
44+
Log.writeLog(this, "launch new process: " + this.command);
45+
System.out.println("launch new process: " + this.command);
46+
Runtime.getRuntime().exec(this.command, env, workingDir);
47+
}
48+
}

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ScriptRunnerThread extends Thread {
1313
ProductionUI ui;
1414

1515
public ScriptRunnerThread(String peerName, String testName, String script) {
16-
this.peerName = ScriptRunnerThread.getFriendlyPeerName(peerName);
16+
this.peerName = Helper.getFriendlyPeerName(peerName);
1717
this.testName = testName;
1818
this.script = script;
1919

@@ -32,27 +32,4 @@ public ScriptRunnerThread(String peerName, String testName, String script) {
3232
public void run() {
3333
this.ui.startCLI(peerName);
3434
}
35-
36-
public static String getFriendlyPeerName(String peerName) {
37-
if(peerName.length() != 1) return peerName; // already friendly - hopefully
38-
39-
switch (peerName) {
40-
case "0":
41-
case "A":
42-
return "Alice";
43-
case "1":
44-
case "B":
45-
return "Bob";
46-
case "2":
47-
case "C":
48-
return "Clara";
49-
case "3":
50-
case "D":
51-
return "David";
52-
case "4":
53-
case "E":
54-
return "Eve";
55-
default: return peerName;
56-
}
57-
}
5835
}

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

Lines changed: 0 additions & 78 deletions
This file was deleted.

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ protected void execute() throws Exception {
2323
*/
2424

2525
// what works - independent tests - no interaction between test peers
26-
// 2025-12-03
27-
String script0_0 = "sendMessage HiFromTest;wait 1000;lsMessages;";
28-
String script0_1 = "sendMessage HiFromTest;wait 1000;lsMessages;";
26+
// 2025-12-03 with thread variant
27+
//
28+
String script0_A = "sendMessage HiFromTest;wait 1000;lsMessages;";
29+
String script0_B = "sendMessage HiFromTest;wait 1000;lsMessages;";
2930

3031
// Orchestrator: orchestrateTest dummy; openTCP 6907
3132
// dann Peers: connectTCP localhost 6907; scriptRQ
@@ -35,6 +36,8 @@ protected void execute() throws Exception {
3536
// check locks - getting even weirder - to test peer names are generated twice?
3637
// There is nothing but a good mystery :)
3738
// what the difference to scenario 0? no additional TCP connections(?)
39+
40+
// going to launch new processes rather new threads: orchestrator (not yet); test peers (not yet)
3841
String script1_A = "wait 5000;connectTCP localhost 9999;release A1;wait 5000;lsMessages;";
3942
String script1_B = "openTCP 9999;block A1;sendMessage HiFromBob;wait 5000;";
4043

@@ -51,7 +54,7 @@ protected void execute() throws Exception {
5154
// fill with example data
5255
this.getSharkMessengerApp().tellUI("use sample data - todo: fill with real data");
5356
// anything will do
54-
scripts.add(script1_A);
57+
scripts.add(script0_A);
5558
scripts.add(script1_B);
5659

5760
this.snmTestSupport.orchestrateTest(scripts);

0 commit comments

Comments
 (0)