Browse Source

FsMQManager: test stateless_ping

JNI-96
heck 5 years ago
parent
commit
086d417c32
  1. 19
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/FsMQManager.java
  2. 2
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_ping/Makefile
  3. 48
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_ping/TestAlice.java
  4. 36
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_ping/TestBob.java
  5. 4
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmsgqueue/FsMsgQueue.java

19
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/FsMQManager.java

@ -49,7 +49,7 @@ public class FsMQManager {
int pollInterval = 100; int pollInterval = 100;
int pollRepeats = timeoutSec * 1000 / pollInterval; int pollRepeats = timeoutSec * 1000 / pollInterval;
int pollCounter = 0; int pollCounter = 0;
do {
while (onwQueue.isEmpty()) { while (onwQueue.isEmpty()) {
TestUtils.sleep(pollInterval); TestUtils.sleep(pollInterval);
pollCounter++; pollCounter++;
@ -59,25 +59,10 @@ public class FsMQManager {
} }
String serializedMsg = onwQueue.remove(); String serializedMsg = onwQueue.remove();
mqMsg = FsMQMessageInternal.deserialize(serializedMsg); mqMsg = FsMQMessageInternal.deserialize(serializedMsg);
} while (doHandshakeProtocol(mqMsg));
ret = mqMsg.toFsMQMessage();
return ret;
}
private boolean doHandshakeProtocol(FsMQMessageInternal msg) {
boolean ret = false;
//
// if(msg.matches(SYNMSG)) {
//
// }
// if(msg.matches(SYNACK)) {
//
// }
ret = mqMsg.toFsMQMessage();
return ret; return ret;
} }
} }
class FsMQMessageInternal extends FsMQMessage implements java.io.Serializable { class FsMQMessageInternal extends FsMQMessage implements java.io.Serializable {

2
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_rxtx_mp/Makefile → test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_ping/Makefile

@ -1,6 +1,6 @@
include ../Makefile.conf include ../Makefile.conf
TEST_UNIT_NAME=stateless_rxtx_mp TEST_UNIT_NAME=stateless_ping
JAVA_CLASSES = \ JAVA_CLASSES = \
TestAlice.class \ TestAlice.class \

48
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_rxtx_mp/TestAlice.java → test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_ping/TestAlice.java

@ -1,4 +1,4 @@
package foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.test.stateless_rxtx_mp; package foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.test.stateless_ping;
import static foundation.pEp.jniadapter.test.framework.TestLogger.*; import static foundation.pEp.jniadapter.test.framework.TestLogger.*;
@ -32,39 +32,43 @@ class TestAlice {
ctx.qm.clearOwnQueue(); ctx.qm.clearOwnQueue();
}); });
new TestUnit<FsMQManagerTestContext>("Initiate PingPong", testCtx, ctx -> { new TestUnit<FsMQManagerTestContext>("Ping initiator", testCtx, ctx -> {
int pingMax = 10;
int pingCount = 0;
while (pingCount < pingMax) {
// TX
String toStr = "Bob";
String msgTx = "ping";
try { try {
String toStr = ctx.qm.identities.getByAddress("Bob").getAddress();
String msgStr = "Ping";
log("TX to:" + toStr); log("TX to:" + toStr);
log(msgStr); log(msgTx);
ctx.qm.sendMessage(toStr, msgStr); ctx.qm.sendMessage(toStr, msgTx);
} catch (IOException e) { } catch (IOException e) {
assert false : e.toString(); assert false : e.toString();
} }
});
new TestUnit<FsMQManagerTestContext>("PingPong", testCtx, ctx -> { // RX
String fromStr = null;
String msgRx = null;
try { try {
FsMQMessage msg; FsMQMessage msg;
while((msg = ctx.qm.receiveMessage(5)) != null) { while ((msg = ctx.qm.receiveMessage()) == null) {
// RX log("Waiting for ping-reply...");
String fromStr = msg.getFrom().getAddress(); TestUtils.sleep(250);
String msgRx = msg.getMsg(); }
fromStr = msg.getFrom().getAddress();
msgRx = msg.getMsg();
log("RX From: " + fromStr); log("RX From: " + fromStr);
log(msgRx); log(msgRx);
} catch (Exception e) {
assert false : e.toString();
}
// TX if (fromStr.equals(toStr)) {
String toStr = fromStr; if (msgRx.equals(msgTx)) {
String msgTx = ctx.getMessages().get(0) + msgRx; pingCount++;
log("TX to:" + toStr); }
log(msgTx);
ctx.qm.sendMessage(fromStr,msgTx);
} }
} catch (IOException e) {
assert false :e.toString();
} catch (ClassNotFoundException e) {
assert false : e.toString();
} }
}); });

36
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_rxtx_mp/TestBob.java → test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_ping/TestBob.java

@ -1,4 +1,4 @@
package foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.test.stateless_rxtx_mp; package foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.test.stateless_ping;
import static foundation.pEp.jniadapter.test.framework.TestLogger.*; import static foundation.pEp.jniadapter.test.framework.TestLogger.*;
@ -32,27 +32,41 @@ class TestBob {
ctx.qm.clearOwnQueue(); ctx.qm.clearOwnQueue();
}); });
new TestUnit<FsMQManagerTestContext>("PingPong", testCtx, ctx -> { new TestUnit<FsMQManagerTestContext>("Ping responder", testCtx, ctx -> {
try { int pingMax = 10;
int pingCount = 0;
while(pingCount < pingMax) {
FsMQMessage msg; FsMQMessage msg;
while((msg = ctx.qm.receiveMessage(5)) != null) {
// RX // RX
String fromStr = msg.getFrom().getAddress(); String fromStr = null;
String msgRx = msg.getMsg(); String msgRx = null;
try {
while ((msg = ctx.qm.receiveMessage()) == null) {
log("Waiting for ping...");
TestUtils.sleep(250);
}
fromStr = msg.getFrom().getAddress();
msgRx = msg.getMsg();
log("RX From: " + fromStr); log("RX From: " + fromStr);
log(msgRx); log(msgRx);
} catch (Exception e) {
assert false : e.toString();
}
if(msgRx.equals("ping")) {
// TX // TX
String toStr = fromStr; String toStr = fromStr;
String msgTx = ctx.getMessages().get(0) + msgRx; String msgTx = msgRx;
try {
log("TX to:" + toStr); log("TX to:" + toStr);
log(msgTx); log(msgTx);
ctx.qm.sendMessage(fromStr,msgTx); ctx.qm.sendMessage(toStr, msgTx);
}
} catch (IOException e) { } catch (IOException e) {
assert false : e.toString(); assert false : e.toString();
} catch (ClassNotFoundException e) { }
assert false : e.toString(); pingCount++;
}
} }
}); });

4
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmsgqueue/FsMsgQueue.java

@ -51,7 +51,7 @@ public class FsMsgQueue implements Queue<String> {
String filename = getNewFilename(); String filename = getNewFilename();
String path = qDir + "/" + filename; String path = qDir + "/" + filename;
// check file not existing yet. // check file not existing yet.
log("Adding msg file:" + filename); // log("Adding msg file:" + filename);
File file = new File(path); File file = new File(path);
if(!file.exists()) { if(!file.exists()) {
@ -237,7 +237,7 @@ public class FsMsgQueue implements Queue<String> {
private Pair<File, String> get() throws Exception { private Pair<File, String> get() throws Exception {
Pair<File, String> ret = null; Pair<File, String> ret = null;
File oldestFile = getOldestMsgFilename(); File oldestFile = getOldestMsgFilename();
log("reading file:" + oldestFile.getName()); // log("reading file:" + oldestFile.getName());
if (oldestFile == null) { if (oldestFile == null) {
throw new NoSuchElementException("No .msg file in dir: " + qDir); throw new NoSuchElementException("No .msg file in dir: " + qDir);
} else { } else {

Loading…
Cancel
Save