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 pollRepeats = timeoutSec * 1000 / pollInterval;
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) {
boolean ret = false;
//
// if(msg.matches(SYNMSG)) {
//
// }
// if(msg.matches(SYNACK)) {
//
// }
while (onwQueue.isEmpty()) {
TestUtils.sleep(pollInterval);
pollCounter++;
if (pollCounter >= pollRepeats) {
return ret;
}
}
String serializedMsg = onwQueue.remove();
mqMsg = FsMQMessageInternal.deserialize(serializedMsg);
ret = mqMsg.toFsMQMessage();
return ret;
}
}
class FsMQMessageInternal extends FsMQMessage implements java.io.Serializable {
FsMQHandshakeHeader header = null;
FsMQMessageInternal(FsMQIdentity from, String msg) throws IllegalStateException {
super(from,msg);
super(from, msg);
}
public FsMQHandshakeHeader getHeader() {
@ -96,7 +81,7 @@ class FsMQMessageInternal extends FsMQMessage implements java.io.Serializable {
}
public FsMQMessage toFsMQMessage() throws NullPointerException {
FsMQMessage ret = new FsMQMessage(this.getFrom(),this.getMsg());
FsMQMessage ret = new FsMQMessage(this.getFrom(), this.getMsg());
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
TEST_UNIT_NAME=stateless_rxtx_mp
TEST_UNIT_NAME=stateless_ping
JAVA_CLASSES = \
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.*;
@ -32,39 +32,43 @@ class TestAlice {
ctx.qm.clearOwnQueue();
});
new TestUnit<FsMQManagerTestContext>("Initiate PingPong", testCtx, ctx -> {
try {
String toStr = ctx.qm.identities.getByAddress("Bob").getAddress();
String msgStr = "Ping";
log("TX to: " + toStr);
log(msgStr);
ctx.qm.sendMessage(toStr, msgStr);
} catch (IOException e) {
assert false :e.toString();
}
});
new TestUnit<FsMQManagerTestContext>("Ping initiator", testCtx, ctx -> {
int pingMax = 10;
int pingCount = 0;
while (pingCount < pingMax) {
// TX
String toStr = "Bob";
String msgTx = "ping";
try {
log("TX to:" + toStr);
log(msgTx);
ctx.qm.sendMessage(toStr, msgTx);
} catch (IOException e) {
assert false : e.toString();
}
new TestUnit<FsMQManagerTestContext>("PingPong", testCtx, ctx -> {
try {
FsMQMessage msg;
while((msg = ctx.qm.receiveMessage(5)) != null) {
// RX
String fromStr = msg.getFrom().getAddress();
String msgRx = msg.getMsg();
// RX
String fromStr = null;
String msgRx = null;
try {
FsMQMessage msg;
while ((msg = ctx.qm.receiveMessage()) == null) {
log("Waiting for ping-reply...");
TestUtils.sleep(250);
}
fromStr = msg.getFrom().getAddress();
msgRx = msg.getMsg();
log("RX From: " + fromStr);
log(msgRx);
} catch (Exception e) {
assert false : e.toString();
}
// TX
String toStr = fromStr;
String msgTx = ctx.getMessages().get(0) + msgRx;
log("TX to:" + toStr);
log(msgTx);
ctx.qm.sendMessage(fromStr,msgTx);
if (fromStr.equals(toStr)) {
if (msgRx.equals(msgTx)) {
pingCount++;
}
}
} 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.*;
@ -32,27 +32,41 @@ class TestBob {
ctx.qm.clearOwnQueue();
});
new TestUnit<FsMQManagerTestContext>("PingPong", testCtx, ctx -> {
try {
new TestUnit<FsMQManagerTestContext>("Ping responder", testCtx, ctx -> {
int pingMax = 10;
int pingCount = 0;
while(pingCount < pingMax) {
FsMQMessage msg;
while((msg = ctx.qm.receiveMessage(5)) != null) {
// RX
String fromStr = msg.getFrom().getAddress();
String msgRx = msg.getMsg();
// RX
String fromStr = null;
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(msgRx);
} catch (Exception e) {
assert false : e.toString();
}
if(msgRx.equals("ping")) {
// TX
String toStr = fromStr;
String msgTx = ctx.getMessages().get(0) + msgRx;
log("TX to:" + toStr);
log(msgTx);
ctx.qm.sendMessage(fromStr,msgTx);
String msgTx = msgRx;
try {
log("TX to:" + toStr);
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 path = qDir + "/" + filename;
// check file not existing yet.
log("Adding msg file:" + filename);
// log("Adding msg file:" + filename);
File file = new File(path);
if(!file.exists()) {
@ -237,7 +237,7 @@ public class FsMsgQueue implements Queue<String> {
private Pair<File, String> get() throws Exception {
Pair<File, String> ret = null;
File oldestFile = getOldestMsgFilename();
log("reading file:" + oldestFile.getName());
// log("reading file:" + oldestFile.getName());
if (oldestFile == null) {
throw new NoSuchElementException("No .msg file in dir: " + qDir);
} else {

Loading…
Cancel
Save