use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.
the class ShardTest method testCanCommitPhaseFailure.
@Test
public void testCanCommitPhaseFailure() throws Exception {
new ShardTestKit(getSystem()) {
{
final DataTree dataTree = createDelegatingMockDataTree();
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardBuilder().dataTree(dataTree).props().withDispatcher(Dispatchers.DefaultDispatcherId()), "testCanCommitPhaseFailure");
waitUntilLeader(shard);
final FiniteDuration duration = duration("5 seconds");
final TransactionIdentifier transactionID1 = nextTransactionId();
doThrow(new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock canCommit failure")).doNothing().when(dataTree).validate(any(DataTreeModification.class));
shard.tell(newBatchedModifications(transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true, false, 1), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
// Send the CanCommitTransaction message.
shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, akka.actor.Status.Failure.class);
// Send another can commit to ensure the failed one got cleaned
// up.
final TransactionIdentifier transactionID2 = nextTransactionId();
shard.tell(newBatchedModifications(transactionID2, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true, false, 1), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
shard.tell(new CanCommitTransaction(transactionID2, CURRENT_VERSION).toSerializable(), getRef());
final CanCommitTransactionReply reply = CanCommitTransactionReply.fromSerializable(expectMsgClass(CanCommitTransactionReply.class));
assertEquals("getCanCommit", true, reply.getCanCommit());
}
};
}
use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.
the class ShardTransactionTest method testOnReceiveBatchedModificationsFailure.
@Test(expected = TestException.class)
public void testOnReceiveBatchedModificationsFailure() throws Exception {
new TestKit(getSystem()) {
{
ShardDataTreeTransactionParent parent = Mockito.mock(ShardDataTreeTransactionParent.class);
DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
ReadWriteShardDataTreeTransaction mockWriteTx = new ReadWriteShardDataTreeTransaction(parent, nextTransactionId(), mockModification);
final ActorRef transaction = newTransactionActor(RW, mockWriteTx, "testOnReceiveBatchedModificationsFailure");
TestKit watcher = new TestKit(getSystem());
watcher.watch(transaction);
YangInstanceIdentifier path = TestModel.TEST_PATH;
ContainerNode node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
doThrow(new TestException()).when(mockModification).write(path, node);
final TransactionIdentifier tx1 = nextTransactionId();
BatchedModifications batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
batched.addModification(new WriteModification(path, node));
transaction.tell(batched, getRef());
expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
batched.setReady(true);
batched.setTotalMessagesSent(2);
transaction.tell(batched, getRef());
Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
if (failure != null) {
Throwables.propagateIfPossible(failure.cause(), Exception.class);
throw new RuntimeException(failure.cause());
}
}
};
}
use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.
the class ShardTransactionTest method testOnReceiveBatchedModificationsReadyWithoutImmediateCommit.
@Test
public void testOnReceiveBatchedModificationsReadyWithoutImmediateCommit() throws Exception {
new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testOnReceiveBatchedModificationsReadyWithoutImmediateCommit");
TestKit watcher = new TestKit(getSystem());
watcher.watch(transaction);
YangInstanceIdentifier writePath = TestModel.TEST_PATH;
NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
final TransactionIdentifier tx1 = nextTransactionId();
BatchedModifications batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
batched.addModification(new WriteModification(writePath, writeData));
transaction.tell(batched, getRef());
BatchedModificationsReply reply = expectMsgClass(duration("5 seconds"), BatchedModificationsReply.class);
assertEquals("getNumBatched", 1, reply.getNumBatched());
batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
batched.setReady(true);
batched.setTotalMessagesSent(2);
transaction.tell(batched, getRef());
expectMsgClass(duration("5 seconds"), ReadyTransactionReply.class);
watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
}
};
}
use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.
the class DataTreeCohortActorTest method testMultipleThreePhaseCommits.
@Test
public void testMultipleThreePhaseCommits() throws Exception {
ActorRef cohortActor = newCohortActor("testMultipleThreePhaseCommits");
TransactionIdentifier txId1 = nextTransactionId();
TransactionIdentifier txId2 = nextTransactionId();
askAndAwait(cohortActor, new CanCommit(txId1, CANDIDATES, MOCK_SCHEMA, cohortActor));
askAndAwait(cohortActor, new CanCommit(txId2, CANDIDATES, MOCK_SCHEMA, cohortActor));
askAndAwait(cohortActor, new PreCommit(txId1));
askAndAwait(cohortActor, new PreCommit(txId2));
askAndAwait(cohortActor, new Commit(txId1));
askAndAwait(cohortActor, new Commit(txId2));
}
use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.
the class DataTreeCohortActorTest method testAbortAfterCanCommit.
@Test
public void testAbortAfterCanCommit() throws Exception {
ActorRef cohortActor = newCohortActor("testAbortAfterCanCommit");
TransactionIdentifier txId = nextTransactionId();
askAndAwait(cohortActor, new CanCommit(txId, CANDIDATES, MOCK_SCHEMA, cohortActor));
verify(mockCohort).canCommit(txId, CANDIDATES, MOCK_SCHEMA);
askAndAwait(cohortActor, new Abort(txId));
verify(mockPostCanCommit).abort();
resetMockCohort();
askAndAwait(cohortActor, new CanCommit(txId, CANDIDATES, MOCK_SCHEMA, cohortActor));
verify(mockCohort).canCommit(txId, CANDIDATES, MOCK_SCHEMA);
}
Aggregations