*/
package org.opendaylight.controller.cluster.datastore.compat;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import akka.actor.ActorRef;
+import akka.dispatch.Dispatchers;
+import akka.testkit.TestActorRef;
import org.junit.Test;
import org.opendaylight.controller.cluster.datastore.AbstractShardTest;
import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
+import org.opendaylight.controller.cluster.datastore.Shard;
import org.opendaylight.controller.cluster.datastore.ShardTestKit;
import org.opendaylight.controller.cluster.datastore.TransactionType;
+import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications;
+import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction;
+import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply;
+import org.opendaylight.controller.cluster.datastore.messages.CommitTransaction;
import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply;
+import org.opendaylight.controller.cluster.datastore.messages.ReadyTransactionReply;
import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext;
+import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
+import org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommitCohortMessages;
import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
/**
* Shard unit tests for backwards compatibility with pre-Boron versions.
path.contains("akka://test/user/testCreateTransaction/shard-txn-1"));
}};
}
+
+ @Test
+ public void testBatchedModificationsWithCommitOnReady() throws Throwable {
+ new ShardTestKit(getSystem()) {{
+ final TestActorRef<Shard> shard = actorFactory.createTestActor(
+ newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
+ "testBatchedModificationsWithCommitOnReady");
+
+ waitUntilLeader(shard);
+
+ final String transactionID = "tx";
+
+ BatchedModifications batched = new BatchedModifications(transactionID,
+ DataStoreVersions.LITHIUM_VERSION, "");
+ batched.addModification(new WriteModification(TestModel.TEST_PATH,
+ ImmutableNodes.containerNode(TestModel.TEST_QNAME)));
+ batched.setReady(true);
+ batched.setDoCommitOnReady(true);
+ batched.setTotalMessagesSent(1);
+
+ shard.tell(batched, getRef());
+ expectMsgClass(ThreePhaseCommitCohortMessages.CommitTransactionReply.class);
+ }};
+ }
+
+ @Test
+ public void testImmediateCommitWithForwardedReadyTransaction() throws Throwable {
+ new ShardTestKit(getSystem()) {{
+ final TestActorRef<Shard> shard = actorFactory.createTestActor(
+ newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
+ "testImmediateCommitWithForwardedReadyTransaction");
+
+ waitUntilLeader(shard);
+
+ final String transactionID = "tx";
+
+ shard.tell(prepareForwardedReadyTransaction(mockShardDataTreeCohort(), transactionID,
+ DataStoreVersions.LITHIUM_VERSION, true), getRef());
+
+ expectMsgClass(ThreePhaseCommitCohortMessages.CommitTransactionReply.class);
+ }};
+ }
+
+ @Test
+ public void testThreePhaseCommitOnForwardedReadyTransaction() throws Throwable {
+ new ShardTestKit(getSystem()) {{
+ final TestActorRef<Shard> shard = actorFactory.createTestActor(
+ newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
+ "testThreePhaseCommitOnForwardedReadyTransaction");
+
+ waitUntilLeader(shard);
+
+ final String transactionID = "tx";
+
+ shard.tell(prepareForwardedReadyTransaction(mockShardDataTreeCohort(), transactionID,
+ DataStoreVersions.LITHIUM_VERSION, false), getRef());
+ expectMsgClass(ReadyTransactionReply.class);
+
+ shard.tell(new CanCommitTransaction(transactionID, DataStoreVersions.LITHIUM_VERSION).toSerializable(), getRef());
+ CanCommitTransactionReply canCommitReply = CanCommitTransactionReply.fromSerializable(
+ expectMsgClass(ThreePhaseCommitCohortMessages.CanCommitTransactionReply.class));
+ assertEquals("Can commit", true, canCommitReply.getCanCommit());
+
+ shard.tell(new CommitTransaction(transactionID, DataStoreVersions.LITHIUM_VERSION).toSerializable(), getRef());
+ expectMsgClass(ThreePhaseCommitCohortMessages.CommitTransactionReply.class);
+ }};
+ }
}