BUG-7033: Implement batchHint in ShardDataTree
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / ShardDataTreeMocking.java
index 1c71b79625cc012f33a46b26f11dfd2f778bb51d..6696df0781a5fcdd3dd42acb7a38722117b8261f 100644 (file)
@@ -43,6 +43,14 @@ public final class ShardDataTreeMocking {
         return cohort;
     }
 
+    public static FutureCallback<Void> coordinatedCanCommit(final ShardDataTreeCohort cohort) {
+        final FutureCallback<Void> callback = mockCallback();
+        doNothing().when(callback).onSuccess(null);
+        doNothing().when(callback).onFailure(any(Throwable.class));
+        cohort.canCommit(callback);
+        return callback;
+    }
+
     public static ShardDataTreeCohort immediatePreCommit(final ShardDataTreeCohort cohort) {
         final FutureCallback<DataTreeCandidate> callback = mockCallback();
         doNothing().when(callback).onSuccess(any(DataTreeCandidate.class));
@@ -53,6 +61,14 @@ public final class ShardDataTreeMocking {
         return cohort;
     }
 
+    public static FutureCallback<DataTreeCandidate> coordinatedPreCommit(final ShardDataTreeCohort cohort) {
+        final FutureCallback<DataTreeCandidate> callback = mockCallback();
+        doNothing().when(callback).onSuccess(any(DataTreeCandidate.class));
+        doNothing().when(callback).onFailure(any(Throwable.class));
+        cohort.preCommit(callback);
+        return callback;
+    }
+
     public static ShardDataTreeCohort immediateCommit(final ShardDataTreeCohort cohort) {
         final FutureCallback<UnsignedLong> callback = mockCallback();
         doNothing().when(callback).onSuccess(any(UnsignedLong.class));
@@ -63,6 +79,37 @@ public final class ShardDataTreeMocking {
         return cohort;
     }
 
+    public static FutureCallback<UnsignedLong> coordinatedCommit(final ShardDataTreeCohort cohort) {
+        final FutureCallback<UnsignedLong> callback = mockCallback();
+        doNothing().when(callback).onSuccess(any(UnsignedLong.class));
+        doNothing().when(callback).onFailure(any(Throwable.class));
+        cohort.commit(callback);
+        return callback;
+    }
+
+    public static FutureCallback<UnsignedLong> immediate3PhaseCommit(final ShardDataTreeCohort cohort) {
+        final FutureCallback<UnsignedLong> commitCallback = mockCallback();
+        doNothing().when(commitCallback).onSuccess(any(UnsignedLong.class));
+        doNothing().when(commitCallback).onFailure(any(Throwable.class));
+
+        final FutureCallback<DataTreeCandidate> preCommitCallback = mockCallback();
+        doAnswer(invocation -> {
+            cohort.commit(commitCallback);
+            return null;
+        }).when(preCommitCallback).onSuccess(any(DataTreeCandidate.class));
+        doNothing().when(preCommitCallback).onFailure(any(Throwable.class));
+
+        final FutureCallback<Void> canCommit = mockCallback();
+        doAnswer(invocation -> {
+            cohort.preCommit(preCommitCallback);
+            return null;
+        }).when(canCommit).onSuccess(null);
+        doNothing().when(canCommit).onFailure(any(Throwable.class));
+
+        cohort.canCommit(canCommit);
+        return commitCallback;
+    }
+
     @SuppressWarnings("unchecked")
     private static <T> Object invokeSuccess(final InvocationOnMock invocation, final T value) {
         invocation.getArgumentAt(0, FutureCallback.class).onSuccess(value);