1 5 package org.apache.sandesha.storage; 6 7 import junit.framework.TestCase; 8 import org.apache.sandesha.Constants; 9 import org.apache.sandesha.RMMessageContext; 10 import org.apache.sandesha.server.ServerStorageManager; 11 import org.apache.sandesha.storage.queue.QueueException; 12 import org.apache.sandesha.storage.queue.SandeshaQueue; 13 14 15 public class TCServerStorageManager extends TestCase { 16 17 public void testRetransmission() { 19 20 SandeshaQueue sq = SandeshaQueue.getInstance(Constants.SERVER); 21 ServerStorageManager csm = new ServerStorageManager(); 22 RMMessageContext msg1; 23 24 csm.setTemporaryOutSequence("seqid1", "uuid:aaaa-bbbb-cccc"); 26 csm.setApprovedOutSequence("uuid:aaaa-bbbb-cccc", "approved1"); 27 28 msg1 = csm.getNextMessageToSend(); 30 assertNotNull(msg1); 31 msg1.setLocked(false); 32 msg1 = csm.getNextMessageToSend(); 33 assertNotNull(msg1); 34 msg1.setLocked(false); 35 msg1 = csm.getNextMessageToSend(); 36 assertNotNull(msg1); 37 msg1.setLocked(false); 38 msg1 = csm.getNextMessageToSend(); 39 assertNotNull(msg1); 40 msg1.setLocked(false); 41 msg1 = csm.getNextMessageToSend(); 42 assertNull(msg1); 43 44 try { 46 Thread.sleep(Constants.RETRANSMISSION_INTERVAL + 100); 47 } catch (InterruptedException e) { 48 e.printStackTrace(); 49 } 50 51 52 msg1 = csm.getNextMessageToSend(); 53 assertNotNull(msg1); 54 msg1.setLocked(false); 55 msg1 = csm.getNextMessageToSend(); 56 assertNotNull(msg1); 57 msg1.setLocked(false); 58 msg1 = csm.getNextMessageToSend(); 59 assertNotNull(msg1); 60 msg1.setLocked(false); 61 msg1 = csm.getNextMessageToSend(); 62 assertNotNull(msg1); 63 msg1.setLocked(false); 64 msg1 = csm.getNextMessageToSend(); 65 assertNull(msg1); 66 67 try { 69 Thread.sleep(Constants.RETRANSMISSION_INTERVAL + 100); 70 } catch (InterruptedException e) { 71 e.printStackTrace(); 72 } 73 74 msg1 = csm.getNextMessageToSend(); 76 assertNotNull(msg1); 77 msg1.setLocked(false); 78 msg1 = csm.getNextMessageToSend(); 79 assertNotNull(msg1); 80 msg1.setLocked(false); 81 msg1 = csm.getNextMessageToSend(); 82 assertNotNull(msg1); 83 msg1.setLocked(false); 84 msg1 = csm.getNextMessageToSend(); 85 assertNotNull(msg1); 86 msg1.setLocked(false); 87 msg1 = csm.getNextMessageToSend(); 88 assertNull(msg1); 89 90 } 91 92 93 public void testAcknowledgement() { 95 SandeshaQueue sq = SandeshaQueue.getInstance(Constants.SERVER); 96 ServerStorageManager csm = new ServerStorageManager(); 97 98 csm.setTemporaryOutSequence("seqid1", "uuid:aaaa-bbbb-cccc"); 99 csm.setApprovedOutSequence("uuid:aaaa-bbbb-cccc", "approved1"); 100 101 RMMessageContext msg1; 102 msg1 = csm.getNextMessageToSend(); 103 assertNotNull(msg1); 104 msg1.setLocked(false); 105 msg1 = csm.getNextMessageToSend(); 106 assertNotNull(msg1); 107 msg1.setLocked(false); 108 msg1 = csm.getNextMessageToSend(); 109 assertNotNull(msg1); 110 msg1.setLocked(false); 111 msg1 = csm.getNextMessageToSend(); 112 assertNotNull(msg1); 113 msg1.setLocked(false); 114 msg1 = csm.getNextMessageToSend(); 115 assertNull(msg1); 116 117 csm.setAcknowledged("approved1", 1); 119 csm.setAcknowledged("approved1", 2); 120 csm.setAcknowledged("approved1", 4); 121 122 try { 124 Thread.sleep(Constants.RETRANSMISSION_INTERVAL + 100); 125 } catch (InterruptedException e) { 126 e.printStackTrace(); 127 } 128 129 msg1 = csm.getNextMessageToSend(); 131 assertNotNull(msg1); 132 msg1.setLocked(false); 133 assertEquals(msg1.getMessageID(), "rmsg3"); 134 msg1 = csm.getNextMessageToSend(); 135 assertNull(msg1); 136 } 137 138 public void testNextMsgToSend() { 140 SandeshaQueue sq = SandeshaQueue.getInstance(Constants.SERVER); 141 ServerStorageManager csm = new ServerStorageManager(); 142 RMMessageContext msg1; 143 144 msg1 = csm.getNextMessageToSend(); 146 assertNull(msg1); 147 msg1 = csm.getNextMessageToSend(); 148 assertNull(msg1); 149 150 csm.setTemporaryOutSequence("seqid1", "uuid:aaaa-bbbb-cccc"); 152 csm.setApprovedOutSequence("uuid:aaaa-bbbb-cccc", "approved1"); 153 154 msg1 = csm.getNextMessageToSend(); 156 assertNotNull(msg1); 157 msg1 = csm.getNextMessageToSend(); 158 assertNotNull(msg1); 159 msg1 = csm.getNextMessageToSend(); 160 assertNotNull(msg1); 161 msg1 = csm.getNextMessageToSend(); 162 assertNotNull(msg1); 163 msg1 = csm.getNextMessageToSend(); 164 assertNull(msg1); 165 } 166 167 public void testOutSequence() { 170 SandeshaQueue sq = SandeshaQueue.getInstance(Constants.SERVER); 171 ServerStorageManager csm = new ServerStorageManager(); 172 173 csm.setTemporaryOutSequence("seqid1", "uuid:aaaa-bbbb-cccc"); 175 176 RMMessageContext msg1; 177 178 msg1 = csm.getNextMessageToSend(); 180 assertNull(msg1); 181 182 msg1 = csm.getNextMessageToSend(); 184 assertNull(msg1); 185 186 csm.setApprovedOutSequence("uuid:aaaa-bbbb-cccc", "approved1"); 188 189 msg1 = csm.getNextMessageToSend(); 191 assertNotNull(msg1); 192 } 193 194 public void testPriorityQueue() { 198 SandeshaQueue sq = SandeshaQueue.getInstance(Constants.SERVER); 199 ServerStorageManager csm = new ServerStorageManager(); 200 201 RMMessageContext createSeqReq1 = new RMMessageContext(); 204 createSeqReq1.setMessageType(Constants.MSG_TYPE_CREATE_SEQUENCE_REQUEST); 205 createSeqReq1.setMessageID("temp1"); 206 207 csm.addCreateSequenceRequest(createSeqReq1); 208 209 RMMessageContext msg1; 210 ServerStorageManager csm1 = new ServerStorageManager(); 211 212 msg1 = csm1.getNextMessageToSend(); 214 assertNotNull(msg1); 215 216 msg1 = csm1.getNextMessageToSend(); 218 assertNull(msg1); 219 220 RMMessageContext ack1 = new RMMessageContext(); 223 ack1.setMessageID("msgack1"); 224 csm.addAcknowledgement(ack1); 225 226 msg1 = csm1.getNextMessageToSend(); 228 assertNotNull(msg1); 229 230 msg1 = csm1.getNextMessageToSend(); 232 assertNull(msg1); 233 } 234 235 236 public void setUp() throws QueueException { 237 238 SandeshaQueue sq = SandeshaQueue.getInstance(Constants.SERVER); 239 ServerStorageManager csm = new ServerStorageManager(); 240 RMMessageContext msg = new RMMessageContext(); 241 242 sq.createNewOutgoingSequence("seqid1"); 244 245 247 long nextMsgNo = csm.getNextMessageNumber("seqid1"); 249 assertEquals(nextMsgNo, 1); 250 msg.setMessageID("rmsg1"); 251 msg.setSequenceID("seqid1"); 252 msg.setMsgNumber(nextMsgNo); 253 sq.addMessageToOutgoingSequence("seqid1", msg); 254 255 nextMsgNo = csm.getNextMessageNumber("seqid1"); 257 assertEquals(nextMsgNo, 2); 258 msg = new RMMessageContext(); 259 msg.setMessageID("rmsg2"); 260 msg.setSequenceID("seqid1"); 261 msg.setMsgNumber(nextMsgNo); 262 sq.addMessageToOutgoingSequence("seqid1", msg); 263 264 nextMsgNo = csm.getNextMessageNumber("seqid1"); 266 assertEquals(nextMsgNo, 3); 267 msg = new RMMessageContext(); 268 msg.setMessageID("rmsg3"); 269 msg.setSequenceID("seqid1"); 270 msg.setMsgNumber(nextMsgNo); 271 272 sq.addMessageToOutgoingSequence("seqid1", msg); 274 nextMsgNo = csm.getNextMessageNumber("seqid1"); 275 assertEquals(nextMsgNo, 4); 276 msg = new RMMessageContext(); 277 msg.setMessageID("rmsg4"); 278 msg.setSequenceID("seqid1"); 279 msg.setMsgNumber(nextMsgNo); 280 sq.addMessageToOutgoingSequence("seqid1", msg); 281 } 282 283 public void tearDown() { 284 285 ServerStorageManager csm = new ServerStorageManager(); 287 csm.clearStorage(); 288 289 } 290 } 291 | Popular Tags |