Search in sources :

Example 11 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class ShardTest method testCommitPhaseFailure.

@Test
public void testCommitPhaseFailure() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final DataTree dataTree = createDelegatingMockDataTree();
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardBuilder().dataTree(dataTree).props().withDispatcher(Dispatchers.DefaultDispatcherId()), "testCommitPhaseFailure");
            waitUntilLeader(shard);
            final FiniteDuration duration = duration("5 seconds");
            final Timeout timeout = new Timeout(duration);
            // Setup 2 simulated transactions with mock cohorts. The first
            // one fails in the
            // commit phase.
            doThrow(new RuntimeException("mock commit failure")).when(dataTree).commit(any(DataTreeCandidate.class));
            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);
            // Send the CanCommitTransaction message for the first Tx.
            shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            final CanCommitTransactionReply canCommitReply = CanCommitTransactionReply.fromSerializable(expectMsgClass(duration, CanCommitTransactionReply.class));
            assertEquals("Can commit", true, canCommitReply.getCanCommit());
            // Send the CanCommitTransaction message for the 2nd Tx. This
            // should get queued and
            // processed after the first Tx completes.
            final Future<Object> canCommitFuture = Patterns.ask(shard, new CanCommitTransaction(transactionID2, CURRENT_VERSION).toSerializable(), timeout);
            // Send the CommitTransaction message for the first Tx. This
            // should send back an error
            // and trigger the 2nd Tx to proceed.
            shard.tell(new CommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, akka.actor.Status.Failure.class);
            // Wait for the 2nd Tx to complete the canCommit phase.
            final CountDownLatch latch = new CountDownLatch(1);
            canCommitFuture.onComplete(new OnComplete<Object>() {

                @Override
                public void onComplete(final Throwable failure, final Object resp) {
                    latch.countDown();
                }
            }, getSystem().dispatcher());
            assertEquals("2nd CanCommit complete", true, latch.await(5, TimeUnit.SECONDS));
            final InOrder inOrder = inOrder(dataTree);
            inOrder.verify(dataTree).validate(any(DataTreeModification.class));
            inOrder.verify(dataTree).prepare(any(DataTreeModification.class));
            // FIXME: this invocation is done on the result of validate(). To test it, we need to make sure mock
            // validate performs wrapping and we capture that mock
            // inOrder.verify(dataTree).validate(any(DataTreeModification.class));
            inOrder.verify(dataTree).commit(any(DataTreeCandidate.class));
        }
    };
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) InOrder(org.mockito.InOrder) Timeout(akka.util.Timeout) ElectionTimeout(org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout) FiniteDuration(scala.concurrent.duration.FiniteDuration) CountDownLatch(java.util.concurrent.CountDownLatch) CanCommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) CommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CommitTransaction) 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) Test(org.junit.Test)

Example 12 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class ShardTest method testImmediateCommitWithCanCommitPhaseFailure.

private void testImmediateCommitWithCanCommitPhaseFailure(final boolean readWrite) throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final DataTree dataTree = createDelegatingMockDataTree();
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardBuilder().dataTree(dataTree).props().withDispatcher(Dispatchers.DefaultDispatcherId()), "testImmediateCommitWithCanCommitPhaseFailure-" + readWrite);
            waitUntilLeader(shard);
            doThrow(new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock canCommit failure")).doNothing().when(dataTree).validate(any(DataTreeModification.class));
            final FiniteDuration duration = duration("5 seconds");
            final TransactionIdentifier transactionID1 = nextTransactionId();
            if (readWrite) {
                shard.tell(prepareForwardedReadyTransaction(shard, transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true), getRef());
            } else {
                shard.tell(prepareBatchedModifications(transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true), getRef());
            }
            expectMsgClass(duration, akka.actor.Status.Failure.class);
            // Send another can commit to ensure the failed one got cleaned
            // up.
            final TransactionIdentifier transactionID2 = nextTransactionId();
            if (readWrite) {
                shard.tell(prepareForwardedReadyTransaction(shard, transactionID2, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true), getRef());
            } else {
                shard.tell(prepareBatchedModifications(transactionID2, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true), getRef());
            }
            expectMsgClass(duration, CommitTransactionReply.class);
        }
    };
}
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) FiniteDuration(scala.concurrent.duration.FiniteDuration)

Example 13 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class ShardTest method testPreCommitPhaseFailure.

@Test
public void testPreCommitPhaseFailure() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final DataTree dataTree = createDelegatingMockDataTree();
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardBuilder().dataTree(dataTree).props().withDispatcher(Dispatchers.DefaultDispatcherId()), "testPreCommitPhaseFailure");
            waitUntilLeader(shard);
            final FiniteDuration duration = duration("5 seconds");
            final Timeout timeout = new Timeout(duration);
            doThrow(new RuntimeException("mock preCommit failure")).when(dataTree).prepare(any(DataTreeModification.class));
            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);
            // Send the CanCommitTransaction message for the first Tx.
            shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            final CanCommitTransactionReply canCommitReply = CanCommitTransactionReply.fromSerializable(expectMsgClass(duration, CanCommitTransactionReply.class));
            assertEquals("Can commit", true, canCommitReply.getCanCommit());
            // Send the CanCommitTransaction message for the 2nd Tx. This
            // should get queued and
            // processed after the first Tx completes.
            final Future<Object> canCommitFuture = Patterns.ask(shard, new CanCommitTransaction(transactionID2, CURRENT_VERSION).toSerializable(), timeout);
            // Send the CommitTransaction message for the first Tx. This
            // should send back an error
            // and trigger the 2nd Tx to proceed.
            shard.tell(new CommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, akka.actor.Status.Failure.class);
            // Wait for the 2nd Tx to complete the canCommit phase.
            final CountDownLatch latch = new CountDownLatch(1);
            canCommitFuture.onComplete(new OnComplete<Object>() {

                @Override
                public void onComplete(final Throwable failure, final Object resp) {
                    latch.countDown();
                }
            }, getSystem().dispatcher());
            assertEquals("2nd CanCommit complete", true, latch.await(5, TimeUnit.SECONDS));
            final InOrder inOrder = inOrder(dataTree);
            inOrder.verify(dataTree).validate(any(DataTreeModification.class));
            inOrder.verify(dataTree).prepare(any(DataTreeModification.class));
            inOrder.verify(dataTree).validate(any(DataTreeModification.class));
        }
    };
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) InOrder(org.mockito.InOrder) Timeout(akka.util.Timeout) ElectionTimeout(org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout) FiniteDuration(scala.concurrent.duration.FiniteDuration) CountDownLatch(java.util.concurrent.CountDownLatch) CanCommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) CommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CommitTransaction) 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) Test(org.junit.Test)

Example 14 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class ShardTest method testAbortAfterReady.

@Test
public void testAbortAfterReady() throws Exception {
    dataStoreContextBuilder.shardTransactionCommitTimeoutInSeconds(1);
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testAbortAfterReady");
            waitUntilLeader(shard);
            final FiniteDuration duration = duration("5 seconds");
            // Ready a tx.
            final TransactionIdentifier transactionID1 = nextTransactionId();
            shard.tell(newBatchedModifications(transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true, false, 1), getRef());
            expectMsgClass(duration, ReadyTransactionReply.class);
            // Send the AbortTransaction message.
            shard.tell(new AbortTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, AbortTransactionReply.class);
            assertEquals("getPendingTxCommitQueueSize", 0, shard.underlyingActor().getPendingTxCommitQueueSize());
            // Now send CanCommitTransaction - should fail.
            shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            final Throwable failure = expectMsgClass(duration, akka.actor.Status.Failure.class).cause();
            assertTrue("Failure type", failure instanceof IllegalStateException);
            // Ready and CanCommit another and verify success.
            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());
            expectMsgClass(duration, CanCommitTransactionReply.class);
        }
    };
}
Also used : TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) FiniteDuration(scala.concurrent.duration.FiniteDuration) AbortTransaction(org.opendaylight.controller.cluster.datastore.messages.AbortTransaction) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Example 15 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class ShardTest method testBatchedModificationsWithCommitOnReady.

@Test
public void testBatchedModificationsWithCommitOnReady() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testBatchedModificationsWithCommitOnReady");
            waitUntilLeader(shard);
            final TransactionIdentifier transactionID = nextTransactionId();
            final FiniteDuration duration = duration("5 seconds");
            // Send a BatchedModifications to start a transaction.
            shard.tell(newBatchedModifications(transactionID, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), false, false, 1), getRef());
            expectMsgClass(duration, BatchedModificationsReply.class);
            // Send a couple more BatchedModifications.
            shard.tell(newBatchedModifications(transactionID, TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build(), false, false, 2), getRef());
            expectMsgClass(duration, BatchedModificationsReply.class);
            shard.tell(newBatchedModifications(transactionID, YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).build(), ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1), true, true, 3), getRef());
            expectMsgClass(duration, CommitTransactionReply.class);
            // Verify data in the data store.
            verifyOuterListEntry(shard, 1);
        }
    };
}
Also used : TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) FiniteDuration(scala.concurrent.duration.FiniteDuration) Test(org.junit.Test)

Aggregations

TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)57 Test (org.junit.Test)37 FiniteDuration (scala.concurrent.duration.FiniteDuration)17 CanCommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction)16 CommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CommitTransaction)12 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)11 CanCommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply)10 ActorRef (akka.actor.ActorRef)8 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)7 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)7 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)7 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)7 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)6 CanCommit (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit)6 Failure (akka.actor.Status.Failure)5 Timeout (akka.util.Timeout)5 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)5