use of org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction in project controller by opendaylight.
the class ThreePhaseCommitCohortProxy method sendCanCommitTransaction.
private void sendCanCommitTransaction(final CohortInfo toCohortInfo, final OnComplete<Object> onComplete) {
CanCommitTransaction message = new CanCommitTransaction(transactionId, toCohortInfo.getActorVersion());
LOG.debug("Tx {}: sending {} to {}", transactionId, message, toCohortInfo.getResolvedActor());
Future<Object> future = actorContext.executeOperationAsync(toCohortInfo.getResolvedActor(), message.toSerializable(), actorContext.getTransactionCommitOperationTimeout());
future.onComplete(onComplete, actorContext.getClientDispatcher());
}
use of org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction in project controller by opendaylight.
the class ShardTest method testTransactionCommitWithSubsequentExpiredCohortEntry.
@Test
public void testTransactionCommitWithSubsequentExpiredCohortEntry() throws Exception {
dataStoreContextBuilder.shardTransactionCommitTimeoutInSeconds(1);
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testTransactionCommitWithSubsequentExpiredCohortEntry");
waitUntilLeader(shard);
final FiniteDuration duration = duration("5 seconds");
final ShardDataTree dataStore = shard.underlyingActor().getDataStore();
final TransactionIdentifier transactionID1 = nextTransactionId();
shard.tell(prepareBatchedModifications(transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), false), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
// CanCommit the first Tx so it's the current in-progress Tx.
shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, CanCommitTransactionReply.class);
// Ready the second Tx.
final TransactionIdentifier transactionID2 = nextTransactionId();
shard.tell(prepareBatchedModifications(transactionID2, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), false), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
// Ready the third Tx.
final TransactionIdentifier transactionID3 = nextTransactionId();
final DataTreeModification modification3 = dataStore.newModification();
new WriteModification(TestModel.TEST2_PATH, ImmutableNodes.containerNode(TestModel.TEST2_QNAME)).apply(modification3);
modification3.ready();
final ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(transactionID3, modification3, true);
shard.tell(readyMessage, getRef());
// Commit the first Tx. After completing, the second should
// expire from the queue and the third
// Tx committed.
shard.tell(new CommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, CommitTransactionReply.class);
// Expect commit reply from the third Tx.
expectMsgClass(duration, CommitTransactionReply.class);
final NormalizedNode<?, ?> node = readStore(shard, TestModel.TEST2_PATH);
assertNotNull(TestModel.TEST2_PATH + " not found", node);
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction in project controller by opendaylight.
the class ShardTest method testAbortQueuedTransaction.
@Test
public void testAbortQueuedTransaction() throws Exception {
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testAbortAfterReady");
waitUntilLeader(shard);
final FiniteDuration duration = duration("5 seconds");
// Ready 3 tx's.
final TransactionIdentifier transactionID1 = nextTransactionId();
shard.tell(newBatchedModifications(transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true, false, 1), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
final TransactionIdentifier transactionID2 = nextTransactionId();
shard.tell(newBatchedModifications(transactionID2, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true, false, 1), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
final TransactionIdentifier transactionID3 = nextTransactionId();
shard.tell(newBatchedModifications(transactionID3, TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build(), true, false, 1), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
// Abort the second tx while it's queued.
shard.tell(new AbortTransaction(transactionID2, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, AbortTransactionReply.class);
// Commit the other 2.
shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, CanCommitTransactionReply.class);
shard.tell(new CommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, CommitTransactionReply.class);
shard.tell(new CanCommitTransaction(transactionID3, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, CanCommitTransactionReply.class);
shard.tell(new CommitTransaction(transactionID3, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, CommitTransactionReply.class);
assertEquals("getPendingTxCommitQueueSize", 0, shard.underlyingActor().getPendingTxCommitQueueSize());
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction in project controller by opendaylight.
the class ShardTest method testTransactionCommitWithPriorExpiredCohortEntries.
// @Test
// @Ignore
// public void testTransactionCommitQueueCapacityExceeded() throws Throwable {
// dataStoreContextBuilder.shardTransactionCommitQueueCapacity(2);
//
// new ShardTestKit(getSystem()) {{
// final TestActorRef<Shard> shard = actorFactory.createTestActor(
// newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
// "testTransactionCommitQueueCapacityExceeded");
//
// waitUntilLeader(shard);
//
// final FiniteDuration duration = duration("5 seconds");
//
// final ShardDataTree dataStore = shard.underlyingActor().getDataStore();
//
// final TransactionIdentifier transactionID1 = nextTransactionId();
// final MutableCompositeModification modification1 = new MutableCompositeModification();
// final ShardDataTreeCohort cohort1 = setupMockWriteTransaction("cohort1", dataStore,
// TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), transactionID1,
// modification1);
//
// final TransactionIdentifier transactionID2 = nextTransactionId();
// final MutableCompositeModification modification2 = new MutableCompositeModification();
// final ShardDataTreeCohort cohort2 = setupMockWriteTransaction("cohort2", dataStore,
// TestModel.OUTER_LIST_PATH,
// ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build(), transactionID2,
// modification2);
//
// final TransactionIdentifier transactionID3 = nextTransactionId();
// final MutableCompositeModification modification3 = new MutableCompositeModification();
// final ShardDataTreeCohort cohort3 = setupMockWriteTransaction("cohort3", dataStore,
// TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), transactionID3,
// modification3);
//
// // Ready the Tx's
//
// shard.tell(prepareReadyTransactionMessage(false, shard.underlyingActor(), cohort1, transactionID1,
// modification1), getRef());
// expectMsgClass(duration, ReadyTransactionReply.class);
//
// shard.tell(prepareReadyTransactionMessage(false, shard.underlyingActor(), cohort2, transactionID2,
// modification2), getRef());
// expectMsgClass(duration, ReadyTransactionReply.class);
//
// // The 3rd Tx should exceed queue capacity and fail.
//
// shard.tell(prepareReadyTransactionMessage(false, shard.underlyingActor(), cohort3, transactionID3,
// modification3), getRef());
// expectMsgClass(duration, akka.actor.Status.Failure.class);
//
// // canCommit 1st Tx.
//
// shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
// expectMsgClass(duration, CanCommitTransactionReply.class);
//
// // canCommit the 2nd Tx - it should get queued.
//
// shard.tell(new CanCommitTransaction(transactionID2, CURRENT_VERSION).toSerializable(), getRef());
//
// // canCommit the 3rd Tx - should exceed queue capacity and fail.
//
// shard.tell(new CanCommitTransaction(transactionID3, CURRENT_VERSION).toSerializable(), getRef());
// expectMsgClass(duration, akka.actor.Status.Failure.class);
// }};
// }
@Test
public void testTransactionCommitWithPriorExpiredCohortEntries() throws Exception {
dataStoreContextBuilder.shardTransactionCommitTimeoutInSeconds(1);
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testTransactionCommitWithPriorExpiredCohortEntries");
waitUntilLeader(shard);
final FiniteDuration duration = duration("5 seconds");
final TransactionIdentifier transactionID1 = nextTransactionId();
shard.tell(newBatchedModifications(transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true, false, 1), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
final TransactionIdentifier transactionID2 = nextTransactionId();
shard.tell(newBatchedModifications(transactionID2, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true, false, 1), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
final TransactionIdentifier transactionID3 = nextTransactionId();
shard.tell(newBatchedModifications(transactionID3, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true, false, 1), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
// All Tx's are readied. We'll send canCommit for the last one
// but not the others. The others
// should expire from the queue and the last one should be
// processed.
shard.tell(new CanCommitTransaction(transactionID3, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, CanCommitTransactionReply.class);
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction in project controller by opendaylight.
the class ShardTest method testReadWriteCommitWithPersistenceDisabled.
@Test
public void testReadWriteCommitWithPersistenceDisabled() throws Exception {
dataStoreContextBuilder.persistent(false);
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testCommitWithPersistenceDisabled");
waitUntilLeader(shard);
// Setup a simulated transactions with a mock cohort.
final FiniteDuration duration = duration("5 seconds");
final TransactionIdentifier transactionID = nextTransactionId();
final NormalizedNode<?, ?> containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
shard.tell(prepareBatchedModifications(transactionID, TestModel.TEST_PATH, containerNode, false), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
// Send the CanCommitTransaction message.
shard.tell(new CanCommitTransaction(transactionID, CURRENT_VERSION).toSerializable(), getRef());
final CanCommitTransactionReply canCommitReply = CanCommitTransactionReply.fromSerializable(expectMsgClass(duration, CanCommitTransactionReply.class));
assertEquals("Can commit", true, canCommitReply.getCanCommit());
// Send the CanCommitTransaction message.
shard.tell(new CommitTransaction(transactionID, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, CommitTransactionReply.class);
final NormalizedNode<?, ?> actualNode = readStore(shard, TestModel.TEST_PATH);
assertEquals(TestModel.TEST_QNAME.getLocalName(), containerNode, actualNode);
}
};
}
Aggregations