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=0db1cdf56188b03db9a772df614e23c733d061de;hpb=e970feb618c5e3793454f7f1a3974797a61c7c17;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 0db1cdf561..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,8 +36,11 @@ 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; import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal; import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; @@ -69,6 +73,8 @@ public abstract class AbstractShardTest extends AbstractActorTest{ shardJournalRecoveryLogBatchSize(3).shardSnapshotBatchCount(5000). shardHeartbeatIntervalInMillis(100); + protected final TestActorFactory actorFactory = new TestActorFactory(getSystem()); + @Before public void setUp() { InMemorySnapshotStore.clear(); @@ -79,6 +85,7 @@ public abstract class AbstractShardTest extends AbstractActorTest{ public void tearDown() { InMemorySnapshotStore.clear(); InMemoryJournal.clear(); + actorFactory.close(); } protected DatastoreContext newDatastoreContext() { @@ -241,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();