1 17 package org.apache.sandesha.storage; 18 19 import junit.framework.TestCase; 20 import org.apache.sandesha.Constants; 21 import org.apache.sandesha.RMMessageContext; 22 import org.apache.sandesha.client.ClientStorageManager; 23 import org.apache.sandesha.storage.queue.QueueException; 24 import org.apache.sandesha.storage.queue.SandeshaQueue; 25 26 30 public class TCClientStorageManager extends TestCase { 31 32 public void testRetransmission() { 34 35 SandeshaQueue sq = SandeshaQueue.getInstance(Constants.CLIENT); 36 ClientStorageManager csm = new ClientStorageManager(); 37 RMMessageContext msg1; 38 39 csm.setTemporaryOutSequence("seqid1", "uuid:aaaa-bbbb-cccc"); 41 csm.setApprovedOutSequence("uuid:aaaa-bbbb-cccc", "approved1"); 42 43 msg1 = csm.getNextMessageToSend(); 45 assertNotNull(msg1); 46 msg1.setLocked(false); 47 msg1 = csm.getNextMessageToSend(); 48 assertNotNull(msg1); 49 msg1.setLocked(false); 50 msg1 = csm.getNextMessageToSend(); 51 assertNotNull(msg1); 52 msg1.setLocked(false); 53 msg1 = csm.getNextMessageToSend(); 54 assertNotNull(msg1); 55 msg1.setLocked(false); 56 msg1 = csm.getNextMessageToSend(); 57 assertNull(msg1); 58 59 try { 61 Thread.sleep(Constants.RETRANSMISSION_INTERVAL + 100); 62 } catch (InterruptedException e) { 63 e.printStackTrace(); 64 } 65 66 67 msg1 = csm.getNextMessageToSend(); 68 assertNotNull(msg1); 69 msg1.setLocked(false); 70 msg1 = csm.getNextMessageToSend(); 71 assertNotNull(msg1); 72 msg1.setLocked(false); 73 msg1 = csm.getNextMessageToSend(); 74 assertNotNull(msg1); 75 msg1.setLocked(false); 76 msg1 = csm.getNextMessageToSend(); 77 assertNotNull(msg1); 78 msg1.setLocked(false); 79 msg1 = csm.getNextMessageToSend(); 80 assertNull(msg1); 81 82 try { 84 Thread.sleep(Constants.RETRANSMISSION_INTERVAL + 100); 85 } catch (InterruptedException e) { 86 e.printStackTrace(); 87 } 88 89 msg1 = csm.getNextMessageToSend(); 91 assertNotNull(msg1); 92 msg1.setLocked(false); 93 msg1 = csm.getNextMessageToSend(); 94 assertNotNull(msg1); 95 msg1.setLocked(false); 96 msg1 = csm.getNextMessageToSend(); 97 assertNotNull(msg1); 98 msg1.setLocked(false); 99 msg1 = csm.getNextMessageToSend(); 100 assertNotNull(msg1); 101 msg1.setLocked(false); 102 msg1 = csm.getNextMessageToSend(); 103 assertNull(msg1); 104 105 } 106 107 public void testAcknowledgement() { 109 SandeshaQueue sq = SandeshaQueue.getInstance(Constants.CLIENT); 110 ClientStorageManager csm = new ClientStorageManager(); 111 112 csm.setTemporaryOutSequence("seqid1", "uuid:aaaa-bbbb-cccc"); 113 csm.setApprovedOutSequence("uuid:aaaa-bbbb-cccc", "approved1"); 114 115 RMMessageContext msg1; 116 msg1 = csm.getNextMessageToSend(); 117 assertNotNull(msg1); 118 msg1.setLocked(false); 119 msg1 = csm.getNextMessageToSend(); 120 assertNotNull(msg1); 121 msg1.setLocked(false); 122 msg1 = csm.getNextMessageToSend(); 123 assertNotNull(msg1); 124 msg1.setLocked(false); 125 msg1 = csm.getNextMessageToSend(); 126 assertNotNull(msg1); 127 msg1.setLocked(false); 128 msg1 = csm.getNextMessageToSend(); 129 assertNull(msg1); 130 131 csm.setAcknowledged("approved1", 1); 133 csm.setAcknowledged("approved1", 2); 134 csm.setAcknowledged("approved1", 4); 135 136 try { 138 Thread.sleep(Constants.RETRANSMISSION_INTERVAL + 100); 139 } catch (InterruptedException e) { 140 e.printStackTrace(); 141 } 142 143 msg1 = csm.getNextMessageToSend(); 145 assertNotNull(msg1); 146 assertEquals(msg1.getMessageID(), "rmsg3"); 147 msg1 = csm.getNextMessageToSend(); 148 assertNull(msg1); 149 } 150 151 248 249 250 public void setUp() throws QueueException { 251 252 SandeshaQueue sq = SandeshaQueue.getInstance(Constants.CLIENT); 253 ClientStorageManager csm = new ClientStorageManager(); 254 RMMessageContext msg = new RMMessageContext(); 255 256 sq.createNewOutgoingSequence("seqid1"); 258 259 261 long nextMsgNo = csm.getNextMessageNumber("seqid1"); 263 assertEquals(nextMsgNo, 1); 264 msg.setMessageID("rmsg1"); 265 msg.setSequenceID("seqid1"); 266 msg.setMsgNumber(nextMsgNo); 267 sq.addMessageToOutgoingSequence("seqid1", msg); 268 269 nextMsgNo = csm.getNextMessageNumber("seqid1"); 271 assertEquals(nextMsgNo, 2); 272 msg = new RMMessageContext(); 273 msg.setMessageID("rmsg2"); 274 msg.setSequenceID("seqid1"); 275 msg.setMsgNumber(nextMsgNo); 276 sq.addMessageToOutgoingSequence("seqid1", msg); 277 278 nextMsgNo = csm.getNextMessageNumber("seqid1"); 280 assertEquals(nextMsgNo, 3); 281 msg = new RMMessageContext(); 282 msg.setMessageID("rmsg3"); 283 msg.setSequenceID("seqid1"); 284 msg.setMsgNumber(nextMsgNo); 285 286 sq.addMessageToOutgoingSequence("seqid1", msg); 288 nextMsgNo = csm.getNextMessageNumber("seqid1"); 289 assertEquals(nextMsgNo, 4); 290 msg = new RMMessageContext(); 291 msg.setMessageID("rmsg4"); 292 msg.setSequenceID("seqid1"); 293 msg.setMsgNumber(nextMsgNo); 294 sq.addMessageToOutgoingSequence("seqid1", msg); 295 } 296 297 public void tearDown() { 298 299 ClientStorageManager csm = new ClientStorageManager(); 301 csm.clearStorage(); 302 303 } 304 305 306 } | Popular Tags |