X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDistributedDataStoreIntegrationTest.java;h=e3aae92f9c2c200d0598600e88dea2cabf9cd4dc;hp=11379a0bf25efb88db839e2c54dfbcc9f32da784;hb=ec870dee9bacb971f11bc747b69e84ac37f5d746;hpb=1a6462c3cdb2cd310ab9503beb18da70f6e3779d diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java index 11379a0bf2..e3aae92f9c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java @@ -45,7 +45,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.junit.After; -import org.junit.Assume; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -64,6 +63,7 @@ import org.opendaylight.controller.cluster.datastore.persisted.MetadataShardData import org.opendaylight.controller.cluster.datastore.persisted.PayloadVersion; import org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState; import org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener; +import org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener; import org.opendaylight.controller.cluster.raft.persisted.Snapshot; import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal; import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore; @@ -111,13 +111,15 @@ public class DistributedDataStoreIntegrationTest { @Parameter public Class testParameter; - private static ActorSystem system; + private ActorSystem system; private final DatastoreContext.Builder datastoreContextBuilder = DatastoreContext.newBuilder() .shardHeartbeatIntervalInMillis(100); @Before public void setUp() throws IOException { + InMemorySnapshotStore.clear(); + InMemoryJournal.clear(); system = ActorSystem.create("cluster-test", ConfigFactory.load().getConfig("Member1")); Address member1Address = AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"); Cluster.get(system).join(member1Address); @@ -125,7 +127,7 @@ public class DistributedDataStoreIntegrationTest { @After public void tearDown() throws IOException { - JavaTestKit.shutdownActorSystem(system); + JavaTestKit.shutdownActorSystem(system, null, Boolean.TRUE); system = null; } @@ -1002,9 +1004,6 @@ public class DistributedDataStoreIntegrationTest { @Test public void testCreateChainedTransactionAfterClose() throws Exception { - //TODO remove when test passes also for ClientBackedDataStore - Assume.assumeTrue(testParameter.equals(DistributedDataStore.class)); - new IntegrationTestKit(getSystem(), datastoreContextBuilder) { { try (AbstractDataStore dataStore = setupAbstractDataStore( @@ -1023,9 +1022,6 @@ public class DistributedDataStoreIntegrationTest { @Test public void testChainWithReadOnlyTxAfterPreviousReady() throws Exception { - //TODO remove when test passes also for ClientBackedDataStore - Assume.assumeTrue(testParameter.equals(DistributedDataStore.class)); - new IntegrationTestKit(getSystem(), datastoreContextBuilder) { { try (final AbstractDataStore dataStore = setupAbstractDataStore( @@ -1070,9 +1066,6 @@ public class DistributedDataStoreIntegrationTest { @Test public void testChainedTransactionFailureWithSingleShard() throws Exception { - //TODO remove when test passes also for ClientBackedDataStore - Assume.assumeTrue(testParameter.equals(DistributedDataStore.class)); - new IntegrationTestKit(getSystem(), datastoreContextBuilder) { { try (final AbstractDataStore dataStore = setupAbstractDataStore( @@ -1116,9 +1109,6 @@ public class DistributedDataStoreIntegrationTest { @Test public void testChainedTransactionFailureWithMultipleShards() throws Exception { - //TODO remove when test passes also for ClientBackedDataStore - Assume.assumeTrue(testParameter.equals(DistributedDataStore.class)); - new IntegrationTestKit(getSystem(), datastoreContextBuilder) { { try (final AbstractDataStore dataStore = setupAbstractDataStore( @@ -1165,9 +1155,6 @@ public class DistributedDataStoreIntegrationTest { @Test public void testChangeListenerRegistration() throws Exception { - //TODO remove when test passes also for ClientBackedDataStore - Assume.assumeTrue(testParameter.equals(DistributedDataStore.class)); - new IntegrationTestKit(getSystem(), datastoreContextBuilder) { { try (final AbstractDataStore dataStore = setupAbstractDataStore( @@ -1183,6 +1170,63 @@ public class DistributedDataStoreIntegrationTest { assertNotNull("registerChangeListener returned null", listenerReg); + IntegrationTestKit.verifyShardState(dataStore, "test-1", + state -> assertEquals("getDataChangeListenerActors", 1, + state.getDataChangeListenerActors().size())); + + // Wait for the initial notification + listener.waitForChangeEvents(TestModel.TEST_PATH); + listener.reset(2); + + // Write 2 updates. + testWriteTransaction(dataStore, TestModel.OUTER_LIST_PATH, + ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); + + YangInstanceIdentifier listPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) + .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).build(); + testWriteTransaction(dataStore, listPath, + ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)); + + // Wait for the 2 updates. + listener.waitForChangeEvents(TestModel.OUTER_LIST_PATH, listPath); + listenerReg.close(); + + IntegrationTestKit.verifyShardState(dataStore, "test-1", + state -> assertEquals("getDataChangeListenerActors", 0, + state.getDataChangeListenerActors().size())); + + testWriteTransaction(dataStore, + YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) + .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).build(), + ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2)); + + listener.expectNoMoreChanges("Received unexpected change after close"); + } + } + }; + } + + @Test + public void testDataTreeChangeListenerRegistration() throws Exception { + new IntegrationTestKit(getSystem(), datastoreContextBuilder) { + { + try (final AbstractDataStore dataStore = setupAbstractDataStore( + testParameter, "testDataTreeChangeListenerRegistration", "test-1")) { + + testWriteTransaction(dataStore, TestModel.TEST_PATH, + ImmutableNodes.containerNode(TestModel.TEST_QNAME)); + + final MockDataTreeChangeListener listener = new MockDataTreeChangeListener(1); + + ListenerRegistration listenerReg = dataStore + .registerTreeChangeListener(TestModel.TEST_PATH, listener); + + assertNotNull("registerTreeChangeListener returned null", listenerReg); + + IntegrationTestKit.verifyShardState(dataStore, "test-1", + state -> assertEquals("getTreeChangeListenerActors", 1, + state.getTreeChangeListenerActors().size())); + // Wait for the initial notification listener.waitForChangeEvents(TestModel.TEST_PATH); listener.reset(2); @@ -1200,6 +1244,10 @@ public class DistributedDataStoreIntegrationTest { listener.waitForChangeEvents(TestModel.OUTER_LIST_PATH, listPath); listenerReg.close(); + IntegrationTestKit.verifyShardState(dataStore, "test-1", + state -> assertEquals("getTreeChangeListenerActors", 0, + state.getTreeChangeListenerActors().size())); + testWriteTransaction(dataStore, YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).build(),