Jonathan Hart

Fixed flaky HostMonitor unit tests.

Change-Id: Ie9e9e922733e6210b61a0360feae38d683685fe7
...@@ -73,8 +73,6 @@ public class HostMonitor implements TimerTask { ...@@ -73,8 +73,6 @@ public class HostMonitor implements TimerTask {
73 monitoredAddresses = Collections.newSetFromMap( 73 monitoredAddresses = Collections.newSetFromMap(
74 new ConcurrentHashMap<IpAddress, Boolean>()); 74 new ConcurrentHashMap<IpAddress, Boolean>());
75 hostProviders = new ConcurrentHashMap<>(); 75 hostProviders = new ConcurrentHashMap<>();
76 -
77 - timeout = Timer.getTimer().newTimeout(this, 0, TimeUnit.MILLISECONDS);
78 } 76 }
79 77
80 /** 78 /**
......
...@@ -5,6 +5,7 @@ import static org.easymock.EasyMock.expect; ...@@ -5,6 +5,7 @@ import static org.easymock.EasyMock.expect;
5 import static org.easymock.EasyMock.expectLastCall; 5 import static org.easymock.EasyMock.expectLastCall;
6 import static org.easymock.EasyMock.replay; 6 import static org.easymock.EasyMock.replay;
7 import static org.easymock.EasyMock.verify; 7 import static org.easymock.EasyMock.verify;
8 +import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertTrue; 9 import static org.junit.Assert.assertTrue;
9 10
10 import java.util.ArrayList; 11 import java.util.ArrayList;
...@@ -13,7 +14,7 @@ import java.util.Collections; ...@@ -13,7 +14,7 @@ import java.util.Collections;
13 import java.util.List; 14 import java.util.List;
14 import java.util.Set; 15 import java.util.Set;
15 16
16 -import org.junit.Ignore; 17 +import org.junit.After;
17 import org.junit.Test; 18 import org.junit.Test;
18 import org.onlab.onos.net.ConnectPoint; 19 import org.onlab.onos.net.ConnectPoint;
19 import org.onlab.onos.net.Device; 20 import org.onlab.onos.net.Device;
...@@ -52,8 +53,12 @@ public class HostMonitorTest { ...@@ -52,8 +53,12 @@ public class HostMonitorTest {
52 53
53 private HostMonitor hostMonitor; 54 private HostMonitor hostMonitor;
54 55
56 + @After
57 + public void shutdown() {
58 + hostMonitor.shutdown();
59 + }
60 +
55 @Test 61 @Test
56 - @Ignore
57 public void testMonitorHostExists() throws Exception { 62 public void testMonitorHostExists() throws Exception {
58 ProviderId id = new ProviderId("fake://", "id"); 63 ProviderId id = new ProviderId("fake://", "id");
59 64
...@@ -83,8 +88,8 @@ public class HostMonitorTest { ...@@ -83,8 +88,8 @@ public class HostMonitorTest {
83 } 88 }
84 89
85 @Test 90 @Test
86 - @Ignore
87 public void testMonitorHostDoesNotExist() throws Exception { 91 public void testMonitorHostDoesNotExist() throws Exception {
92 +
88 HostManager hostManager = createMock(HostManager.class); 93 HostManager hostManager = createMock(HostManager.class);
89 94
90 DeviceId devId = DeviceId.deviceId("fake"); 95 DeviceId devId = DeviceId.deviceId("fake");
...@@ -124,11 +129,11 @@ public class HostMonitorTest { ...@@ -124,11 +129,11 @@ public class HostMonitorTest {
124 129
125 // Check that a packet was sent to our PacketService and that it has 130 // Check that a packet was sent to our PacketService and that it has
126 // the properties we expect 131 // the properties we expect
127 - assertTrue(packetService.packets.size() == 1); 132 + assertEquals(1, packetService.packets.size());
128 OutboundPacket packet = packetService.packets.get(0); 133 OutboundPacket packet = packetService.packets.get(0);
129 134
130 // Check the output port is correct 135 // Check the output port is correct
131 - assertTrue(packet.treatment().instructions().size() == 1); 136 + assertEquals(1, packet.treatment().instructions().size());
132 Instruction instruction = packet.treatment().instructions().get(0); 137 Instruction instruction = packet.treatment().instructions().get(0);
133 assertTrue(instruction instanceof OutputInstruction); 138 assertTrue(instruction instanceof OutputInstruction);
134 OutputInstruction oi = (OutputInstruction) instruction; 139 OutputInstruction oi = (OutputInstruction) instruction;
......