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%2FAbstractShardTest.java;h=a196eda597110baac1dfb5645a6599ec6d7f7e54;hb=4c1877fd363bf0663c91b85b2bf5be64d22e56aa;hp=36aa9a27213edad6f79c62d63abd36917a7c32fe;hpb=6050fd28f2def659abb5bc9d7127eb748b5fb32a;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java index 36aa9a2721..a196eda597 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.opendaylight.controller.cluster.datastore.DataStoreVersions.CURRENT_VERSION; import akka.actor.ActorRef; import akka.actor.PoisonPill; import akka.actor.Props; @@ -35,6 +36,8 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder; import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier; +import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications; +import org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction; import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification; import org.opendaylight.controller.cluster.datastore.modification.WriteModification; import org.opendaylight.controller.cluster.raft.TestActorFactory; @@ -245,6 +248,50 @@ public abstract class AbstractShardTest extends AbstractActorTest{ return cohort; } + protected Object prepareReadyTransactionMessage(boolean remoteReadWriteTransaction, Shard shard, ShardDataTreeCohort cohort, + String transactionID, + MutableCompositeModification modification, + boolean doCommitOnReady) { + if(remoteReadWriteTransaction){ + return new ForwardedReadyTransaction(transactionID, CURRENT_VERSION, cohort, true, doCommitOnReady); + } else { + setupCohortDecorator(shard, cohort); + return prepareBatchedModifications(transactionID, modification, doCommitOnReady); + } + } + + protected Object prepareReadyTransactionMessage(boolean remoteReadWriteTransaction, Shard shard, ShardDataTreeCohort cohort, + String transactionID, + MutableCompositeModification modification) { + return prepareReadyTransactionMessage(remoteReadWriteTransaction, shard, cohort, transactionID, modification, false); + } + + protected void setupCohortDecorator(Shard shard, final ShardDataTreeCohort cohort) { + shard.getCommitCoordinator().setCohortDecorator(new ShardCommitCoordinator.CohortDecorator() { + @Override + public ShardDataTreeCohort decorate(String transactionID, ShardDataTreeCohort actual) { + return cohort; + } + }); + } + + protected BatchedModifications prepareBatchedModifications(String transactionID, + MutableCompositeModification modification) { + return prepareBatchedModifications(transactionID, modification, false); + } + + private BatchedModifications prepareBatchedModifications(String transactionID, + MutableCompositeModification modification, + boolean doCommitOnReady) { + final BatchedModifications batchedModifications = new BatchedModifications(transactionID, CURRENT_VERSION, null); + batchedModifications.addModification(modification); + batchedModifications.setReady(true); + batchedModifications.setDoCommitOnReady(doCommitOnReady); + batchedModifications.setTotalMessagesSent(1); + return batchedModifications; + } + + public static NormalizedNode readStore(final TestActorRef shard, final YangInstanceIdentifier id) throws ExecutionException, InterruptedException { return shard.underlyingActor().getDataStore().readNode(id).orNull();