Browse Source

merge in tests from sync

JNI-92
heck 5 years ago
parent
commit
e0df43342e
  1. 1
      test/java/foundation/pEp/jniadapter/test/basic/TestMain.java
  2. 4
      test/java/foundation/pEp/jniadapter/test/jni92/SyncCallbacks.java
  3. 109
      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) {
Engine engine;
TestUtils.log("fds");
// load
try {
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("Subject: " + message.getShortmsg());
TestUtils.log("Attachement[0]: " + message.getAttachments().get(0).toString());
TestUtils.logSectEnd();
TestUtils.logSectEnd("");
}
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("Partner: " + partner);
TestUtils.log("Signal: " + signal);
TestUtils.logSectEnd();
TestUtils.logSectEnd("");
}
}

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

@ -13,71 +13,82 @@ https://pep.foundation/jira/browse/JNI-81
`engine.key_reset_identity` and `engine.setMessageToSendCallback`
*/
class TestThread extends Thread {
private String threadName = "TestThread-1";
private Engine engine = null;
TestThread(String threadName) {
this.threadName = threadName;
Thread.currentThread().setName(threadName);
}
public void run() {
TestUtils.logH1(threadName + ": Starting thread");
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();
}
} catch (Exception e) {
TestUtils.log("Exception in Thread " + threadName);
TestUtils.log(e.toString());
}
TestUtils.sleep(20000);
if(engine.isSyncRunning()) {
engine.stopSync();
}
TestUtils.log(threadName + ": DONE");
TestUtils.logH1( "Thread Starting");
TestMain.TestMainRun(2);
}
}
class TestMain {
public static void main(String[] args) throws Exception {
TestUtils.logH1("JNI-92 Starting");
Vector<TestThread> tts = new Vector<TestThread>();
int nrThreads = 3;
for(int i = 0; i < nrThreads; i++){
tts.add(new TestThread("TestThread-" + i));
public static Engine createNewEngine() throws pEpException {
Engine e;
TestUtils.logH2("Creating new Engine");
e = new Engine();
TestUtils.log("Engine created\n");
return e;
}
public static Vector<Engine> createEngines(int nrEngines) throws pEpException {
Vector<Engine> ev = new Vector<Engine>();
for(int i = 0; i < nrEngines; i++) {
ev.add(createNewEngine());
}
return ev;
}
tts.forEach( t -> {
t.start();
TestUtils.sleep(2000);
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");
});
}
public static void TestMainRun(int nrEngines) {
Vector<Engine> engineVector = TestMain.createEngines(nrEngines);
// TestUtils.sleep(200);
TestMain.own_identities_retrieve_on_EngineVector(engineVector);
}
tts.forEach( t -> {
try {
t.join();
} catch(Exception e ){
TestUtils.log("Exception joining thread" + e.toString());
public static void main(String[] args) throws Exception {
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>();
int nrThreads = nrEngines;
for (int i = 0; i < nrThreads; i++) {
tts.add(new TestThread("TestThread-" + i));
// TestUtils.sleep(200);
}
});
tts.forEach(t -> {
t.start();
// TestUtils.sleep(2000);
});
tts.forEach(t -> {
try {
t.join();
} catch (Exception e) {
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) {
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) {
String decorationStr = getDecoratorString(msg, "=");
System.out.println(decorationStr + " " + msg.toUpperCase() + " " + decorationStr);
log(decorationStr + " " + msg.toUpperCase() + " " + decorationStr);
}
public static void logH2(String msg) {
String decorationStr = getDecoratorString(msg, "-");
System.out.println(decorationStr + " " + msg + " " + decorationStr);
log(decorationStr + " " + msg + " " + decorationStr);
}
private static String getDecoratorString(String msg, String s) {
@ -46,7 +48,7 @@ public class TestUtils {
return decorationStr;
}
public static void logSectEnd() {
System.out.println("");
public static void logSectEnd(String msg) {
log(msg + "\n");
}
}
Loading…
Cancel
Save