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%2FTransactionProxyTest.java;h=ce1d6f6948482102fdd83ea211b5428a60f0c577;hb=24ee386f244cafa9bd3126ddbba1435969aa76c2;hp=62c03d7617ad12b2992903dda19c3d08c74e0a8d;hpb=7e62b4a59f9e43bcd0585845f1aeb55c44199f27;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java index 62c03d7617..ce1d6f6948 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java @@ -5,16 +5,16 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -79,7 +79,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import scala.concurrent.Promise; @SuppressWarnings({"resource", "checkstyle:IllegalThrows", "checkstyle:AvoidHidingCauseException"}) @@ -90,7 +90,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } interface Invoker { - FluentFuture invoke(TransactionProxy proxy) throws Exception; + FluentFuture invoke(TransactionProxy proxy); } @Test @@ -102,19 +102,19 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class)); - Optional> readOptional = transactionProxy.read( + Optional readOptional = transactionProxy.read( TestModel.TEST_PATH).get(5, TimeUnit.SECONDS); - assertEquals("NormalizedNode isPresent", false, readOptional.isPresent()); + assertFalse("NormalizedNode isPresent", readOptional.isPresent()); - NormalizedNode expectedNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode expectedNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME); doReturn(readDataReply(expectedNode)).when(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class)); readOptional = transactionProxy.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS); - assertEquals("NormalizedNode isPresent", true, readOptional.isPresent()); + assertTrue("NormalizedNode isPresent", readOptional.isPresent()); assertEquals("Response NormalizedNode", expectedNode, readOptional.get()); } @@ -190,7 +190,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { public void testReadWithPriorRecordingOperationSuccessful() throws Exception { ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE); - NormalizedNode expectedNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode expectedNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectBatchedModifications(actorRef, 1); @@ -201,10 +201,10 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { transactionProxy.write(TestModel.TEST_PATH, expectedNode); - Optional> readOptional = transactionProxy.read( + Optional readOptional = transactionProxy.read( TestModel.TEST_PATH).get(5, TimeUnit.SECONDS); - assertEquals("NormalizedNode isPresent", true, readOptional.isPresent()); + assertTrue("NormalizedNode isPresent", readOptional.isPresent()); assertEquals("Response NormalizedNode", expectedNode, readOptional.get()); InOrder inOrder = Mockito.inOrder(mockActorContext); @@ -251,14 +251,14 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).get(); - assertEquals("Exists response", false, exists); + assertEquals("Exists response", Boolean.FALSE, exists); doReturn(dataExistsReply(true)).when(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef)), eqDataExists(), any(Timeout.class)); exists = transactionProxy.exists(TestModel.TEST_PATH).get(); - assertEquals("Exists response", true, exists); + assertEquals("Exists response", Boolean.TRUE, exists); } @Test(expected = PrimaryNotFoundException.class) @@ -299,7 +299,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { public void testExistsWithPriorRecordingOperationSuccessful() throws Exception { ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE); - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectBatchedModifications(actorRef, 1); @@ -312,7 +312,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).get(); - assertEquals("Exists response", true, exists); + assertEquals("Exists response", Boolean.TRUE, exists); InOrder inOrder = Mockito.inOrder(mockActorContext); inOrder.verify(mockActorContext).executeOperationAsync( @@ -329,11 +329,11 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testWrite() throws Exception { + public void testWrite() { dataStoreContextBuilder.shardBatchedModificationCount(1); ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY); - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectBatchedModifications(actorRef, 1); @@ -360,16 +360,16 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { expectBatchedModificationsReady(actorRef); - final NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + final NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); final TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE); final CountDownLatch readComplete = new CountDownLatch(1); final AtomicReference caughtEx = new AtomicReference<>(); com.google.common.util.concurrent.Futures.addCallback(transactionProxy.read(TestModel.TEST_PATH), - new FutureCallback>>() { + new FutureCallback>() { @Override - public void onSuccess(final Optional> result) { + public void onSuccess(final Optional result) { try { transactionProxy.write(TestModel.TEST_PATH, nodeToWrite); } catch (Exception e) { @@ -418,11 +418,11 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testMerge() throws Exception { + public void testMerge() { dataStoreContextBuilder.shardBatchedModificationCount(1); ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY); - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectBatchedModifications(actorRef, 1); @@ -434,7 +434,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testDelete() throws Exception { + public void testDelete() { dataStoreContextBuilder.shardBatchedModificationCount(1); ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY); @@ -448,10 +448,10 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testReadWrite() throws Exception { + public void testReadWrite() { ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE); - final NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + final NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class)); @@ -476,10 +476,10 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testReadyWithReadWrite() throws Exception { + public void testReadyWithReadWrite() { ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE); - final NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + final NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class)); @@ -508,7 +508,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testReadyWithNoModifications() throws Exception { + public void testReadyWithNoModifications() { ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE); doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync( @@ -533,7 +533,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testReadyWithMultipleShardWrites() throws Exception { + public void testReadyWithMultipleShardWrites() { ActorRef actorRef1 = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY); ActorRef actorRef2 = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY, @@ -572,32 +572,29 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { ArgumentCaptor batchedMods = ArgumentCaptor.forClass(BatchedModifications.class); verify(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef1)), batchedMods.capture(), any(Timeout.class)); - assertEquals("Participating shards present", true, - batchedMods.getValue().getParticipatingShardNames().isPresent()); + assertTrue("Participating shards present", batchedMods.getValue().getParticipatingShardNames().isPresent()); assertEquals("Participating shards", expShardNames, batchedMods.getValue().getParticipatingShardNames().get()); batchedMods = ArgumentCaptor.forClass(BatchedModifications.class); verify(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef2)), batchedMods.capture(), any(Timeout.class)); - assertEquals("Participating shards present", true, - batchedMods.getValue().getParticipatingShardNames().isPresent()); + assertTrue("Participating shards present", batchedMods.getValue().getParticipatingShardNames().isPresent()); assertEquals("Participating shards", expShardNames, batchedMods.getValue().getParticipatingShardNames().get()); ArgumentCaptor readyLocalTx = ArgumentCaptor.forClass(ReadyLocalTransaction.class); verify(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef3)), readyLocalTx.capture(), any(Timeout.class)); - assertEquals("Participating shards present", true, - readyLocalTx.getValue().getParticipatingShardNames().isPresent()); + assertTrue("Participating shards present", readyLocalTx.getValue().getParticipatingShardNames().isPresent()); assertEquals("Participating shards", expShardNames, readyLocalTx.getValue().getParticipatingShardNames().get()); } @Test - public void testReadyWithWriteOnlyAndLastBatchPending() throws Exception { + public void testReadyWithWriteOnlyAndLastBatchPending() { dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true); ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY); - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectBatchedModificationsReady(actorRef, true); @@ -619,11 +616,11 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testReadyWithWriteOnlyAndLastBatchEmpty() throws Exception { + public void testReadyWithWriteOnlyAndLastBatchEmpty() { dataStoreContextBuilder.shardBatchedModificationCount(1).writeOnlyTransactionOptimizationsEnabled(true); ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY); - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectBatchedModificationsReady(actorRef, true); @@ -647,12 +644,12 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testReadyWithReplyFailure() throws Exception { + public void testReadyWithReplyFailure() { dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true); ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY); - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectFailedBatchedModifications(actorRef); @@ -668,7 +665,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testReadyWithDebugContextEnabled() throws Exception { + public void testReadyWithDebugContextEnabled() { dataStoreContextBuilder.transactionDebugContextEnabled(true); ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE); @@ -687,7 +684,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testReadyWithLocalTransaction() throws Exception { + public void testReadyWithLocalTransaction() { ActorRef shardActorRef = getSystem().actorOf(Props.create(DoNothingActor.class)); doReturn(getSystem().actorSelection(shardActorRef.path())).when(mockActorContext) @@ -700,7 +697,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { expectReadyLocalTransaction(shardActorRef, true); - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); transactionProxy.write(TestModel.TEST_PATH, nodeToWrite); DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready(); @@ -710,12 +707,11 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { ArgumentCaptor readyLocalTx = ArgumentCaptor.forClass(ReadyLocalTransaction.class); verify(mockActorContext).executeOperationAsync( eq(actorSelection(shardActorRef)), readyLocalTx.capture(), any(Timeout.class)); - assertEquals("Participating shards present", false, - readyLocalTx.getValue().getParticipatingShardNames().isPresent()); + assertFalse("Participating shards present", readyLocalTx.getValue().getParticipatingShardNames().isPresent()); } @Test - public void testReadyWithLocalTransactionWithFailure() throws Exception { + public void testReadyWithLocalTransactionWithFailure() { ActorRef shardActorRef = getSystem().actorOf(Props.create(DoNothingActor.class)); doReturn(getSystem().actorSelection(shardActorRef.path())).when(mockActorContext) @@ -732,7 +728,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { expectReadyLocalTransaction(shardActorRef, true); - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); transactionProxy.write(TestModel.TEST_PATH, nodeToWrite); DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready(); @@ -740,12 +736,12 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { verifyCohortFutures((SingleCommitCohortProxy)ready, RuntimeException.class); } - private void testWriteOnlyTxWithFindPrimaryShardFailure(final Exception toThrow) throws Exception { + private void testWriteOnlyTxWithFindPrimaryShardFailure(final Exception toThrow) { doReturn(Futures.failed(toThrow)).when(mockActorContext).findPrimaryShardAsync(anyString()); TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY); - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); transactionProxy.merge(TestModel.TEST_PATH, nodeToWrite); @@ -761,22 +757,22 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testWriteOnlyTxWithPrimaryNotFoundException() throws Exception { + public void testWriteOnlyTxWithPrimaryNotFoundException() { testWriteOnlyTxWithFindPrimaryShardFailure(new PrimaryNotFoundException("mock")); } @Test - public void testWriteOnlyTxWithNotInitializedException() throws Exception { + public void testWriteOnlyTxWithNotInitializedException() { testWriteOnlyTxWithFindPrimaryShardFailure(new NotInitializedException("mock")); } @Test - public void testWriteOnlyTxWithNoShardLeaderException() throws Exception { + public void testWriteOnlyTxWithNoShardLeaderException() { testWriteOnlyTxWithFindPrimaryShardFailure(new NoShardLeaderException("mock")); } @Test - public void testReadyWithInvalidReplyMessageType() throws Exception { + public void testReadyWithInvalidReplyMessageType() { dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true); ActorRef actorRef1 = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY); @@ -812,7 +808,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testClose() throws Exception { + public void testClose() { ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE); doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync( @@ -973,15 +969,14 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { return dataTree; } - private static DataTree createDataTree(final NormalizedNode readResponse) { + private static DataTree createDataTree(final NormalizedNode readResponse) { DataTree dataTree = mock(DataTree.class); DataTreeSnapshot dataTreeSnapshot = mock(DataTreeSnapshot.class); DataTreeModification dataTreeModification = mock(DataTreeModification.class); doReturn(dataTreeSnapshot).when(dataTree).takeSnapshot(); doReturn(dataTreeModification).when(dataTreeSnapshot).newModification(); - doReturn(java.util.Optional.of(readResponse)).when(dataTreeModification).readNode( - any(YangInstanceIdentifier.class)); + doReturn(Optional.of(readResponse)).when(dataTreeModification).readNode(any(YangInstanceIdentifier.class)); return dataTree; } @@ -990,7 +985,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { @Test public void testWriteCompletionForLocalShard() { completeOperationLocal(transactionProxy -> { - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); transactionProxy.write(TestModel.TEST_PATH, nodeToWrite); @@ -1002,7 +997,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { @Test public void testWriteThrottlingWhenShardFound() { throttleOperation(transactionProxy -> { - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectIncompleteBatchedModifications(); @@ -1016,7 +1011,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { public void testWriteThrottlingWhenShardNotFound() { // Confirm that there is no throttling when the Shard is not found completeOperation(transactionProxy -> { - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectBatchedModifications(2); @@ -1031,7 +1026,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { @Test public void testWriteCompletion() { completeOperation(transactionProxy -> { - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectBatchedModifications(2); @@ -1044,7 +1039,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { @Test public void testMergeThrottlingWhenShardFound() { throttleOperation(transactionProxy -> { - NormalizedNode nodeToMerge = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToMerge = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectIncompleteBatchedModifications(); @@ -1057,7 +1052,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { @Test public void testMergeThrottlingWhenShardNotFound() { completeOperation(transactionProxy -> { - NormalizedNode nodeToMerge = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToMerge = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectBatchedModifications(2); @@ -1070,7 +1065,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { @Test public void testMergeCompletion() { completeOperation(transactionProxy -> { - NormalizedNode nodeToMerge = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToMerge = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectBatchedModifications(2); @@ -1084,7 +1079,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { @Test public void testMergeCompletionForLocalShard() { completeOperationLocal(transactionProxy -> { - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); transactionProxy.merge(TestModel.TEST_PATH, nodeToWrite); @@ -1172,7 +1167,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { @Test public void testReadCompletion() { completeOperation(transactionProxy -> { - NormalizedNode nodeToRead = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToRead = ImmutableNodes.containerNode(TestModel.TEST_QNAME); doReturn(readDataReply(nodeToRead)).when(mockActorContext).executeOperationAsync( any(ActorSelection.class), eqReadData(), any(Timeout.class)); @@ -1186,7 +1181,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { @Test public void testReadCompletionForLocalShard() { - final NormalizedNode nodeToRead = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + final NormalizedNode nodeToRead = ImmutableNodes.containerNode(TestModel.TEST_QNAME); completeOperationLocal(transactionProxy -> { transactionProxy.read(TestModel.TEST_PATH); @@ -1247,7 +1242,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { @Test public void testExistsCompletionForLocalShard() { - final NormalizedNode nodeToRead = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + final NormalizedNode nodeToRead = ImmutableNodes.containerNode(TestModel.TEST_QNAME); completeOperationLocal(transactionProxy -> { transactionProxy.exists(TestModel.TEST_PATH); @@ -1270,7 +1265,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { public void testReadyThrottling() { throttleOperation(transactionProxy -> { - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); expectBatchedModifications(1); @@ -1283,8 +1278,8 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { @Test public void testReadyThrottlingWithTwoTransactionContexts() { throttleOperation(transactionProxy -> { - NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); - NormalizedNode carsNode = ImmutableNodes.containerNode(CarsModel.BASE_QNAME); + NormalizedNode nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode carsNode = ImmutableNodes.containerNode(CarsModel.BASE_QNAME); expectBatchedModifications(2); @@ -1299,7 +1294,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { .getOperationTimeoutInMillis()) * 2); } - private void testModificationOperationBatching(final TransactionType type) throws Exception { + private void testModificationOperationBatching(final TransactionType type) { int shardBatchedModificationCount = 3; dataStoreContextBuilder.shardBatchedModificationCount(shardBatchedModificationCount); @@ -1308,22 +1303,22 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { expectBatchedModifications(actorRef, shardBatchedModificationCount); YangInstanceIdentifier writePath1 = TestModel.TEST_PATH; - NormalizedNode writeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode writeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); YangInstanceIdentifier writePath2 = TestModel.OUTER_LIST_PATH; - NormalizedNode writeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME); + NormalizedNode writeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME); YangInstanceIdentifier writePath3 = TestModel.INNER_LIST_PATH; - NormalizedNode writeNode3 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME); + NormalizedNode writeNode3 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME); YangInstanceIdentifier mergePath1 = TestModel.TEST_PATH; - NormalizedNode mergeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode mergeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); YangInstanceIdentifier mergePath2 = TestModel.OUTER_LIST_PATH; - NormalizedNode mergeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME); + NormalizedNode mergeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME); YangInstanceIdentifier mergePath3 = TestModel.INNER_LIST_PATH; - NormalizedNode mergeNode3 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME); + NormalizedNode mergeNode3 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME); YangInstanceIdentifier deletePath1 = TestModel.TEST_PATH; YangInstanceIdentifier deletePath2 = TestModel.OUTER_LIST_PATH; @@ -1358,17 +1353,17 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testReadWriteModificationOperationBatching() throws Exception { + public void testReadWriteModificationOperationBatching() { testModificationOperationBatching(READ_WRITE); } @Test - public void testWriteOnlyModificationOperationBatching() throws Exception { + public void testWriteOnlyModificationOperationBatching() { testModificationOperationBatching(WRITE_ONLY); } @Test - public void testOptimizedWriteOnlyModificationOperationBatching() throws Exception { + public void testOptimizedWriteOnlyModificationOperationBatching() { dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true); testModificationOperationBatching(WRITE_ONLY); } @@ -1384,16 +1379,16 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { expectBatchedModifications(actorRef, shardBatchedModificationCount); final YangInstanceIdentifier writePath1 = TestModel.TEST_PATH; - final NormalizedNode writeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + final NormalizedNode writeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); YangInstanceIdentifier writePath2 = TestModel.OUTER_LIST_PATH; - NormalizedNode writeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME); + NormalizedNode writeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME); final YangInstanceIdentifier mergePath1 = TestModel.TEST_PATH; - final NormalizedNode mergeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + final NormalizedNode mergeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); YangInstanceIdentifier mergePath2 = TestModel.INNER_LIST_PATH; - NormalizedNode mergeNode2 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME); + NormalizedNode mergeNode2 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME); final YangInstanceIdentifier deletePath = TestModel.OUTER_LIST_PATH; @@ -1411,9 +1406,9 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { transactionProxy.write(writePath1, writeNode1); transactionProxy.write(writePath2, writeNode2); - Optional> readOptional = transactionProxy.read(writePath2).get(5, TimeUnit.SECONDS); + Optional readOptional = transactionProxy.read(writePath2).get(5, TimeUnit.SECONDS); - assertEquals("NormalizedNode isPresent", true, readOptional.isPresent()); + assertTrue("NormalizedNode isPresent", readOptional.isPresent()); assertEquals("Response NormalizedNode", writeNode2, readOptional.get()); transactionProxy.merge(mergePath1, mergeNode1); @@ -1424,9 +1419,9 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { transactionProxy.delete(deletePath); Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).get(); - assertEquals("Exists response", true, exists); + assertEquals("Exists response", Boolean.TRUE, exists); - assertEquals("NormalizedNode isPresent", true, readOptional.isPresent()); + assertTrue("NormalizedNode isPresent", readOptional.isPresent()); assertEquals("Response NormalizedNode", mergeNode2, readOptional.get()); List batchedModifications = captureBatchedModifications(actorRef); @@ -1461,16 +1456,15 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testReadRoot() throws ReadFailedException, InterruptedException, ExecutionException, - java.util.concurrent.TimeoutException { - SchemaContext schemaContext = SchemaContextHelper.full(); + public void testReadRoot() throws InterruptedException, ExecutionException, java.util.concurrent.TimeoutException { + EffectiveModelContext schemaContext = SchemaContextHelper.full(); Configuration configuration = mock(Configuration.class); doReturn(configuration).when(mockActorContext).getConfiguration(); doReturn(schemaContext).when(mockActorContext).getSchemaContext(); doReturn(Sets.newHashSet("test", "cars")).when(configuration).getAllShardNames(); - NormalizedNode expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); - NormalizedNode expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME); + NormalizedNode expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + NormalizedNode expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME); setUpReadData("test", NormalizedNodeAggregatorTest.getRootNode(expectedNode1, schemaContext)); setUpReadData("cars", NormalizedNodeAggregatorTest.getRootNode(expectedNode2, schemaContext)); @@ -1481,19 +1475,19 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY); - Optional> readOptional = transactionProxy.read( - YangInstanceIdentifier.EMPTY).get(5, TimeUnit.SECONDS); + Optional readOptional = transactionProxy.read( + YangInstanceIdentifier.empty()).get(5, TimeUnit.SECONDS); - assertEquals("NormalizedNode isPresent", true, readOptional.isPresent()); + assertTrue("NormalizedNode isPresent", readOptional.isPresent()); - NormalizedNode normalizedNode = readOptional.get(); + NormalizedNode normalizedNode = readOptional.get(); - assertTrue("Expect value to be a Collection", normalizedNode.getValue() instanceof Collection); + assertTrue("Expect value to be a Collection", normalizedNode.body() instanceof Collection); @SuppressWarnings("unchecked") - Collection> collection = (Collection>) normalizedNode.getValue(); + Collection collection = (Collection) normalizedNode.body(); - for (NormalizedNode node : collection) { + for (NormalizedNode node : collection) { assertTrue("Expected " + node + " to be a ContainerNode", node instanceof ContainerNode); } @@ -1509,7 +1503,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { } - private void setUpReadData(final String shardName, final NormalizedNode expectedNode) { + private void setUpReadData(final String shardName, final NormalizedNode expectedNode) { ActorSystem actorSystem = getSystem(); ActorRef shardActorRef = getSystem().actorOf(Props.create(DoNothingActor.class)); @@ -1529,6 +1523,6 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { eqCreateTransaction(memberName, TransactionType.READ_ONLY), any(Timeout.class)); doReturn(readDataReply(expectedNode)).when(mockActorContext).executeOperationAsync( - eq(actorSelection(txActorRef)), eqReadData(YangInstanceIdentifier.EMPTY), any(Timeout.class)); + eq(actorSelection(txActorRef)), eqReadData(YangInstanceIdentifier.empty()), any(Timeout.class)); } }