use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.
the class ShardWriteTransaction method readyTransaction.
private void readyTransaction(boolean returnSerialized, boolean doImmediateCommit, short clientTxVersion) {
TransactionIdentifier transactionID = getTransactionId();
LOG.debug("readyTransaction : {}", transactionID);
getShardActor().forward(new ForwardedReadyTransaction(transactionID, clientTxVersion, transaction, doImmediateCommit), getContext());
// The shard will handle the commit from here so we're no longer needed - self-destruct.
getSelf().tell(PoisonPill.getInstance(), getSelf());
}
use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier 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.access.concepts.TransactionIdentifier 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.access.concepts.TransactionIdentifier 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.access.concepts.TransactionIdentifier in project controller by opendaylight.
the class ShardTest method testBatchedModificationsWithOperationFailure.
@Test
public void testBatchedModificationsWithOperationFailure() throws Exception {
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testBatchedModificationsWithOperationFailure");
waitUntilLeader(shard);
// Test merge with invalid data. An exception should occur when
// the merge is applied. Note that
// write will not validate the children for performance reasons.
final TransactionIdentifier transactionID = nextTransactionId();
final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
BatchedModifications batched = new BatchedModifications(transactionID, CURRENT_VERSION);
batched.addModification(new MergeModification(TestModel.TEST_PATH, invalidData));
shard.tell(batched, getRef());
Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
final Throwable cause = failure.cause();
batched = new BatchedModifications(transactionID, DataStoreVersions.CURRENT_VERSION);
batched.setReady(true);
batched.setTotalMessagesSent(2);
shard.tell(batched, getRef());
failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
assertEquals("Failure cause", cause, failure.cause());
}
};
}
Aggregations