//For testing weather messages are re-transmitted correctly
public void testRetransmission() {
SandeshaQueue sq = SandeshaQueue.getInstance(Constants.CLIENT);
ClientStorageManager csm = new ClientStorageManager();
RMMessageContext msg1;
//approving the out sequence
csm.setTemporaryOutSequence("seqid1", "uuid:aaaa-bbbb-cccc");
csm.setApprovedOutSequence("uuid:aaaa-bbbb-cccc", "approved1");
//messages should be returned (since the out sequence is approved)
msg1 = csm.getNextMessageToSend();
assertNotNull(msg1);
msg1.setLocked(false);
msg1 = csm.getNextMessageToSend();
assertNotNull(msg1);
msg1.setLocked(false);
msg1 = csm.getNextMessageToSend();
assertNotNull(msg1);
msg1.setLocked(false);
msg1 = csm.getNextMessageToSend();
assertNotNull(msg1);
msg1.setLocked(false);
msg1 = csm.getNextMessageToSend();
assertNull(msg1);
//Waiting for little more than re-transmission interval
try {
Thread.sleep(Constants.RETRANSMISSION_INTERVAL + 100);
} catch (InterruptedException e) {
e.printStackTrace();
}
msg1 = csm.getNextMessageToSend();
assertNotNull(msg1);
msg1.setLocked(false);
msg1 = csm.getNextMessageToSend();
assertNotNull(msg1);
msg1.setLocked(false);
msg1 = csm.getNextMessageToSend();
assertNotNull(msg1);
msg1.setLocked(false);
msg1 = csm.getNextMessageToSend();
assertNotNull(msg1);
msg1.setLocked(false);
msg1 = csm.getNextMessageToSend();
assertNull(msg1);
//Again waiting for little more than re-transmission interval :)
try {
Thread.sleep(Constants.RETRANSMISSION_INTERVAL + 100);
} catch (InterruptedException e) {
e.printStackTrace();
}
//Messages should be returned once again
msg1 = csm.getNextMessageToSend();
assertNotNull(msg1);
msg1.setLocked(false);
msg1 = csm.getNextMessageToSend();
assertNotNull(msg1);
msg1.setLocked(false);
msg1 = csm.getNextMessageToSend();
assertNotNull(msg1);
msg1.setLocked(false);
msg1 = csm.getNextMessageToSend();
assertNotNull(msg1);
msg1.setLocked(false);
msg1 = csm.getNextMessageToSend();
assertNull(msg1);
}