Bug 8385 - @Ignore testMultipleRegistrationsAtOnePrefix
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / sharding / DistributedShardedDOMDataTreeRemotingTest.java
index 522a7d39f9bb744a94b4af7c374c59f8ef462ef0..ca8af73cb0d8087b7722652d8c3f800fa562cc57 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.controller.cluster.sharding;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -24,9 +25,12 @@ import akka.testkit.JavaTestKit;
 import com.google.common.collect.Lists;
 import com.typesafe.config.ConfigFactory;
 import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.opendaylight.controller.cluster.ActorSystemProvider;
@@ -63,21 +67,17 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
     private static final DOMDataTreeIdentifier TEST_ID =
             new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
 
-    private static final String MODULE_SHARDS_CONFIG = "module-shards-cars-member-1-and-2.conf";
+    private static final String MODULE_SHARDS_CONFIG = "module-shards-default.conf";
 
     private ActorSystem leaderSystem;
     private ActorSystem followerSystem;
 
 
     private final Builder leaderDatastoreContextBuilder =
-            DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(5)
-                    .logicalStoreType(
-                            org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION);
+            DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(5);
 
     private final DatastoreContext.Builder followerDatastoreContextBuilder =
-            DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(5)
-                    .logicalStoreType(
-                            org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION);
+            DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(5);
 
     private DistributedDataStore leaderConfigDatastore;
     private DistributedDataStore leaderOperDatastore;
@@ -129,8 +129,8 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
             followerOperDatastore.close();
         }
 
-        JavaTestKit.shutdownActorSystem(leaderSystem);
-        JavaTestKit.shutdownActorSystem(followerSystem);
+        JavaTestKit.shutdownActorSystem(leaderSystem, null, Boolean.TRUE);
+        JavaTestKit.shutdownActorSystem(followerSystem, null, Boolean.TRUE);
 
         InMemoryJournal.clear();
         InMemorySnapshotStore.clear();
@@ -162,6 +162,8 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
                 followerOperDatastore,
                 followerConfigDatastore);
 
+        followerTestKit.waitForMembersUp("member-1");
+
         leaderShardFactory.init();
         followerShardFactory.init();
 
@@ -170,15 +172,16 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
 
         leaderTestKit.waitUntilLeader(leaderOperDatastore.getActorContext(),
                 ClusterUtils.getCleanShardName(YangInstanceIdentifier.EMPTY));
-
     }
 
     @Test
     public void testProducerRegistrations() throws Exception {
+        LOG.info("testProducerRegistrations starting");
         initEmptyDatastores();
 
         leaderTestKit.waitForMembersUp("member-2");
 
+        // TODO refactor shard creation and verification to own method
         final DistributedShardRegistration shardRegistration =
                 waitOnAsyncTask(leaderShardFactory.createDistributedShard(
                         TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME, AbstractTest.MEMBER_2_NAME)),
@@ -195,6 +198,12 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
         assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(),
                 ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier())));
 
+        final Set<String> peers  = new HashSet<>();
+        IntegrationTestKit.verifyShardState(leaderConfigDatastore,
+                ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()), onDemandShardState ->
+                        peers.addAll(onDemandShardState.getPeerAddresses().values()));
+        assertEquals(peers.size(), 1);
+
         final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
         try {
             followerShardFactory.createProducer(Collections.singleton(TEST_ID));
@@ -226,10 +235,13 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
         }
 
         shardRegistration.close().toCompletableFuture().get();
+
+        LOG.info("testProducerRegistrations ending");
     }
 
     @Test
     public void testWriteIntoMultipleShards() throws Exception {
+        LOG.info("testWriteIntoMultipleShards starting");
         initEmptyDatastores();
 
         leaderTestKit.waitForMembersUp("member-2");
@@ -246,6 +258,12 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
         findLocalShard(followerConfigDatastore.getActorContext(),
                 ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
 
+        final Set<String> peers  = new HashSet<>();
+        IntegrationTestKit.verifyShardState(leaderConfigDatastore,
+                ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()), onDemandShardState ->
+                        peers.addAll(onDemandShardState.getPeerAddresses().values()));
+        assertEquals(peers.size(), 1);
+
         LOG.debug("Got after waiting for nonleader");
         final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
 
@@ -264,10 +282,13 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
         tx.submit().checkedGet();
 
         shardRegistration.close().toCompletableFuture().get();
+
+        LOG.info("testWriteIntoMultipleShards ending");
     }
 
     @Test
     public void testMultipleShardRegistrations() throws Exception {
+        LOG.info("testMultipleShardRegistrations starting");
         initEmptyDatastores();
 
         final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(
@@ -324,7 +345,6 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
         assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(),
                 ClusterUtils.getCleanShardName(TestModel.JUNK_PATH)));
 
-
         LOG.debug("Closing registrations");
 
         reg1.close().toCompletableFuture().get();
@@ -359,10 +379,13 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
                 ClusterUtils.getCleanShardName(TestModel.JUNK_PATH));
 
         LOG.debug("All follower shards gone");
+        LOG.info("testMultipleShardRegistrations ending");
     }
 
     @Test
+    @Ignore
     public void testMultipleRegistrationsAtOnePrefix() throws Exception {
+        LOG.info("testMultipleRegistrationsAtOnePrefix starting");
         initEmptyDatastores();
 
         for (int i = 0; i < 10; i++) {
@@ -380,6 +403,13 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
             assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(),
                     ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
 
+
+            final Set<String> peers  = new HashSet<>();
+            IntegrationTestKit.verifyShardState(leaderConfigDatastore,
+                    ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()), onDemandShardState ->
+                            peers.addAll(onDemandShardState.getPeerAddresses().values()));
+            assertEquals(peers.size(), 1);
+
             waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
 
             waitUntilShardIsDown(leaderConfigDatastore.getActorContext(),
@@ -389,5 +419,6 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
                     ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
         }
 
+        LOG.info("testMultipleRegistrationsAtOnePrefix ending");
     }
 }