1 21 22 package org.jacorb.test.notification.queue; 23 24 import org.easymock.MockControl; 25 import org.jacorb.notification.interfaces.Message; 26 import org.jacorb.notification.queue.BoundedDeadlineEventQueue; 27 import org.jacorb.notification.queue.EventQueueOverflowStrategy; 28 29 import junit.framework.Test; 30 import junit.framework.TestCase; 31 import junit.framework.TestSuite; 32 33 37 public class BoundedDeadlineEventQueueTest extends TestCase 38 { 39 private BoundedDeadlineEventQueue objectUnderTest_; 40 41 private MockControl controlMessage1_; 42 43 private Message mockMessage1_; 44 45 private MockControl controlMessage2_; 46 47 private Message mockMessage2_; 48 49 private MockControl controlMessage3_; 50 51 private Message mockMessage3_; 52 53 public BoundedDeadlineEventQueueTest(String name) 54 { 55 super(name); 56 } 57 58 protected void setUp() 59 { 60 objectUnderTest_ = new BoundedDeadlineEventQueue(2, 61 EventQueueOverflowStrategy.EARLIEST_TIMEOUT); 62 63 controlMessage1_ = MockControl.createControl(Message.class); 64 controlMessage2_ = MockControl.createControl(Message.class); 65 controlMessage3_ = MockControl.createControl(Message.class); 66 67 mockMessage1_ = (Message) controlMessage1_.getMock(); 68 mockMessage2_ = (Message) controlMessage2_.getMock(); 69 mockMessage3_ = (Message) controlMessage3_.getMock(); 70 } 71 72 public void testGetSingleNonBlocking() throws Exception 73 { 74 mockMessage1_.hasTimeout(); 75 controlMessage1_.setDefaultReturnValue(false); 76 controlMessage1_.replay(); 77 78 assertNull(objectUnderTest_.getMessage(false)); 79 80 objectUnderTest_.put(mockMessage1_); 81 82 assertEquals(mockMessage1_, objectUnderTest_.getMessage(false)); 83 } 84 85 public void testGetAllNonBlocking() throws Exception 86 { 87 mockMessage1_.hasTimeout(); 88 controlMessage1_.setDefaultReturnValue(false); 89 controlMessage1_.replay(); 90 91 assertEquals(0, objectUnderTest_.getAllMessages(false).length); 92 93 objectUnderTest_.put(mockMessage1_); 94 objectUnderTest_.put(mockMessage1_); 95 96 assertEquals(2, objectUnderTest_.getAllMessages(false).length); 97 } 98 99 public void testGetAllClearsQueue() throws Exception 100 { 101 mockMessage1_.hasTimeout(); 102 controlMessage1_.setDefaultReturnValue(false); 103 controlMessage1_.replay(); 104 105 objectUnderTest_.put(mockMessage1_); 106 107 assertEquals(mockMessage1_, objectUnderTest_.getAllMessages(false)[0]); 108 109 assertEquals(0, objectUnderTest_.getAllMessages(false).length); 110 } 111 112 public void testInsert() throws Exception 113 { 114 mockMessage1_.hasTimeout(); 115 controlMessage1_.setReturnValue(true); 116 mockMessage1_.getTimeout(); 117 controlMessage1_.setReturnValue(100); 118 controlMessage1_.replay(); 119 120 mockMessage2_.hasTimeout(); 121 controlMessage2_.setReturnValue(true); 122 mockMessage2_.getTimeout(); 123 controlMessage2_.setReturnValue(10); 124 controlMessage2_.replay(); 125 126 objectUnderTest_.put(mockMessage1_); 127 objectUnderTest_.put(mockMessage2_); 128 129 assertEquals(mockMessage2_, objectUnderTest_.getMessage(false)); 130 131 controlMessage1_.verify(); 132 controlMessage2_.verify(); 133 } 134 135 public void testOverflow() throws Exception 136 { 137 mockMessage1_.hasTimeout(); 138 controlMessage1_.setDefaultReturnValue(true); 139 mockMessage1_.getTimeout(); 140 controlMessage1_.setDefaultReturnValue(100); 141 controlMessage1_.replay(); 142 143 mockMessage2_.hasTimeout(); 144 controlMessage2_.setDefaultReturnValue(true); 145 mockMessage2_.getTimeout(); 146 controlMessage2_.setDefaultReturnValue(10); 147 controlMessage2_.replay(); 148 149 mockMessage3_.hasTimeout(); 150 controlMessage3_.setDefaultReturnValue(true); 151 mockMessage3_.getTimeout(); 152 controlMessage3_.setDefaultReturnValue(1); 153 controlMessage3_.replay(); 154 155 objectUnderTest_.put(mockMessage1_); 156 objectUnderTest_.put(mockMessage2_); 157 objectUnderTest_.put(mockMessage3_); 158 159 assertEquals(mockMessage3_, objectUnderTest_.getMessage(false)); 160 assertEquals(mockMessage1_, objectUnderTest_.getMessage(false)); 161 162 assertTrue(objectUnderTest_.isEmpty()); 163 assertNull(objectUnderTest_.getMessage(false)); 164 165 controlMessage1_.verify(); 166 controlMessage2_.verify(); 167 controlMessage3_.verify(); 168 } 169 170 175 public void testGetEvents() throws Exception 176 { 177 mockMessage1_.hasTimeout(); 178 controlMessage1_.setDefaultReturnValue(false); 179 180 controlMessage1_.replay(); 181 182 mockMessage2_.hasTimeout(); 183 controlMessage2_.setDefaultReturnValue(false); 184 185 controlMessage2_.replay(); 186 187 objectUnderTest_.put(mockMessage1_); 188 objectUnderTest_.put(mockMessage2_); 189 190 assertEquals(1, objectUnderTest_.getMessages(1, false).length); 191 assertEquals(1, objectUnderTest_.getMessages(1, false).length); 192 } 193 194 public static Test suite() 195 { 196 return new TestSuite(BoundedDeadlineEventQueueTest.class); 197 } 198 } | Popular Tags |