X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fsharding%2FDistributedShardedDOMDataTreeRemotingTest.java;h=d977f9346288fc722708fb146cc48c4f89c08265;hb=refs%2Fchanges%2F22%2F65622%2F11;hp=63a3852f6d473a29a0371faa0a9806bbb341fe53;hpb=e591fdb38771fec9a0af6d03f3e0ef88a61de477;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeRemotingTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeRemotingTest.java index 63a3852f6d..d977f93462 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeRemotingTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeRemotingTest.java @@ -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; @@ -20,14 +21,15 @@ import akka.actor.ActorSystem; import akka.actor.Address; import akka.actor.AddressFromURIString; import akka.cluster.Cluster; -import akka.testkit.JavaTestKit; +import akka.testkit.javadsl.TestKit; 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; @@ -54,7 +56,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLe import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Ignore("https://bugs.opendaylight.org/show_bug.cgi?id=8301") public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { private static final Logger LOG = LoggerFactory.getLogger(DistributedShardedDOMDataTreeRemotingTest.class); @@ -65,21 +66,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; @@ -131,21 +128,25 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { followerOperDatastore.close(); } - JavaTestKit.shutdownActorSystem(leaderSystem, null, Boolean.TRUE); - JavaTestKit.shutdownActorSystem(followerSystem, null, Boolean.TRUE); + TestKit.shutdownActorSystem(leaderSystem, Boolean.TRUE); + TestKit.shutdownActorSystem(followerSystem, Boolean.TRUE); InMemoryJournal.clear(); InMemorySnapshotStore.clear(); } private void initEmptyDatastores() throws Exception { + initEmptyDatastores(MODULE_SHARDS_CONFIG); + } + + private void initEmptyDatastores(final String moduleShardsConfig) throws Exception { leaderTestKit = new IntegrationTestKit(leaderSystem, leaderDatastoreContextBuilder); leaderConfigDatastore = leaderTestKit.setupDistributedDataStore( - "config", MODULE_SHARDS_CONFIG, true, + "config", moduleShardsConfig, true, SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext()); leaderOperDatastore = leaderTestKit.setupDistributedDataStore( - "operational", MODULE_SHARDS_CONFIG, true, + "operational", moduleShardsConfig, true, SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext()); leaderShardFactory = new DistributedShardedDOMDataTree(leaderSystemProvider, @@ -155,17 +156,19 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { followerTestKit = new IntegrationTestKit(followerSystem, followerDatastoreContextBuilder); followerConfigDatastore = followerTestKit.setupDistributedDataStore( - "config", MODULE_SHARDS_CONFIG, true, SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext()); + "config", moduleShardsConfig, true, SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext()); followerOperDatastore = followerTestKit.setupDistributedDataStore( - "operational", MODULE_SHARDS_CONFIG, true, + "operational", moduleShardsConfig, true, SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext()); followerShardFactory = new DistributedShardedDOMDataTree(followerSystemProvider, followerOperDatastore, followerConfigDatastore); + followerTestKit.waitForMembersUp("member-1"); + + LOG.info("Initializing leader DistributedShardedDOMDataTree"); leaderShardFactory.init(); - followerShardFactory.init(); leaderTestKit.waitUntilLeader(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(YangInstanceIdentifier.EMPTY)); @@ -173,14 +176,18 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { leaderTestKit.waitUntilLeader(leaderOperDatastore.getActorContext(), ClusterUtils.getCleanShardName(YangInstanceIdentifier.EMPTY)); + LOG.info("Initializing follower DistributedShardedDOMDataTree"); + followerShardFactory.init(); } @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)), @@ -197,6 +204,12 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()))); + final Set 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)); @@ -228,10 +241,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"); @@ -248,6 +264,12 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { findLocalShard(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier())); + final Set 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)); @@ -266,10 +288,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( @@ -326,7 +351,6 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.JUNK_PATH))); - LOG.debug("Closing registrations"); reg1.close().toCompletableFuture().get(); @@ -361,14 +385,16 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { ClusterUtils.getCleanShardName(TestModel.JUNK_PATH)); LOG.debug("All follower shards gone"); + LOG.info("testMultipleShardRegistrations ending"); } @Test public void testMultipleRegistrationsAtOnePrefix() throws Exception { + LOG.info("testMultipleRegistrationsAtOnePrefix starting"); initEmptyDatastores(); - for (int i = 0; i < 10; i++) { - LOG.debug("Round {}", i); + for (int i = 0; i < 5; i++) { + LOG.info("Round {}", i); final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard( TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME, AbstractTest.MEMBER_2_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION); @@ -382,6 +408,13 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH))); + + final Set 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(), @@ -391,5 +424,14 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { ClusterUtils.getCleanShardName(TestModel.TEST_PATH)); } + LOG.info("testMultipleRegistrationsAtOnePrefix ending"); + } + + @Test + public void testInitialBootstrappingWithNoModuleShards() throws Exception { + LOG.info("testInitialBootstrappingWithNoModuleShards starting"); + initEmptyDatastores("module-shards-default-member-1.conf"); + + // We just verify the DistributedShardedDOMDataTree initialized without error. } }