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%2Fdatabroker%2Factors%2Fdds%2FLocalReadWriteProxyTransactionTest.java;h=dbcdd5960de8e89e92db08cb3c1b35de9dab5763;hp=7f1508d4d4e347bca4fed333c04a62e595b9437e;hb=cb697c760773585fc89b3a52c6cc7e3605de716f;hpb=9e6714ce7693d8e3c00adf72dafce78041d3a7cc diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadWriteProxyTransactionTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadWriteProxyTransactionTest.java index 7f1508d4d4..dbcdd5960d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadWriteProxyTransactionTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadWriteProxyTransactionTest.java @@ -7,7 +7,9 @@ */ package org.opendaylight.controller.cluster.databroker.actors.dds; -import static org.mockito.Matchers.any; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -18,8 +20,8 @@ import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtil import akka.testkit.TestProbe; import com.google.common.base.Ticker; import com.google.common.util.concurrent.ListenableFuture; +import java.util.Optional; import java.util.function.Consumer; -import org.junit.Assert; import org.junit.Test; import org.mockito.Mock; import org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest; @@ -39,9 +41,9 @@ import org.opendaylight.controller.cluster.access.commands.TransactionRequest; import org.opendaylight.controller.cluster.access.commands.TransactionWrite; import org.opendaylight.controller.cluster.access.concepts.Response; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification; -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.tree.api.CursorAwareDataTreeModification; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot; public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTest { @Mock @@ -52,24 +54,24 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes final TransactionIdentifier id, final DataTreeSnapshot snapshot) { when(snapshot.newModification()).thenReturn(modification); - when(modification.readNode(PATH_1)).thenReturn(com.google.common.base.Optional.of(DATA_1)); - when(modification.readNode(PATH_3)).thenReturn(com.google.common.base.Optional.absent()); + when(modification.readNode(PATH_1)).thenReturn(Optional.of(DATA_1)); + when(modification.readNode(PATH_3)).thenReturn(Optional.empty()); return new LocalReadWriteProxyTransaction(parent, TestUtils.TRANSACTION_ID, snapshot); } @Test - public void testIsSnapshotOnly() throws Exception { - Assert.assertFalse(transaction.isSnapshotOnly()); + public void testIsSnapshotOnly() { + assertFalse(transaction.isSnapshotOnly()); } @Test - public void testReadOnlyView() throws Exception { - Assert.assertEquals(modification, transaction.readOnlyView()); + public void testReadOnlyView() { + assertEquals(modification, transaction.readOnlyView()); } @Test @Override - public void testDelete() throws Exception { + public void testDelete() { transaction.delete(PATH_1); verify(modification).delete(PATH_1); } @@ -82,50 +84,50 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes final TransactionTester tester = getTester(); final CommitLocalTransactionRequest req = tester.expectTransactionRequest(CommitLocalTransactionRequest.class); tester.replySuccess(new TransactionCommitSuccess(TRANSACTION_ID, req.getSequence())); - assertFutureEquals(true, result); + assertFutureEquals(Boolean.TRUE, result); } @Test @Override - public void testCanCommit() throws Exception { + public void testCanCommit() { testRequestResponse(transaction::canCommit, CommitLocalTransactionRequest.class, TransactionCanCommitSuccess::new); } @Test @Override - public void testPreCommit() throws Exception { + public void testPreCommit() { testRequestResponse(transaction::preCommit, TransactionPreCommitRequest.class, TransactionPreCommitSuccess::new); } @Test @Override - public void testDoCommit() throws Exception { + public void testDoCommit() { testRequestResponse(transaction::doCommit, TransactionDoCommitRequest.class, TransactionCommitSuccess::new); } @Test @Override - public void testMerge() throws Exception { + public void testMerge() { transaction.merge(PATH_1, DATA_1); verify(modification).merge(PATH_1, DATA_1); } @Test @Override - public void testWrite() throws Exception { + public void testWrite() { transaction.write(PATH_1, DATA_1); verify(modification).write(PATH_1, DATA_1); } @Test - public void testCommitRequest() throws Exception { + public void testCommitRequest() { transaction.doWrite(PATH_1, DATA_1); final boolean coordinated = true; final CommitLocalTransactionRequest request = transaction.commitRequest(coordinated); - Assert.assertEquals(coordinated, request.isCoordinated()); - Assert.assertEquals(modification, request.getModification()); + assertEquals(coordinated, request.isCoordinated()); + assertEquals(modification, request.getModification()); } @Test @@ -137,19 +139,20 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes } @Test - public void testDoSeal() throws Exception { + public void testSealOnly() throws Exception { assertOperationThrowsException(() -> transaction.getSnapshot(), IllegalStateException.class); - transaction.doSeal(); - Assert.assertEquals(modification, transaction.getSnapshot()); + transaction.sealOnly(); + assertEquals(modification, transaction.getSnapshot()); } @Test - public void testFlushState() throws Exception { + public void testFlushState() { final TransactionTester transactionTester = createRemoteProxyTransactionTester(); final RemoteProxyTransaction successor = transactionTester.getTransaction(); doAnswer(LocalProxyTransactionTest::applyToCursorAnswer).when(modification).applyToCursor(any()); - transaction.doSeal(); - transaction.flushState(successor); + transaction.sealOnly(); + final TransactionRequest request = transaction.flushState().get(); + transaction.forwardToSuccessor(successor, request, null); verify(modification).applyToCursor(any()); transactionTester.getTransaction().seal(); transactionTester.getTransaction().directCommit(); @@ -159,17 +162,17 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes } @Test - public void testApplyModifyTransactionRequestCoordinated() throws Exception { + public void testApplyModifyTransactionRequestCoordinated() { applyModifyTransactionRequest(true); } @Test - public void testApplyModifyTransactionRequestSimple() throws Exception { + public void testApplyModifyTransactionRequestSimple() { applyModifyTransactionRequest(false); } @Test - public void testApplyModifyTransactionRequestAbort() throws Exception { + public void testApplyModifyTransactionRequestAbort() { final TestProbe probe = createProbe(); final ModifyTransactionRequestBuilder builder = new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref()); @@ -182,7 +185,7 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes } @Test - public void testHandleForwardedRemotePreCommitRequest() throws Exception { + public void testHandleForwardedRemotePreCommitRequest() { final TestProbe probe = createProbe(); final TransactionPreCommitRequest request = new TransactionPreCommitRequest(TRANSACTION_ID, 0L, probe.ref()); @@ -190,7 +193,7 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes } @Test - public void testHandleForwardedRemoteDoCommitRequest() throws Exception { + public void testHandleForwardedRemoteDoCommitRequest() { final TestProbe probe = createProbe(); final TransactionDoCommitRequest request = new TransactionDoCommitRequest(TRANSACTION_ID, 0L, probe.ref()); @@ -198,7 +201,7 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes } @Test - public void testHandleForwardedRemoteAbortRequest() throws Exception { + public void testHandleForwardedRemoteAbortRequest() { final TestProbe probe = createProbe(); final TransactionAbortRequest request = new TransactionAbortRequest(TRANSACTION_ID, 0L, probe.ref()); @@ -206,7 +209,7 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes } @Test - public void testForwardToLocalCommit() throws Exception { + public void testForwardToLocalCommit() { final TestProbe probe = createProbe(); final DataTreeModification mod = mock(DataTreeModification.class); final TransactionRequest request = @@ -242,8 +245,8 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes verify(modification).delete(PATH_3); final CommitLocalTransactionRequest commitRequest = getTester().expectTransactionRequest(CommitLocalTransactionRequest.class); - Assert.assertEquals(modification, commitRequest.getModification()); - Assert.assertEquals(coordinated, commitRequest.isCoordinated()); + assertEquals(modification, commitRequest.getModification()); + assertEquals(coordinated, commitRequest.isCoordinated()); } -} \ No newline at end of file +}