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%2FShardDataTreeMocking.java;h=7de4835e374691b7131fe75b5d9be13492e06965;hb=9b319f491af1c65705b69e8a182aab5006a2f959;hp=1c71b79625cc012f33a46b26f11dfd2f778bb51d;hpb=5464f50be733df1bbbe31cf05665d542d3b7c5e7;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMocking.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMocking.java index 1c71b79625..7de4835e37 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMocking.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMocking.java @@ -7,7 +7,8 @@ */ package org.opendaylight.controller.cluster.datastore; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.inOrder; @@ -20,6 +21,8 @@ import com.google.common.primitives.UnsignedLong; import com.google.common.util.concurrent.FutureCallback; import org.mockito.InOrder; import org.mockito.invocation.InvocationOnMock; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; +import org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; public final class ShardDataTreeMocking { @@ -43,6 +46,14 @@ public final class ShardDataTreeMocking { return cohort; } + public static FutureCallback coordinatedCanCommit(final ShardDataTreeCohort cohort) { + final FutureCallback 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 callback = mockCallback(); doNothing().when(callback).onSuccess(any(DataTreeCandidate.class)); @@ -53,6 +64,14 @@ public final class ShardDataTreeMocking { return cohort; } + public static FutureCallback coordinatedPreCommit(final ShardDataTreeCohort cohort) { + final FutureCallback 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 callback = mockCallback(); doNothing().when(callback).onSuccess(any(UnsignedLong.class)); @@ -63,46 +82,68 @@ public final class ShardDataTreeMocking { return cohort; } - @SuppressWarnings("unchecked") + public static FutureCallback coordinatedCommit(final ShardDataTreeCohort cohort) { + final FutureCallback callback = mockCallback(); + doNothing().when(callback).onSuccess(any(UnsignedLong.class)); + doNothing().when(callback).onFailure(any(Throwable.class)); + cohort.commit(callback); + return callback; + } + + public static FutureCallback immediate3PhaseCommit(final ShardDataTreeCohort cohort) { + final FutureCallback commitCallback = mockCallback(); + doNothing().when(commitCallback).onSuccess(any(UnsignedLong.class)); + doNothing().when(commitCallback).onFailure(any(Throwable.class)); + + final FutureCallback preCommitCallback = mockCallback(); + doAnswer(invocation -> { + cohort.commit(commitCallback); + return null; + }).when(preCommitCallback).onSuccess(any(DataTreeCandidate.class)); + doNothing().when(preCommitCallback).onFailure(any(Throwable.class)); + + final FutureCallback 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; + } + private static Object invokeSuccess(final InvocationOnMock invocation, final T value) { - invocation.getArgumentAt(0, FutureCallback.class).onSuccess(value); + invocation.>getArgument(0).onSuccess(value); return null; } private static Object invokeFailure(final InvocationOnMock invocation) { - invocation.getArgumentAt(0, FutureCallback.class).onFailure(mock(Exception.class)); + invocation.>getArgument(0).onFailure(mock(Exception.class)); return null; } @SuppressWarnings("unchecked") public static ShardDataTreeCohort failedCanCommit(final ShardDataTreeCohort mock) { - doAnswer(invocation -> { - return invokeFailure(invocation); - }).when(mock).canCommit(any(FutureCallback.class)); + doAnswer(ShardDataTreeMocking::invokeFailure).when(mock).canCommit(any(FutureCallback.class)); return mock; } @SuppressWarnings("unchecked") public static ShardDataTreeCohort failedPreCommit(final ShardDataTreeCohort mock) { - doAnswer(invocation -> { - return invokeFailure(invocation); - }).when(mock).preCommit(any(FutureCallback.class)); + doAnswer(ShardDataTreeMocking::invokeFailure).when(mock).preCommit(any(FutureCallback.class)); return mock; } @SuppressWarnings("unchecked") public static ShardDataTreeCohort failedCommit(final ShardDataTreeCohort mock) { - doAnswer(invocation -> { - return invokeFailure(invocation); - }).when(mock).commit(any(FutureCallback.class)); + doAnswer(ShardDataTreeMocking::invokeFailure).when(mock).commit(any(FutureCallback.class)); return mock; } @SuppressWarnings("unchecked") public static ShardDataTreeCohort successfulCanCommit(final ShardDataTreeCohort mock) { - doAnswer(invocation -> { - return invokeSuccess(invocation, null); - }).when(mock).canCommit(any(FutureCallback.class)); + doAnswer(invocation -> invokeSuccess(invocation, null)).when(mock).canCommit(any(FutureCallback.class)); return mock; } @@ -114,9 +155,7 @@ public final class ShardDataTreeMocking { @SuppressWarnings("unchecked") public static ShardDataTreeCohort successfulPreCommit(final ShardDataTreeCohort mock, final DataTreeCandidate candidate) { - doAnswer(invocation -> { - return invokeSuccess(invocation, candidate); - }).when(mock).preCommit(any(FutureCallback.class)); + doAnswer(invocation -> invokeSuccess(invocation, candidate)).when(mock).preCommit(any(FutureCallback.class)); return mock; } @@ -127,9 +166,7 @@ public final class ShardDataTreeMocking { @SuppressWarnings("unchecked") public static ShardDataTreeCohort successfulCommit(final ShardDataTreeCohort mock, final UnsignedLong index) { - doAnswer(invocation -> { - return invokeSuccess(invocation, index); - }).when(mock).commit(any(FutureCallback.class)); + doAnswer(invocation -> invokeSuccess(invocation, index)).when(mock).commit(any(FutureCallback.class)); return mock; } @@ -141,4 +178,12 @@ public final class ShardDataTreeMocking { inOrder.verify(mock).preCommit(any(FutureCallback.class)); inOrder.verify(mock).commit(any(FutureCallback.class)); } + + public static void immediatePayloadReplication(final ShardDataTree shardDataTree, final Shard mockShard) { + doAnswer(invocation -> { + shardDataTree.applyReplicatedPayload(invocation.getArgument(0), invocation.getArgument(1)); + return null; + }).when(mockShard).persistPayload(any(TransactionIdentifier.class), any(CommitTransactionPayload.class), + anyBoolean()); + } }