Browse Source

Tests: FSMQManager - throw only RuntimeExceptions, not higher

JNI-153
heck 4 years ago
parent
commit
7ca56f9ed7
  1. 29
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/FsMQManager.java

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

@ -1,12 +1,10 @@
package foundation.pEp.jniadapter.test.utils.transport.fsmqmanager; package foundation.pEp.jniadapter.test.utils.transport.fsmqmanager;
import foundation.pEp.pitytest.utils.TestUtils;
import foundation.pEp.jniadapter.test.utils.transport.fsmsgqueue.FsMsgQueue; import foundation.pEp.jniadapter.test.utils.transport.fsmsgqueue.FsMsgQueue;
import foundation.pEp.pitytest.utils.TestUtils;
import java.io.*; import java.io.*;
import java.util.*; import java.util.Base64;
import static foundation.pEp.pitytest.TestLogger.log;
public class FsMQManager { public class FsMQManager {
public FsMQIdentities identities = null; public FsMQIdentities identities = null;
@ -19,12 +17,16 @@ public class FsMQManager {
identities.getQueueForIdentity(identities.self.getAddress()).clear(); identities.getQueueForIdentity(identities.self.getAddress()).clear();
} }
public void sendMessage(String address, String msg) throws UnknownIdentityException, IOException, NullPointerException { public void sendMessage(String address, String msg) throws UnknownIdentityException, NullPointerException {
if (address != null) { if (address != null) {
if (msg != null) { if (msg != null) {
FsMQMessageInternal mqMsg = new FsMQMessageInternal(identities.self, msg); FsMQMessageInternal mqMsg = new FsMQMessageInternal(identities.self, msg);
String serializedStr = mqMsg.serialize(); try {
identities.getQueueForIdentity(address).add(serializedStr); String serializedStr = mqMsg.serialize();
identities.getQueueForIdentity(address).add(serializedStr);
} catch (IOException e) {
throw new RuntimeException(e.toString());
}
} else { } else {
throw new NullPointerException("msg cant be null"); throw new NullPointerException("msg cant be null");
} }
@ -35,13 +37,13 @@ public class FsMQManager {
// Non blocking read // Non blocking read
// Returns null if no messages available // Returns null if no messages available
public FsMQMessage receiveMessage() throws IOException, ClassNotFoundException { public FsMQMessage receiveMessage() {
return receiveMessage(0); return receiveMessage(0);
} }
// Blocking read // Blocking read
// Returns null if no messages available within timeout // Returns null if no messages available within timeout
public FsMQMessage receiveMessage(int timeoutSec) throws IOException, ClassNotFoundException { public FsMQMessage receiveMessage(int timeoutSec) {
FsMQMessage ret = null; FsMQMessage ret = null;
FsMsgQueue onwQueue = identities.getQueueForIdentity(identities.self.getAddress()); FsMsgQueue onwQueue = identities.getQueueForIdentity(identities.self.getAddress());
FsMQMessageInternal mqMsg = null; FsMQMessageInternal mqMsg = null;
@ -57,9 +59,12 @@ public class FsMQManager {
} }
} }
String serializedMsg = onwQueue.remove(); String serializedMsg = onwQueue.remove();
mqMsg = FsMQMessageInternal.deserialize(serializedMsg); try {
mqMsg = FsMQMessageInternal.deserialize(serializedMsg);
ret = mqMsg.toFsMQMessage(); ret = mqMsg.toFsMQMessage();
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
return ret; return ret;
} }
} }

Loading…
Cancel
Save