Fix duplicate host event
Change-Id: I632a1482e7b1b768ce7a0243cc8b6b398b9825b7
diff --git a/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java b/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
index 1473f33..f48b836 100644
--- a/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
+++ b/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
@@ -192,10 +192,7 @@
@Override
public void removeHost(HostId hostId) {
checkNotNull(hostId, HOST_ID_NULL);
- HostEvent event = store.removeHost(hostId);
- if (event != null) {
- post(event);
- }
+ store.removeHost(hostId);
}
// Personalized host provider service issued to the supplied provider.
@@ -211,11 +208,8 @@
checkNotNull(hostId, HOST_ID_NULL);
checkValidity();
hostDescription = validateHost(hostDescription, hostId);
- HostEvent event = store.createOrUpdateHost(provider().id(), hostId,
+ store.createOrUpdateHost(provider().id(), hostId,
hostDescription, replaceIps);
- if (event != null) {
- post(event);
- }
}
// returns a HostDescription made from the union of the BasicHostConfig
@@ -231,20 +225,14 @@
public void hostVanished(HostId hostId) {
checkNotNull(hostId, HOST_ID_NULL);
checkValidity();
- HostEvent event = store.removeHost(hostId);
- if (event != null) {
- post(event);
- }
+ store.removeHost(hostId);
}
@Override
public void removeIpFromHost(HostId hostId, IpAddress ipAddress) {
checkNotNull(hostId, HOST_ID_NULL);
checkValidity();
- HostEvent event = store.removeIp(hostId, ipAddress);
- if (event != null) {
- post(event);
- }
+ store.removeIp(hostId, ipAddress);
}
}
diff --git a/core/net/src/test/java/org/onosproject/net/host/impl/HostManagerTest.java b/core/net/src/test/java/org/onosproject/net/host/impl/HostManagerTest.java
index 92c6c93..c5a6cab 100644
--- a/core/net/src/test/java/org/onosproject/net/host/impl/HostManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/host/impl/HostManagerTest.java
@@ -20,6 +20,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onlab.junit.TestTools;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
@@ -129,13 +130,15 @@
}
private void validateEvents(Enum... types) {
- int i = 0;
- assertEquals("wrong events received", types.length, listener.events.size());
- for (Event event : listener.events) {
- assertEquals("incorrect event type", types[i], event.type());
- i++;
- }
- listener.events.clear();
+ TestTools.assertAfter(100, () -> {
+ int i = 0;
+ assertEquals("wrong events received", types.length, listener.events.size());
+ for (Event event : listener.events) {
+ assertEquals("incorrect event type", types[i], event.type());
+ i++;
+ }
+ listener.events.clear();
+ });
}
@Test