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%2FDistributedShardedDOMDataTreeTest.java;h=8faaf6ac0cca1a02567b6a44eac036907ec1fd8d;hb=def2aa2710cabf4d1867e8ce5dd847d380ef9393;hp=91435bed5c1efd8076ee52b59ff91ffc3f506049;hpb=20f8f30f4bbf1e982672c1f883a6a18b0e4539de;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeTest.java index 91435bed5c..8faaf6ac0c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeTest.java @@ -10,6 +10,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.mockito.Matchers.anyCollection; import static org.mockito.Matchers.anyMap; import static org.mockito.Mockito.doNothing; @@ -55,6 +56,10 @@ import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder; import org.opendaylight.controller.cluster.datastore.DistributedDataStore; import org.opendaylight.controller.cluster.datastore.IntegrationTestKit; import org.opendaylight.controller.cluster.datastore.utils.ClusterUtils; +import org.opendaylight.controller.cluster.dom.api.CDSDataTreeProducer; +import org.opendaylight.controller.cluster.dom.api.CDSShardAccess; +import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal; +import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore; import org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration; import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; @@ -82,7 +87,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMa import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Ignore("distributed-data is broken needs to be removed") public class DistributedShardedDOMDataTreeTest extends AbstractTest { private static final Logger LOG = LoggerFactory.getLogger(DistributedShardedDOMDataTreeRemotingTest.class); @@ -99,6 +103,8 @@ public class DistributedShardedDOMDataTreeTest extends AbstractTest { .node(TestModel.INNER_LIST_QNAME)); private static final Set SINGLE_MEMBER = Collections.singleton(AbstractTest.MEMBER_NAME); + private static final String MODULE_SHARDS_CONFIG = "module-shards-cars-member-1.conf"; + private ActorSystem leaderSystem; private final Builder leaderDatastoreContextBuilder = @@ -109,6 +115,7 @@ public class DistributedShardedDOMDataTreeTest extends AbstractTest { org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION); private DistributedDataStore leaderDistributedDataStore; + private DistributedDataStore operDistributedDatastore; private IntegrationTestKit leaderTestKit; private DistributedShardedDOMDataTree leaderShardFactory; @@ -124,6 +131,9 @@ public class DistributedShardedDOMDataTreeTest extends AbstractTest { public void setUp() { MockitoAnnotations.initMocks(this); + InMemoryJournal.clear(); + InMemorySnapshotStore.clear(); + leaderSystem = ActorSystem.create("cluster-test", ConfigFactory.load().getConfig("Member1")); Cluster.get(leaderSystem).join(MEMBER_1_ADDRESS); @@ -132,30 +142,43 @@ public class DistributedShardedDOMDataTreeTest extends AbstractTest { } @After - public void tearDown() { + public void tearDown() throws Exception { if (leaderDistributedDataStore != null) { leaderDistributedDataStore.close(); } + if (operDistributedDatastore != null) { + operDistributedDatastore.close(); + } + JavaTestKit.shutdownActorSystem(leaderSystem); + + InMemoryJournal.clear(); + InMemorySnapshotStore.clear(); } - private void initEmptyDatastore(final String type) { + private void initEmptyDatastores() throws Exception { leaderTestKit = new IntegrationTestKit(leaderSystem, leaderDatastoreContextBuilder); - leaderDistributedDataStore = - leaderTestKit.setupDistributedDataStoreWithoutConfig(type, SchemaContextHelper.full()); + leaderDistributedDataStore = leaderTestKit.setupDistributedDataStore( + "config", MODULE_SHARDS_CONFIG, "empty-modules.conf", true, + SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext()); + operDistributedDatastore = leaderTestKit.setupDistributedDataStore( + "operational", MODULE_SHARDS_CONFIG, "empty-modules.conf",true, + SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext()); leaderShardFactory = new DistributedShardedDOMDataTree(leaderSystemProvider, - leaderDistributedDataStore, + operDistributedDatastore, leaderDistributedDataStore); + + leaderShardFactory.init(); } @Test public void testWritesIntoDefaultShard() throws Exception { - initEmptyDatastore("config"); + initEmptyDatastores(); final DOMDataTreeIdentifier configRoot = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY); @@ -180,7 +203,7 @@ public class DistributedShardedDOMDataTreeTest extends AbstractTest { @Test public void testSingleNodeWrites() throws Exception { - initEmptyDatastore("config"); + initEmptyDatastores(); final DistributedShardRegistration shardRegistration = waitOnAsyncTask( leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)), @@ -198,6 +221,7 @@ public class DistributedShardedDOMDataTreeTest extends AbstractTest { YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(TestModel.NAME_QNAME).build(); final LeafNode valueToCheck = ImmutableLeafNodeBuilder.create().withNodeIdentifier( new NodeIdentifier(TestModel.NAME_QNAME)).withValue("Test Value").build(); + LOG.debug("Writing data {} at {}, cursor {}", nameId.getLastPathArgument(), valueToCheck, cursor); cursor.write(nameId.getLastPathArgument(), valueToCheck); @@ -225,11 +249,13 @@ public class DistributedShardedDOMDataTreeTest extends AbstractTest { verifyNoMoreInteractions(mockedDataTreeListener); + shardRegistration.close().toCompletableFuture().get(); + } @Test public void testMultipleWritesIntoSingleMapEntry() throws Exception { - initEmptyDatastore("config"); + initEmptyDatastores(); final DistributedShardRegistration shardRegistration = waitOnAsyncTask( leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)), @@ -313,10 +339,11 @@ public class DistributedShardedDOMDataTreeTest extends AbstractTest { // top level shard at TEST element, with subshards on each outer-list map entry @Test + @Ignore public void testMultipleShardLevels() throws Exception { - initEmptyDatastore("config"); + initEmptyDatastores(); - final DistributedShardRegistration testShardId = waitOnAsyncTask( + final DistributedShardRegistration testShardReg = waitOnAsyncTask( leaderShardFactory.createDistributedShard(TEST_ID, SINGLE_MEMBER), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION); @@ -373,8 +400,7 @@ public class DistributedShardedDOMDataTreeTest extends AbstractTest { leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID), true, Collections.emptyList()); - // need 6 invocations, first initial thats from the parent shard, and then each individual subshard - verify(mockedDataTreeListener, timeout(10000).times(6)).onDataTreeChanged(captorForChanges.capture(), + verify(mockedDataTreeListener, timeout(35000).atLeast(2)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture()); verifyNoMoreInteractions(mockedDataTreeListener); final List>> allSubtrees = captorForSubtrees.getAllValues(); @@ -391,49 +417,19 @@ public class DistributedShardedDOMDataTreeTest extends AbstractTest { .withValue(createOuterEntries(listSize, "testing-values")).build()) .build(); - assertEquals(expected, actual); - } - - @Test - public void testDistributedData() throws Exception { - initEmptyDatastore("config"); - waitOnAsyncTask( - leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)), - DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION); - - waitOnAsyncTask( - leaderShardFactory.createDistributedShard( - new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_CONTAINER_PATH), - Lists.newArrayList(AbstractTest.MEMBER_NAME)), - DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION); + for (final DistributedShardRegistration registration : registrations) { + waitOnAsyncTask(registration.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION); + } - waitOnAsyncTask( - leaderShardFactory.createDistributedShard( - new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.INNER_LIST_PATH), - Lists.newArrayList(AbstractTest.MEMBER_NAME)), - DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION); - - waitOnAsyncTask( - leaderShardFactory.createDistributedShard( - new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.JUNK_PATH), - Lists.newArrayList(AbstractTest.MEMBER_NAME)), - DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION); - - leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), - ClusterUtils.getCleanShardName(TestModel.TEST_PATH)); - leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), - ClusterUtils.getCleanShardName(TestModel.OUTER_CONTAINER_PATH)); - leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), - ClusterUtils.getCleanShardName(TestModel.INNER_LIST_PATH)); - leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), - ClusterUtils.getCleanShardName(TestModel.JUNK_PATH)); + waitOnAsyncTask(testShardReg.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION); + assertEquals(expected, actual); } @Test public void testMultipleRegistrationsAtOnePrefix() throws Exception { - initEmptyDatastore("config"); + initEmptyDatastores(); for (int i = 0; i < 10; i++) { LOG.debug("Round {}", i); @@ -454,6 +450,40 @@ public class DistributedShardedDOMDataTreeTest extends AbstractTest { } } + @Test + public void testCDSDataTreeProducer() throws Exception { + initEmptyDatastores(); + + final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard( + TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)), + DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION); + + leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), + ClusterUtils.getCleanShardName(TestModel.TEST_PATH)); + + assertNotNull(findLocalShard(leaderDistributedDataStore.getActorContext(), + ClusterUtils.getCleanShardName(TestModel.TEST_PATH))); + + + final DOMDataTreeIdentifier configRoot = + new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY); + final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot)); + + assertTrue(producer instanceof CDSDataTreeProducer); + + final CDSDataTreeProducer cdsProducer = (CDSDataTreeProducer) producer; + CDSShardAccess shardAccess = cdsProducer.getShardAccess(TEST_ID); + assertEquals(shardAccess.getShardIdentifier(), TEST_ID); + + shardAccess = cdsProducer.getShardAccess(INNER_LIST_ID); + assertEquals(TEST_ID, shardAccess.getShardIdentifier()); + + shardAccess = cdsProducer.getShardAccess(configRoot); + assertEquals(configRoot, shardAccess.getShardIdentifier()); + + waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION); + } + private static Collection createOuterEntries(final int amount, final String valuePrefix) { final Collection ret = new ArrayList<>(); for (int i = 0; i < amount; i++) {