Browse Source

FsMQManager: test stateless_ping

JNI-96
heck 5 years ago
parent
commit
086d417c32
  1. 39
      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. 62
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_ping/TestAlice.java
  4. 44
      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

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

@ -49,42 +49,27 @@ 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()) {
TestUtils.sleep(pollInterval);
pollCounter++;
if (pollCounter >= pollRepeats) {
return ret;
}
}
String serializedMsg = onwQueue.remove();
mqMsg = FsMQMessageInternal.deserialize(serializedMsg);
} while (doHandshakeProtocol(mqMsg));
ret = mqMsg.toFsMQMessage();
return ret;
}
private boolean doHandshakeProtocol(FsMQMessageInternal msg) { while (onwQueue.isEmpty()) {
boolean ret = false; TestUtils.sleep(pollInterval);
// pollCounter++;
// if(msg.matches(SYNMSG)) { if (pollCounter >= pollRepeats) {
// return ret;
// } }
// if(msg.matches(SYNACK)) { }
// String serializedMsg = onwQueue.remove();
// } mqMsg = FsMQMessageInternal.deserialize(serializedMsg);
ret = mqMsg.toFsMQMessage();
return ret; return ret;
} }
} }
class FsMQMessageInternal extends FsMQMessage implements java.io.Serializable { class FsMQMessageInternal extends FsMQMessage implements java.io.Serializable {
FsMQHandshakeHeader header = null; FsMQHandshakeHeader header = null;
FsMQMessageInternal(FsMQIdentity from, String msg) throws IllegalStateException { FsMQMessageInternal(FsMQIdentity from, String msg) throws IllegalStateException {
super(from,msg); super(from, msg);
} }
public FsMQHandshakeHeader getHeader() { public FsMQHandshakeHeader getHeader() {
@ -96,7 +81,7 @@ class FsMQMessageInternal extends FsMQMessage implements java.io.Serializable {
} }
public FsMQMessage toFsMQMessage() throws NullPointerException { public FsMQMessage toFsMQMessage() throws NullPointerException {
FsMQMessage ret = new FsMQMessage(this.getFrom(),this.getMsg()); FsMQMessage ret = new FsMQMessage(this.getFrom(), this.getMsg());
return ret; return ret;
} }

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 \

62
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 -> {
try { int pingMax = 10;
String toStr = ctx.qm.identities.getByAddress("Bob").getAddress(); int pingCount = 0;
String msgStr = "Ping"; while (pingCount < pingMax) {
log("TX to: " + toStr); // TX
log(msgStr); String toStr = "Bob";
ctx.qm.sendMessage(toStr, msgStr); String msgTx = "ping";
} catch (IOException e) { try {
assert false :e.toString(); log("TX to:" + toStr);
} log(msgTx);
}); ctx.qm.sendMessage(toStr, msgTx);
} catch (IOException e) {
assert false : e.toString();
}
new TestUnit<FsMQManagerTestContext>("PingPong", testCtx, ctx -> { // RX
try { String fromStr = null;
FsMQMessage msg; String msgRx = null;
while((msg = ctx.qm.receiveMessage(5)) != null) { try {
// RX FsMQMessage msg;
String fromStr = msg.getFrom().getAddress(); while ((msg = ctx.qm.receiveMessage()) == null) {
String msgRx = msg.getMsg(); log("Waiting for ping-reply...");
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();
}
// 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();
} }
}); });

44
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 = null;
String fromStr = msg.getFrom().getAddress(); String msgRx = null;
String msgRx = msg.getMsg(); 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;
log("TX to:" + toStr); try {
log(msgTx); log("TX to:" + toStr);
ctx.qm.sendMessage(fromStr,msgTx); log(msgTx);
ctx.qm.sendMessage(toStr, msgTx);
} catch (IOException e) {
assert false : e.toString();
}
pingCount++;
} }
} catch (IOException e) {
assert false :e.toString();
} catch (ClassNotFoundException e) {
assert false : e.toString();
} }
}); });

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