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%2Fdatastore%2FShardTest.java;h=f396eae9605dc61f8d05a4992833a704bfa1be22;hb=dcc776a5e749d495a66e8753e123a1ddbd15d9c6;hp=9d4381e145282c547ca4ed326402e104163118bc;hpb=7011afc1380ca25ad3de4cc8865f12fe3f5e09cf;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java index 9d4381e145..f396eae960 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java @@ -52,7 +52,6 @@ import org.opendaylight.controller.cluster.access.concepts.MemberName; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException; import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier; -import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats; import org.opendaylight.controller.cluster.datastore.messages.AbortTransaction; import org.opendaylight.controller.cluster.datastore.messages.AbortTransactionReply; import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications; @@ -169,7 +168,7 @@ public class ShardTest extends AbstractShardTest { public void testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration() throws Exception { final CountDownLatch onFirstElectionTimeout = new CountDownLatch(1); final CountDownLatch onChangeListenerRegistered = new CountDownLatch(1); - final Creator creator = new Creator() { + final Creator creator = new Creator<>() { boolean firstElectionTimeout = true; @Override @@ -202,8 +201,8 @@ public class ShardTest extends AbstractShardTest { final ActorRef dclActor = actorFactory.createActor(DataTreeChangeListenerActor.props(listener, path), "testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration-DataChangeListener"); - final TestActorRef shard = actorFactory.createTestActor( - Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), + final TestActorRef shard = actorFactory.createTestActor(Props.create(Shard.class, + new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), "testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration"); final ShardTestKit testKit = new ShardTestKit(getSystem()); @@ -299,8 +298,8 @@ public class ShardTest extends AbstractShardTest { writeToStore(store, TestModel.TEST_PATH, container); - final YangInstanceIdentifier root = YangInstanceIdentifier.EMPTY; - final NormalizedNode expected = readStore(store, root); + final YangInstanceIdentifier root = YangInstanceIdentifier.empty(); + final NormalizedNode expected = readStore(store, root); final Snapshot snapshot = Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(expected)), Collections.emptyList(), 1, 2, 3, 4, -1, null, null); @@ -344,7 +343,7 @@ public class ShardTest extends AbstractShardTest { while (sw.elapsed(TimeUnit.SECONDS) <= 5) { Uninterruptibles.sleepUninterruptibly(75, TimeUnit.MILLISECONDS); - final NormalizedNode actual = readStore(shard, TestModel.TEST_PATH); + final NormalizedNode actual = readStore(shard, TestModel.TEST_PATH); if (actual != null) { assertEquals("Applied state", node, actual); return; @@ -551,7 +550,7 @@ public class ShardTest extends AbstractShardTest { verifyOuterListEntry(shard, 1); - verifyLastApplied(shard, 6); + verifyLastApplied(shard, 3); } @Test @@ -749,7 +748,7 @@ public class ShardTest extends AbstractShardTest { // Verify data in the data store. - final NormalizedNode actualNode = readStore(shard, path); + final NormalizedNode actualNode = readStore(shard, path); assertEquals("Stored node", containerNode, actualNode); } @@ -757,7 +756,7 @@ public class ShardTest extends AbstractShardTest { public void testOnBatchedModificationsWhenNotLeader() { final AtomicBoolean overrideLeaderCalls = new AtomicBoolean(); final ShardTestKit testKit = new ShardTestKit(getSystem()); - final Creator creator = new Creator() { + final Creator creator = new Creator<>() { private static final long serialVersionUID = 1L; @Override @@ -777,8 +776,8 @@ public class ShardTest extends AbstractShardTest { } }; - final TestActorRef shard = actorFactory.createTestActor(Props - .create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), + final TestActorRef shard = actorFactory.createTestActor(Props.create(Shard.class, + new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), "testOnBatchedModificationsWhenNotLeader"); ShardTestKit.waitUntilLeader(shard); @@ -839,7 +838,7 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); final TransactionIdentifier transactionID = nextTransactionId(); - final NormalizedNode containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + final NormalizedNode containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME); if (readWrite) { shard.tell(prepareForwardedReadyTransaction(shard, transactionID, TestModel.TEST_PATH, containerNode, true), testKit.getRef()); @@ -850,7 +849,7 @@ public class ShardTest extends AbstractShardTest { testKit.expectMsgClass(Duration.ofSeconds(5), CommitTransactionReply.class); - final NormalizedNode actualNode = readStore(shard, TestModel.TEST_PATH); + final NormalizedNode actualNode = readStore(shard, TestModel.TEST_PATH); assertEquals(TestModel.TEST_QNAME.getLocalName(), containerNode, actualNode); } @@ -883,7 +882,7 @@ public class ShardTest extends AbstractShardTest { testKit.expectMsgClass(CommitTransactionReply.class); - final NormalizedNode actualNode = readStore(shard, TestModel.OUTER_LIST_PATH); + final NormalizedNode actualNode = readStore(shard, TestModel.OUTER_LIST_PATH); assertEquals(TestModel.OUTER_LIST_QNAME.getLocalName(), mergeData, actualNode); } @@ -928,7 +927,7 @@ public class ShardTest extends AbstractShardTest { shard.tell(new CommitTransaction(txId, CURRENT_VERSION).toSerializable(), testKit.getRef()); testKit.expectMsgClass(CommitTransactionReply.class); - final NormalizedNode actualNode = readStore(shard, TestModel.OUTER_LIST_PATH); + final NormalizedNode actualNode = readStore(shard, TestModel.OUTER_LIST_PATH); assertEquals(TestModel.OUTER_LIST_QNAME.getLocalName(), mergeData, actualNode); } @@ -947,7 +946,7 @@ public class ShardTest extends AbstractShardTest { final Duration duration = Duration.ofSeconds(5); final TransactionIdentifier transactionID = nextTransactionId(); - final NormalizedNode containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + final NormalizedNode containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME); shard.tell(prepareBatchedModifications(transactionID, TestModel.TEST_PATH, containerNode, false), testKit.getRef()); testKit.expectMsgClass(duration, ReadyTransactionReply.class); @@ -964,7 +963,7 @@ public class ShardTest extends AbstractShardTest { shard.tell(new CommitTransaction(transactionID, CURRENT_VERSION).toSerializable(), testKit.getRef()); testKit.expectMsgClass(duration, CommitTransactionReply.class); - final NormalizedNode actualNode = readStore(shard, TestModel.TEST_PATH); + final NormalizedNode actualNode = readStore(shard, TestModel.TEST_PATH); assertEquals(TestModel.TEST_QNAME.getLocalName(), containerNode, actualNode); } @@ -1026,8 +1025,8 @@ public class ShardTest extends AbstractShardTest { // Committed transaction count should increase as usual assertEquals(1, shardStats.getCommittedTransactionsCount()); - // Commit index should advance 2 to account for disabling metadata - assertEquals(2, shardStats.getCommitIndex()); + // Commit index should advance 1 to account for disabling metadata + assertEquals(1, shardStats.getCommitIndex()); } @Test @@ -1084,7 +1083,7 @@ public class ShardTest extends AbstractShardTest { // Wait for the 2nd Tx to complete the canCommit phase. final CountDownLatch latch = new CountDownLatch(1); - canCommitFuture.onComplete(new OnComplete() { + canCommitFuture.onComplete(new OnComplete<>() { @Override public void onComplete(final Throwable failure, final Object resp) { latch.countDown(); @@ -1154,7 +1153,7 @@ public class ShardTest extends AbstractShardTest { // Wait for the 2nd Tx to complete the canCommit phase. final CountDownLatch latch = new CountDownLatch(1); - canCommitFuture.onComplete(new OnComplete() { + canCommitFuture.onComplete(new OnComplete<>() { @Override public void onComplete(final Throwable failure, final Object resp) { latch.countDown(); @@ -1182,7 +1181,7 @@ public class ShardTest extends AbstractShardTest { final Duration duration = Duration.ofSeconds(5); final TransactionIdentifier transactionID1 = nextTransactionId(); - doThrow(new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock canCommit failure")) + doThrow(new DataValidationFailedException(YangInstanceIdentifier.empty(), "mock canCommit failure")) .doNothing().when(dataTree).validate(any(DataTreeModification.class)); shard.tell(newBatchedModifications(transactionID1, TestModel.TEST_PATH, @@ -1223,7 +1222,7 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); - doThrow(new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock canCommit failure")) + doThrow(new DataValidationFailedException(YangInstanceIdentifier.empty(), "mock canCommit failure")) .doNothing().when(dataTree).validate(any(DataTreeModification.class)); final Duration duration = Duration.ofSeconds(5); @@ -1272,8 +1271,8 @@ public class ShardTest extends AbstractShardTest { } }; - final TestActorRef shard = actorFactory.createTestActor(Props - .create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), + final TestActorRef shard = actorFactory.createTestActor(Props.create(Shard.class, + new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), "testAbortWithCommitPending"); ShardTestKit.waitUntilLeader(shard); @@ -1292,7 +1291,7 @@ public class ShardTest extends AbstractShardTest { shard.tell(new CommitTransaction(transactionID, CURRENT_VERSION).toSerializable(), testKit.getRef()); testKit.expectMsgClass(duration, CommitTransactionReply.class); - final NormalizedNode node = readStore(shard, TestModel.TEST_PATH); + final NormalizedNode node = readStore(shard, TestModel.TEST_PATH); // Since we're simulating an abort occurring during replication // and before finish commit, @@ -1360,7 +1359,7 @@ public class ShardTest extends AbstractShardTest { shard.tell(new CommitTransaction(transactionID2, CURRENT_VERSION).toSerializable(), testKit.getRef()); testKit.expectMsgClass(duration, CommitTransactionReply.class); - final NormalizedNode node = readStore(shard, listNodePath); + final NormalizedNode node = readStore(shard, listNodePath); assertNotNull(listNodePath + " not found", node); } @@ -1520,7 +1519,7 @@ public class ShardTest extends AbstractShardTest { testKit.expectMsgClass(duration, CommitTransactionReply.class); - final NormalizedNode node = readStore(shard, TestModel.TEST2_PATH); + final NormalizedNode node = readStore(shard, TestModel.TEST2_PATH); assertNotNull(TestModel.TEST2_PATH + " not found", node); } @@ -1730,14 +1729,13 @@ public class ShardTest extends AbstractShardTest { final Creator creator = () -> new TestShard(newShardBuilder()); - final TestActorRef shard = actorFactory.createTestActor(Props - .create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), - shardActorName); + final TestActorRef shard = actorFactory.createTestActor(Props.create(Shard.class, + new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), shardActorName); ShardTestKit.waitUntilLeader(shard); writeToStore(shard, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - final NormalizedNode expectedRoot = readStore(shard, YangInstanceIdentifier.EMPTY); + final NormalizedNode expectedRoot = readStore(shard, YangInstanceIdentifier.empty()); // Trigger creation of a snapshot by ensuring final RaftActorContext raftActorContext = ((TestShard) shard.underlyingActor()).getRaftActorContext(); @@ -1749,7 +1747,7 @@ public class ShardTest extends AbstractShardTest { } private static void awaitAndValidateSnapshot(final AtomicReference latch, - final AtomicReference savedSnapshot, final NormalizedNode expectedRoot) + final AtomicReference savedSnapshot, final NormalizedNode expectedRoot) throws InterruptedException { assertTrue("Snapshot saved", latch.get().await(5, TimeUnit.SECONDS)); @@ -1761,8 +1759,8 @@ public class ShardTest extends AbstractShardTest { savedSnapshot.set(null); } - private static void verifySnapshot(final Snapshot snapshot, final NormalizedNode expectedRoot) { - final NormalizedNode actual = ((ShardSnapshotState)snapshot.getState()).getSnapshot().getRootNode().get(); + private static void verifySnapshot(final Snapshot snapshot, final NormalizedNode expectedRoot) { + final NormalizedNode actual = ((ShardSnapshotState)snapshot.getState()).getSnapshot().getRootNode().get(); assertEquals("Root node", expectedRoot, actual); } @@ -1780,16 +1778,16 @@ public class ShardTest extends AbstractShardTest { commitTransaction(store, putTransaction); - final NormalizedNode expected = readStore(store, YangInstanceIdentifier.EMPTY); + final NormalizedNode expected = readStore(store, YangInstanceIdentifier.empty()); final DataTreeModification writeTransaction = store.takeSnapshot().newModification(); - writeTransaction.delete(YangInstanceIdentifier.EMPTY); - writeTransaction.write(YangInstanceIdentifier.EMPTY, expected); + writeTransaction.delete(YangInstanceIdentifier.empty()); + writeTransaction.write(YangInstanceIdentifier.empty(), expected); commitTransaction(store, writeTransaction); - final NormalizedNode actual = readStore(store, YangInstanceIdentifier.EMPTY); + final NormalizedNode actual = readStore(store, YangInstanceIdentifier.empty()); assertEquals(expected, actual); }