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%2FSimpleShardDataTreeCohortTest.java;h=4550894fed33c07f30d8e7ba6b2a133df387297a;hb=refs%2Fchanges%2F85%2F66885%2F6;hp=1830290d6013a18149ff413344496cfb99e8aaa2;hpb=a47dd7a5d21ca68804a6d0e2e3ca765f223c2ef4;p=controller.git 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 1830290d60..4550894fed 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 @@ -10,17 +10,17 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertSame; import static org.mockito.Matchers.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; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; + import com.google.common.primitives.UnsignedLong; import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.ListenableFuture; -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.mockito.Mock; @@ -31,7 +31,6 @@ 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. @@ -57,7 +56,7 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { public void setup() throws Exception { MockitoAnnotations.initMocks(this); - doNothing().when(mockUserCohorts).commit(); + doReturn(Optional.empty()).when(mockUserCohorts).commit(); doReturn(Optional.empty()).when(mockUserCohorts).abort(); cohort = new SimpleShardDataTreeCohort(mockShardDataTree, mockModification, nextTransactionId(), @@ -137,13 +136,13 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { final DataTreeCandidateTip candidate = preCommitSuccess(); doAnswer(invocation -> { - invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).successfulCommit(UnsignedLong.valueOf(0)); + invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).successfulCommit(UnsignedLong.valueOf(0), + () -> { }); return null; }).when(mockShardDataTree).startCommit(cohort, candidate); @SuppressWarnings("unchecked") - final - FutureCallback mockCommitCallback = mock(FutureCallback.class); + final FutureCallback mockCommitCallback = mock(FutureCallback.class); cohort.commit(mockCommitCallback); verify(mockCommitCallback).onSuccess(any(UnsignedLong.class)); @@ -153,7 +152,7 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { } @Test - public void testPreCommitWithIllegalArgumentEx() throws Throwable { + public void testPreCommitWithIllegalArgumentEx() throws Exception { canCommitSuccess(); final Exception cause = new IllegalArgumentException("mock"); @@ -173,7 +172,7 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { } @Test - public void testPreCommitWithReportedFailure() throws Throwable { + public void testPreCommitWithReportedFailure() throws Exception { canCommitSuccess(); final Exception cause = new IllegalArgumentException("mock"); @@ -210,25 +209,38 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { verify(mockUserCohorts).abort(); } + private static Future abort(final ShardDataTreeCohort cohort) { + final CompletableFuture f = new CompletableFuture<>(); + cohort.abort(new FutureCallback() { + @Override + public void onSuccess(final Void result) { + f.complete(null); + } + + @Override + public void onFailure(final Throwable failure) { + f.completeExceptionally(failure); + } + }); + + return f; + } + @Test public void testAbort() throws Exception { - doNothing().when(mockShardDataTree).startAbort(cohort); - - cohort.abort().get(); + doReturn(Boolean.TRUE).when(mockShardDataTree).startAbort(cohort); + abort(cohort).get(); verify(mockShardDataTree).startAbort(cohort); } @Test public void testAbortWithCohorts() throws Exception { - doNothing().when(mockShardDataTree).startAbort(cohort); - - final Promise> cohortFuture = akka.dispatch.Futures.promise(); - doReturn(Optional.of(cohortFuture.future())).when(mockUserCohorts).abort(); + doReturn(true).when(mockShardDataTree).startAbort(cohort); - final ListenableFuture abortFuture = cohort.abort(); + doReturn(Optional.of(CompletableFuture.completedFuture(null))).when(mockUserCohorts).abort(); - cohortFuture.success(Collections.emptyList()); + final Future abortFuture = abort(cohort); abortFuture.get(); verify(mockShardDataTree).startAbort(cohort);