Search in sources :

Example 21 with BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.

the class ShardTest method testTransactionMessagesWithNoLeader.

@Test
public void testTransactionMessagesWithNoLeader() {
    new ShardTestKit(getSystem()) {

        {
            dataStoreContextBuilder.customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName()).shardHeartbeatIntervalInMillis(50).shardElectionTimeoutFactor(1);
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testTransactionMessagesWithNoLeader");
            waitUntilNoLeader(shard);
            final TransactionIdentifier txId = nextTransactionId();
            shard.tell(new BatchedModifications(txId, DataStoreVersions.CURRENT_VERSION), getRef());
            Failure failure = expectMsgClass(Failure.class);
            assertEquals("Failure cause type", NoShardLeaderException.class, failure.cause().getClass());
            shard.tell(prepareForwardedReadyTransaction(shard, txId, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true), getRef());
            failure = expectMsgClass(Failure.class);
            assertEquals("Failure cause type", NoShardLeaderException.class, failure.cause().getClass());
            shard.tell(new ReadyLocalTransaction(txId, mock(DataTreeModification.class), true), getRef());
            failure = expectMsgClass(Failure.class);
            assertEquals("Failure cause type", NoShardLeaderException.class, failure.cause().getClass());
        }
    };
}
Also used : ReadyLocalTransaction(org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) Failure(akka.actor.Status.Failure) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Test(org.junit.Test)

Example 22 with BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.

the class ShardTransactionTest method testOnReceiveBatchedModifications.

@Test
public void testOnReceiveBatchedModifications() 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, "testOnReceiveBatchedModifications");
            YangInstanceIdentifier writePath = TestModel.TEST_PATH;
            NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
            YangInstanceIdentifier mergePath = TestModel.OUTER_LIST_PATH;
            NormalizedNode<?, ?> mergeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
            YangInstanceIdentifier deletePath = TestModel.TEST_PATH;
            BatchedModifications batched = new BatchedModifications(nextTransactionId(), DataStoreVersions.CURRENT_VERSION);
            batched.addModification(new WriteModification(writePath, writeData));
            batched.addModification(new MergeModification(mergePath, mergeData));
            batched.addModification(new DeleteModification(deletePath));
            transaction.tell(batched, getRef());
            BatchedModificationsReply reply = expectMsgClass(duration("5 seconds"), BatchedModificationsReply.class);
            assertEquals("getNumBatched", 3, reply.getNumBatched());
            InOrder inOrder = Mockito.inOrder(mockModification);
            inOrder.verify(mockModification).write(writePath, writeData);
            inOrder.verify(mockModification).merge(mergePath, mergeData);
            inOrder.verify(mockModification).delete(deletePath);
        }
    };
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) InOrder(org.mockito.InOrder) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) TestKit(akka.testkit.javadsl.TestKit) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) BatchedModificationsReply(org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply) Test(org.junit.Test)

Example 23 with BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications 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());
            }
        }
    };
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) TestKit(akka.testkit.javadsl.TestKit) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Example 24 with BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications 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);
        }
    };
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) BatchedModificationsReply(org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) TestKit(akka.testkit.javadsl.TestKit) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Test(org.junit.Test)

Example 25 with BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.

the class TransactionProxyTest method testModificationOperationBatching.

private void testModificationOperationBatching(final TransactionType type) throws Exception {
    int shardBatchedModificationCount = 3;
    dataStoreContextBuilder.shardBatchedModificationCount(shardBatchedModificationCount);
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), type);
    expectBatchedModifications(actorRef, shardBatchedModificationCount);
    YangInstanceIdentifier writePath1 = TestModel.TEST_PATH;
    NormalizedNode<?, ?> writeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    YangInstanceIdentifier writePath2 = TestModel.OUTER_LIST_PATH;
    NormalizedNode<?, ?> writeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME);
    YangInstanceIdentifier writePath3 = TestModel.INNER_LIST_PATH;
    NormalizedNode<?, ?> writeNode3 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME);
    YangInstanceIdentifier mergePath1 = TestModel.TEST_PATH;
    NormalizedNode<?, ?> mergeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    YangInstanceIdentifier mergePath2 = TestModel.OUTER_LIST_PATH;
    NormalizedNode<?, ?> mergeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME);
    YangInstanceIdentifier mergePath3 = TestModel.INNER_LIST_PATH;
    NormalizedNode<?, ?> mergeNode3 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME);
    YangInstanceIdentifier deletePath1 = TestModel.TEST_PATH;
    YangInstanceIdentifier deletePath2 = TestModel.OUTER_LIST_PATH;
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, type);
    transactionProxy.write(writePath1, writeNode1);
    transactionProxy.write(writePath2, writeNode2);
    transactionProxy.delete(deletePath1);
    transactionProxy.merge(mergePath1, mergeNode1);
    transactionProxy.merge(mergePath2, mergeNode2);
    transactionProxy.write(writePath3, writeNode3);
    transactionProxy.merge(mergePath3, mergeNode3);
    transactionProxy.delete(deletePath2);
    // This sends the last batch.
    transactionProxy.ready();
    List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
    assertEquals("Captured BatchedModifications count", 3, batchedModifications.size());
    verifyBatchedModifications(batchedModifications.get(0), false, new WriteModification(writePath1, writeNode1), new WriteModification(writePath2, writeNode2), new DeleteModification(deletePath1));
    verifyBatchedModifications(batchedModifications.get(1), false, new MergeModification(mergePath1, mergeNode1), new MergeModification(mergePath2, mergeNode2), new WriteModification(writePath3, writeNode3));
    verifyBatchedModifications(batchedModifications.get(2), true, true, new MergeModification(mergePath3, mergeNode3), new DeleteModification(deletePath2));
    assertEquals("getTotalMessageCount", 3, batchedModifications.get(2).getTotalMessagesSent());
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) ActorRef(akka.actor.ActorRef) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)

Aggregations

BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)31 Test (org.junit.Test)17 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)13 ActorRef (akka.actor.ActorRef)12 Failure (akka.actor.Status.Failure)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)6 TestActorRef (akka.testkit.TestActorRef)5 TestKit (akka.testkit.javadsl.TestKit)5 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)5 Timeout (akka.util.Timeout)4 CommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply)4 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)4 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)4 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)3 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)3 InOrder (org.mockito.InOrder)2 BatchedModificationsReply (org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply)2 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)2