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%2FSimpleShardDataTreeCohortTest.java;h=65cf2eac375ee5e3fd6b1ed912361ded25899f3c;hp=5b218715737b6a34032aacc0beb01826e2da1444;hb=d73c2f32f32d48fbe1b86710fb52813fa728b403;hpb=85c23944a273c338098997700b14f3a802025bb5 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohortTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohortTest.java index 5b21871573..65cf2eac37 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohortTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohortTest.java @@ -8,9 +8,8 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertSame; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -19,27 +18,27 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import com.google.common.primitives.UnsignedLong; import com.google.common.util.concurrent.FutureCallback; -import java.util.Collections; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; -import scala.concurrent.Promise; /** * Unit tests for SimpleShardDataTreeCohort. * * @author Thomas Pantelis */ +@RunWith(MockitoJUnitRunner.StrictStubs.class) public class SimpleShardDataTreeCohortTest extends AbstractTest { @Mock private ShardDataTree mockShardDataTree; @@ -56,24 +55,22 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { private SimpleShardDataTreeCohort cohort; @Before - public void setup() throws Exception { - MockitoAnnotations.initMocks(this); - - doNothing().when(mockUserCohorts).commit(); + public void setup() { + doReturn(Optional.empty()).when(mockUserCohorts).commit(); doReturn(Optional.empty()).when(mockUserCohorts).abort(); - cohort = new SimpleShardDataTreeCohort.Normal(mockShardDataTree, mockModification, nextTransactionId(), - mockUserCohorts); + cohort = new SimpleShardDataTreeCohort(mockShardDataTree, mockModification, nextTransactionId(), + mockUserCohorts, Optional.empty()); } @Test - public void testCanCommitSuccess() throws Exception { + public void testCanCommitSuccess() { canCommitSuccess(); } private void canCommitSuccess() { doAnswer(invocation -> { - invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).successfulCanCommit(); + invocation.getArgument(0).successfulCanCommit(); return null; }).when(mockShardDataTree).startCanCommit(cohort); @@ -85,9 +82,9 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { verifyNoMoreInteractions(callback); } - private void testValidatationPropagates(final Exception cause) throws DataValidationFailedException { + private void testValidatationPropagates(final Exception cause) { doAnswer(invocation -> { - invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).failedCanCommit(cause); + invocation.getArgument(0).failedCanCommit(cause); return null; }).when(mockShardDataTree).startCanCommit(cohort); @@ -100,24 +97,24 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { } @Test - public void testCanCommitWithConflictingModEx() throws DataValidationFailedException { - testValidatationPropagates(new ConflictingModificationAppliedException(YangInstanceIdentifier.EMPTY, "mock")); + public void testCanCommitWithConflictingModEx() { + testValidatationPropagates(new ConflictingModificationAppliedException(YangInstanceIdentifier.empty(), "mock")); } @Test - public void testCanCommitWithDataValidationEx() throws DataValidationFailedException { - testValidatationPropagates(new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock")); + public void testCanCommitWithDataValidationEx() { + testValidatationPropagates(new DataValidationFailedException(YangInstanceIdentifier.empty(), "mock")); } @Test - public void testCanCommitWithIllegalArgumentEx() throws DataValidationFailedException { + public void testCanCommitWithIllegalArgumentEx() { testValidatationPropagates(new IllegalArgumentException("mock")); } private DataTreeCandidateTip preCommitSuccess() { final DataTreeCandidateTip mockCandidate = mock(DataTreeCandidateTip.class); doAnswer(invocation -> { - invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).successfulPreCommit(mockCandidate); + invocation.getArgument(0).successfulPreCommit(mockCandidate); return null; }).when(mockShardDataTree).startPreCommit(cohort); @@ -134,12 +131,12 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { } @Test - public void testPreCommitAndCommitSuccess() throws Exception { + public void testPreCommitAndCommitSuccess() { canCommitSuccess(); final DataTreeCandidateTip candidate = preCommitSuccess(); doAnswer(invocation -> { - invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).successfulCommit(UnsignedLong.valueOf(0)); + invocation.getArgument(0).successfulCommit(UnsignedLong.valueOf(0), () -> { }); return null; }).when(mockShardDataTree).startCommit(cohort, candidate); @@ -154,12 +151,12 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { } @Test - public void testPreCommitWithIllegalArgumentEx() throws Exception { + public void testPreCommitWithIllegalArgumentEx() { canCommitSuccess(); final Exception cause = new IllegalArgumentException("mock"); doAnswer(invocation -> { - invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).failedPreCommit(cause); + invocation.getArgument(0).failedPreCommit(cause); return null; }).when(mockShardDataTree).startPreCommit(cohort); @@ -174,7 +171,7 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { } @Test - public void testPreCommitWithReportedFailure() throws Exception { + public void testPreCommitWithReportedFailure() { canCommitSuccess(); final Exception cause = new IllegalArgumentException("mock"); @@ -197,7 +194,7 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { final Exception cause = new IllegalArgumentException("mock"); doAnswer(invocation -> { - invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).failedCommit(cause); + invocation.getArgument(0).failedCommit(cause); return null; }).when(mockShardDataTree).startCommit(cohort, candidate); @@ -230,7 +227,7 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { @Test public void testAbort() throws Exception { - doReturn(true).when(mockShardDataTree).startAbort(cohort); + doReturn(Boolean.TRUE).when(mockShardDataTree).startAbort(cohort); abort(cohort).get(); verify(mockShardDataTree).startAbort(cohort); @@ -240,13 +237,10 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { public void testAbortWithCohorts() throws Exception { doReturn(true).when(mockShardDataTree).startAbort(cohort); - final Promise> cohortFuture = akka.dispatch.Futures.promise(); - doReturn(Optional.of(cohortFuture.future())).when(mockUserCohorts).abort(); + doReturn(Optional.of(CompletableFuture.completedFuture(null))).when(mockUserCohorts).abort(); final Future abortFuture = abort(cohort); - cohortFuture.success(Collections.emptyList()); - abortFuture.get(); verify(mockShardDataTree).startAbort(cohort); }