Search in sources :

Example 11 with CanCommitTransactionReply

use of org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply 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());
        }
    };
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) FiniteDuration(scala.concurrent.duration.FiniteDuration) CanCommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply) Test(org.junit.Test)

Aggregations

CanCommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply)11 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)10 CanCommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction)10 Test (org.junit.Test)9 FiniteDuration (scala.concurrent.duration.FiniteDuration)9 CommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CommitTransaction)8 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)5 Timeout (akka.util.Timeout)4 ElectionTimeout (org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout)4 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 InOrder (org.mockito.InOrder)3 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)3 OnComplete (akka.dispatch.OnComplete)2 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)2 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)2 DataValidationFailedException (org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException)2 IOException (java.io.IOException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)1