Bug 8328 - Create prefix shards with correct peers 98/56498/2
authorJakub Morvay <jmorvay@cisco.com>
Thu, 27 Apr 2017 15:21:42 +0000 (17:21 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 4 May 2017 12:14:19 +0000 (12:14 +0000)
Change-Id: I068b38bb275d23d27559aec3f336a6b9081fb732
Signed-off-by: Jakub Morvay <jmorvay@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManager.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeRemotingTest.java

index a8eebf8..38fed07 100644 (file)
@@ -559,7 +559,7 @@ class ShardManager extends AbstractUntypedPersistentActorWithMetering {
                 .storeRoot(config.getPrefix().getRootIdentifier());
         DatastoreContext shardDatastoreContext = builder.build();
 
-        final Map<String, String> peerAddresses = Collections.emptyMap();
+        final Map<String, String> peerAddresses = getPeerAddresses(shardName);
         final boolean isActiveMember = true;
 
         LOG.debug("{} doCreatePrefixShard: shardId: {}, memberNames: {}, peerAddresses: {}, isActiveMember: {}",
index 36a533e..30abf8c 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,6 +25,8 @@ 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;
@@ -63,7 +66,7 @@ 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;
@@ -168,7 +171,6 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
 
         leaderTestKit.waitUntilLeader(leaderOperDatastore.getActorContext(),
                 ClusterUtils.getCleanShardName(YangInstanceIdentifier.EMPTY));
-
     }
 
     @Test
@@ -177,6 +179,7 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
 
         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)),
@@ -193,6 +196,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));
@@ -244,6 +253,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));
 
@@ -322,7 +337,6 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest {
         assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(),
                 ClusterUtils.getCleanShardName(TestModel.JUNK_PATH)));
 
-
         LOG.debug("Closing registrations");
 
         reg1.close().toCompletableFuture().get();
@@ -378,6 +392,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(),

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.