poll for events when validating.
Change-Id: Ia727a1c97f5d2d713281130997cee7fa3b1ba39d
Showing
1 changed file
with
14 additions
and
7 deletions
... | @@ -43,8 +43,11 @@ import java.util.Iterator; | ... | @@ -43,8 +43,11 @@ import java.util.Iterator; |
43 | import java.util.List; | 43 | import java.util.List; |
44 | import java.util.Map.Entry; | 44 | import java.util.Map.Entry; |
45 | import java.util.Set; | 45 | import java.util.Set; |
46 | +import java.util.concurrent.BlockingQueue; | ||
46 | import java.util.concurrent.ConcurrentHashMap; | 47 | import java.util.concurrent.ConcurrentHashMap; |
47 | import java.util.concurrent.ConcurrentMap; | 48 | import java.util.concurrent.ConcurrentMap; |
49 | +import java.util.concurrent.LinkedBlockingQueue; | ||
50 | +import java.util.concurrent.TimeUnit; | ||
48 | 51 | ||
49 | import static org.junit.Assert.*; | 52 | import static org.junit.Assert.*; |
50 | import static org.onlab.onos.net.Device.Type.SWITCH; | 53 | import static org.onlab.onos.net.Device.Type.SWITCH; |
... | @@ -182,7 +185,7 @@ public class DistributedDeviceManagerTest { | ... | @@ -182,7 +185,7 @@ public class DistributedDeviceManagerTest { |
182 | validateEvents(DEVICE_ADDED, DEVICE_ADDED); | 185 | validateEvents(DEVICE_ADDED, DEVICE_ADDED); |
183 | 186 | ||
184 | connectDevice(DID1, SW2); | 187 | connectDevice(DID1, SW2); |
185 | - validateEvents(DEVICE_UPDATED); | 188 | + validateEvents(DEVICE_UPDATED, DEVICE_UPDATED); |
186 | } | 189 | } |
187 | 190 | ||
188 | @Test | 191 | @Test |
... | @@ -251,12 +254,16 @@ public class DistributedDeviceManagerTest { | ... | @@ -251,12 +254,16 @@ public class DistributedDeviceManagerTest { |
251 | } | 254 | } |
252 | 255 | ||
253 | protected void validateEvents(Enum... types) { | 256 | protected void validateEvents(Enum... types) { |
254 | - int i = 0; | 257 | + for (Enum type : types) { |
255 | - assertEquals("wrong events received", types.length, listener.events.size()); | 258 | + try { |
256 | - for (Event event : listener.events) { | 259 | + Event event = listener.events.poll(1, TimeUnit.SECONDS); |
257 | - assertEquals("incorrect event type", types[i], event.type()); | 260 | + assertNotNull("Timed out waiting for " + event, event); |
258 | - i++; | 261 | + assertEquals("incorrect event type", type, event.type()); |
262 | + } catch (InterruptedException e) { | ||
263 | + fail("Unexpected interrupt"); | ||
264 | + } | ||
259 | } | 265 | } |
266 | + assertTrue("Unexpected events left", listener.events.isEmpty()); | ||
260 | listener.events.clear(); | 267 | listener.events.clear(); |
261 | } | 268 | } |
262 | 269 | ||
... | @@ -281,7 +288,7 @@ public class DistributedDeviceManagerTest { | ... | @@ -281,7 +288,7 @@ public class DistributedDeviceManagerTest { |
281 | } | 288 | } |
282 | 289 | ||
283 | private static class TestListener implements DeviceListener { | 290 | private static class TestListener implements DeviceListener { |
284 | - final List<DeviceEvent> events = new ArrayList<>(); | 291 | + final BlockingQueue<DeviceEvent> events = new LinkedBlockingQueue<>(); |
285 | 292 | ||
286 | @Override | 293 | @Override |
287 | public void event(DeviceEvent event) { | 294 | public void event(DeviceEvent event) { | ... | ... |
-
Please register or login to post a comment