defer OVSDB port 6640 opening until system is ready
[ovsdb.git] / southbound / southbound-impl / src / test / java / org / opendaylight / ovsdb / southbound / SouthboundProviderTest.java
index 227ceee5d2e7f5327c1df2c15796671df31fbdef..3551b5e3108eddf4b26e017c47ef4dd1835a1afa 100644 (file)
@@ -23,18 +23,23 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
-import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException;
-import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipChange;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.infrautils.diagstatus.DiagStatusService;
+import org.opendaylight.infrautils.ready.SystemReadyListener;
+import org.opendaylight.infrautils.ready.SystemReadyMonitor;
+import org.opendaylight.infrautils.ready.SystemState;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.eos.binding.api.Entity;
+import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipCandidateRegistration;
+import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipChange;
+import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListener;
+import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListenerRegistration;
+import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
+import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
+import org.opendaylight.mdsal.eos.common.api.EntityOwnershipChangeState;
+import org.opendaylight.mdsal.eos.common.api.EntityOwnershipState;
 import org.opendaylight.ovsdb.lib.OvsdbConnection;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
@@ -59,14 +64,16 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
     public void testInit() throws CandidateAlreadyRegisteredException {
         // Indicate that this is the owner
         when(entityOwnershipService.getOwnershipState(any(Entity.class))).thenReturn(
-                Optional.of(new EntityOwnershipState(true, true)));
+                Optional.of(EntityOwnershipState.from(true, true)));
 
         try (SouthboundProvider southboundProvider = new SouthboundProvider(
                 getDataBroker(),
                 entityOwnershipService,
                 Mockito.mock(OvsdbConnection.class),
                 Mockito.mock(DOMSchemaService.class),
-                Mockito.mock(BindingNormalizedNodeSerializer.class))) {
+                Mockito.mock(BindingNormalizedNodeSerializer.class),
+                new ImmediateSystemReadyMonitor(),
+                Mockito.mock(DiagStatusService.class))) {
 
             // Initiate the session
             southboundProvider.init();
@@ -84,14 +91,16 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
     public void testInitWithClose() throws CandidateAlreadyRegisteredException {
         // Indicate that this is the owner
         when(entityOwnershipService.getOwnershipState(any(Entity.class))).thenReturn(
-                Optional.of(new EntityOwnershipState(true, true)));
+                Optional.of(EntityOwnershipState.from(true, true)));
 
         try (SouthboundProvider southboundProvider = new SouthboundProvider(
                 getDataBroker(),
                 entityOwnershipService,
                 Mockito.mock(OvsdbConnection.class),
                 Mockito.mock(DOMSchemaService.class),
-                Mockito.mock(BindingNormalizedNodeSerializer.class))) {
+                Mockito.mock(BindingNormalizedNodeSerializer.class),
+                new ImmediateSystemReadyMonitor(),
+                Mockito.mock(DiagStatusService.class))) {
 
             // Initiate the session
             southboundProvider.init();
@@ -111,14 +120,16 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
     @Test
     public void testGetDb() {
         when(entityOwnershipService.getOwnershipState(any(Entity.class))).thenReturn(
-                Optional.of(new EntityOwnershipState(true, true)));
+                Optional.of(EntityOwnershipState.from(true, true)));
 
         try (SouthboundProvider southboundProvider = new SouthboundProvider(
                 getDataBroker(),
                 entityOwnershipService,
                 Mockito.mock(OvsdbConnection.class),
                 Mockito.mock(DOMSchemaService.class),
-                Mockito.mock(BindingNormalizedNodeSerializer.class))) {
+                Mockito.mock(BindingNormalizedNodeSerializer.class),
+                new ImmediateSystemReadyMonitor(),
+                Mockito.mock(DiagStatusService.class))) {
 
             southboundProvider.init();
 
@@ -129,7 +140,7 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
     @Test
     public void testHandleOwnershipChange() throws ReadFailedException {
         when(entityOwnershipService.getOwnershipState(any(Entity.class))).thenReturn(
-                Optional.of(new EntityOwnershipState(false, true)));
+                Optional.of(EntityOwnershipState.from(false, true)));
         Entity entity = new Entity("ovsdb-southbound-provider", "ovsdb-southbound-provider");
         KeyedInstanceIdentifier<Topology, TopologyKey> topologyIid = InstanceIdentifier
                 .create(NetworkTopology.class)
@@ -140,7 +151,9 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                 entityOwnershipService,
                 Mockito.mock(OvsdbConnection.class),
                 Mockito.mock(DOMSchemaService.class),
-                Mockito.mock(BindingNormalizedNodeSerializer.class))) {
+                Mockito.mock(BindingNormalizedNodeSerializer.class),
+                new ImmediateSystemReadyMonitor(),
+                Mockito.mock(DiagStatusService.class))) {
 
             southboundProvider.init();
 
@@ -151,7 +164,8 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                     topologyIid).checkedGet().isPresent());
 
             // Become owner
-            southboundProvider.handleOwnershipChange(new EntityOwnershipChange(entity, false, true, true));
+            southboundProvider.handleOwnershipChange(new EntityOwnershipChange(entity,
+                    EntityOwnershipChangeState.from(false, true, true)));
 
             // Now the OVSDB topology must be present in both trees
             assertTrue(getDataBroker().newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION,
@@ -160,7 +174,8 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                     topologyIid).checkedGet().isPresent());
 
             // Verify idempotency
-            southboundProvider.handleOwnershipChange(new EntityOwnershipChange(entity, false, true, true));
+            southboundProvider.handleOwnershipChange(new EntityOwnershipChange(entity,
+                    EntityOwnershipChangeState.from(false, true, true)));
 
             // The OVSDB topology must be present in both trees
             assertTrue(getDataBroker().newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION,
@@ -169,4 +184,18 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                     topologyIid).checkedGet().isPresent());
         }
     }
+
+    private static class ImmediateSystemReadyMonitor implements SystemReadyMonitor {
+
+        @Override
+        public SystemState getSystemState() {
+            return SystemState.ACTIVE;
+        }
+
+        @Override
+        public void registerListener(SystemReadyListener listener) {
+            listener.onSystemBootReady();
+        }
+
+    }
 }