Browse Source

Tests: improved Logging, prefix threadName

Test: jni92, single vs multithreaded mass instantiation of Engine
JNI-94
heck 5 years ago
parent
commit
fd686c0f2e
  1. 1
      test/java/foundation/pEp/jniadapter/test/basic/TestMain.java
  2. 4
      test/java/foundation/pEp/jniadapter/test/jni92/SyncCallbacks.java
  3. 85
      test/java/foundation/pEp/jniadapter/test/jni92/TestMain.java
  4. 12
      test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java

1
test/java/foundation/pEp/jniadapter/test/basic/TestMain.java

@ -25,7 +25,6 @@ class TestMain {
public static void main(String[] args) { public static void main(String[] args) {
Engine engine; Engine engine;
TestUtils.log("fds");
// load // load
try { try {
engine = new Engine(); engine = new Engine();

4
test/java/foundation/pEp/jniadapter/test/jni92/SyncCallbacks.java

@ -10,7 +10,7 @@ class SyncCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeC
TestUtils.log("To: " + message.getTo()); TestUtils.log("To: " + message.getTo());
TestUtils.log("Subject: " + message.getShortmsg()); TestUtils.log("Subject: " + message.getShortmsg());
TestUtils.log("Attachement[0]: " + message.getAttachments().get(0).toString()); TestUtils.log("Attachement[0]: " + message.getAttachments().get(0).toString());
TestUtils.logSectEnd(); TestUtils.logSectEnd("");
} }
public void notifyHandshake(Identity myself, Identity partner, SyncHandshakeSignal signal) public void notifyHandshake(Identity myself, Identity partner, SyncHandshakeSignal signal)
@ -19,6 +19,6 @@ class SyncCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeC
TestUtils.log("Myself: " + myself); TestUtils.log("Myself: " + myself);
TestUtils.log("Partner: " + partner); TestUtils.log("Partner: " + partner);
TestUtils.log("Signal: " + signal); TestUtils.log("Signal: " + signal);
TestUtils.logSectEnd(); TestUtils.logSectEnd("");
} }
} }

85
test/java/foundation/pEp/jniadapter/test/jni92/TestMain.java

@ -13,72 +13,83 @@ https://pep.foundation/jira/browse/JNI-81
`engine.key_reset_identity` and `engine.setMessageToSendCallback` `engine.key_reset_identity` and `engine.setMessageToSendCallback`
*/ */
class TestThread extends Thread { class TestThread extends Thread {
private String threadName = "TestThread-1";
private Engine engine = null;
TestThread(String threadName) { TestThread(String threadName) {
this.threadName = threadName; Thread.currentThread().setName(threadName);
} }
public void run() { public void run() {
TestUtils.logH1(threadName + ": Starting thread"); TestUtils.logH1( "Thread Starting");
TestMain.TestMainRun(2);
try {
// load engine
try {
engine = new Engine();
SyncCallbacks callbacks = new SyncCallbacks();
engine.setMessageToSendCallback(callbacks);
engine.setNotifyHandshakeCallback(callbacks);
} catch (pEpException ex) {
TestUtils.log(threadName + ": cannot load");
return;
} }
TestUtils.log(threadName + ": Engine loaded"); }
if(!engine.isSyncRunning()) {
engine.startSync();
class TestMain {
public static Engine createNewEngine() throws pEpException {
Engine e;
TestUtils.logH2("Creating new Engine");
e = new Engine();
TestUtils.log("Engine created\n");
return e;
} }
} catch (Exception e) { public static Vector<Engine> createEngines(int nrEngines) throws pEpException {
TestUtils.log("Exception in Thread " + threadName); Vector<Engine> ev = new Vector<Engine>();
TestUtils.log(e.toString()); for(int i = 0; i < nrEngines; i++) {
ev.add(createNewEngine());
} }
TestUtils.sleep(20000); return ev;
if(engine.isSyncRunning()) {
engine.stopSync();
} }
TestUtils.log(threadName + ": DONE");
public static void own_identities_retrieve_on_EngineVector(Vector<Engine> ev) {
ev.forEach(e -> {
TestUtils.logH2("own_identities_retrieve()");
e.own_identities_retrieve();
TestUtils.log("\n");
});
} }
}
class TestMain { public static void TestMainRun(int nrEngines) {
Vector<Engine> engineVector = TestMain.createEngines(nrEngines);
// TestUtils.sleep(200);
TestMain.own_identities_retrieve_on_EngineVector(engineVector);
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
TestUtils.logH1("JNI-92 Starting"); TestUtils.logH1("JNI-92 Starting");
boolean multiThreaded = true;
int nrEngines = 3;
if (!multiThreaded) {
// Single Threaded
TestMainRun(nrEngines);
} else {
// Mutli Threaded
Vector<TestThread> tts = new Vector<TestThread>(); Vector<TestThread> tts = new Vector<TestThread>();
int nrThreads = 3; int nrThreads = nrEngines;
for(int i = 0; i < nrThreads; i++){ for (int i = 0; i < nrThreads; i++) {
tts.add(new TestThread("TestThread-" + i)); tts.add(new TestThread("TestThread-" + i));
// TestUtils.sleep(200);
} }
tts.forEach( t -> { tts.forEach(t -> {
t.start(); t.start();
TestUtils.sleep(2000); // TestUtils.sleep(2000);
}); });
tts.forEach( t -> { tts.forEach(t -> {
try { try {
t.join(); t.join();
} catch(Exception e ){ } catch (Exception e) {
TestUtils.log("Exception joining thread" + e.toString()); TestUtils.log("Exception joining thread" + e.toString());
} }
}); });
} }
}
} }

12
test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java

@ -23,17 +23,19 @@ public class TestUtils {
} }
public static void log(String msg) { public static void log(String msg) {
System.out.println(msg); String threadNameFmt = String.format("%-10s", Thread.currentThread().getName());
String msgOut = threadNameFmt + ": " + msg;
System.out.println(msgOut);
} }
public static void logH1(String msg) { public static void logH1(String msg) {
String decorationStr = getDecoratorString(msg, "="); String decorationStr = getDecoratorString(msg, "=");
System.out.println(decorationStr + " " + msg.toUpperCase() + " " + decorationStr); log(decorationStr + " " + msg.toUpperCase() + " " + decorationStr);
} }
public static void logH2(String msg) { public static void logH2(String msg) {
String decorationStr = getDecoratorString(msg, "-"); String decorationStr = getDecoratorString(msg, "-");
System.out.println(decorationStr + " " + msg + " " + decorationStr); log(decorationStr + " " + msg + " " + decorationStr);
} }
private static String getDecoratorString(String msg, String s) { private static String getDecoratorString(String msg, String s) {
@ -46,7 +48,7 @@ public class TestUtils {
return decorationStr; return decorationStr;
} }
public static void logSectEnd() { public static void logSectEnd(String msg) {
System.out.println(""); log(msg + "\n");
} }
} }
Loading…
Cancel
Save