BUG-2138: DistributedShardListeners support for nested shards
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / SimpleShardDataTreeCohortTest.java
index 1830290d6013a18149ff413344496cfb99e8aaa2..5fef104eaa33d116d2a31bf9fbe0f692504a493c 100644 (file)
@@ -16,11 +16,13 @@ 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;
@@ -142,8 +144,7 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest {
         }).when(mockShardDataTree).startCommit(cohort, candidate);
 
         @SuppressWarnings("unchecked")
-        final
-        FutureCallback<UnsignedLong> mockCommitCallback = mock(FutureCallback.class);
+        final FutureCallback<UnsignedLong> mockCommitCallback = mock(FutureCallback.class);
         cohort.commit(mockCommitCallback);
 
         verify(mockCommitCallback).onSuccess(any(UnsignedLong.class));
@@ -153,7 +154,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 +174,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,23 +211,39 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest {
         verify(mockUserCohorts).abort();
     }
 
+    private static Future<?> abort(final ShardDataTreeCohort cohort) {
+        final CompletableFuture<Void> f = new CompletableFuture<>();
+        cohort.abort(new FutureCallback<Void>() {
+            @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(true).when(mockShardDataTree).startAbort(cohort);
 
+        abort(cohort).get();
         verify(mockShardDataTree).startAbort(cohort);
     }
 
     @Test
     public void testAbortWithCohorts() throws Exception {
-        doNothing().when(mockShardDataTree).startAbort(cohort);
+        doReturn(true).when(mockShardDataTree).startAbort(cohort);
 
         final Promise<Iterable<Object>> cohortFuture = akka.dispatch.Futures.promise();
         doReturn(Optional.of(cohortFuture.future())).when(mockUserCohorts).abort();
 
-        final ListenableFuture<Void> abortFuture = cohort.abort();
+        final Future<?> abortFuture = abort(cohort);
 
         cohortFuture.success(Collections.emptyList());