Search in sources :

Example 6 with DeleteModification

use of org.opendaylight.controller.cluster.datastore.modification.DeleteModification in project controller by opendaylight.

the class EntityOwnershipShard method onUnregisterCandidateLocal.

private void onUnregisterCandidateLocal(final UnregisterCandidateLocal unregisterCandidate) {
    LOG.debug("{}: onUnregisterCandidateLocal: {}", persistenceId(), unregisterCandidate);
    DOMEntity entity = unregisterCandidate.getEntity();
    YangInstanceIdentifier candidatePath = candidatePath(entity.getType(), entity.getIdentifier(), localMemberName.getName());
    commitCoordinator.commitModification(new DeleteModification(candidatePath), this);
    getSender().tell(SuccessReply.INSTANCE, getSelf());
}
Also used : DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 7 with DeleteModification

use of org.opendaylight.controller.cluster.datastore.modification.DeleteModification 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 8 with DeleteModification

use of org.opendaylight.controller.cluster.datastore.modification.DeleteModification 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)

Example 9 with DeleteModification

use of org.opendaylight.controller.cluster.datastore.modification.DeleteModification in project controller by opendaylight.

the class TransactionProxyTest method testModificationOperationBatchingWithInterleavedReads.

@Test
public void testModificationOperationBatchingWithInterleavedReads() throws Exception {
    int shardBatchedModificationCount = 10;
    dataStoreContextBuilder.shardBatchedModificationCount(shardBatchedModificationCount);
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
    expectBatchedModifications(actorRef, shardBatchedModificationCount);
    final YangInstanceIdentifier writePath1 = TestModel.TEST_PATH;
    final NormalizedNode<?, ?> writeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    YangInstanceIdentifier writePath2 = TestModel.OUTER_LIST_PATH;
    NormalizedNode<?, ?> writeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME);
    final YangInstanceIdentifier mergePath1 = TestModel.TEST_PATH;
    final NormalizedNode<?, ?> mergeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    YangInstanceIdentifier mergePath2 = TestModel.INNER_LIST_PATH;
    NormalizedNode<?, ?> mergeNode2 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME);
    final YangInstanceIdentifier deletePath = TestModel.OUTER_LIST_PATH;
    doReturn(readDataReply(writeNode2)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(writePath2), any(Timeout.class));
    doReturn(readDataReply(mergeNode2)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(mergePath2), any(Timeout.class));
    doReturn(dataExistsReply(true)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqDataExists(), any(Timeout.class));
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    transactionProxy.write(writePath1, writeNode1);
    transactionProxy.write(writePath2, writeNode2);
    Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(writePath2).get(5, TimeUnit.SECONDS);
    assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
    assertEquals("Response NormalizedNode", writeNode2, readOptional.get());
    transactionProxy.merge(mergePath1, mergeNode1);
    transactionProxy.merge(mergePath2, mergeNode2);
    readOptional = transactionProxy.read(mergePath2).get(5, TimeUnit.SECONDS);
    transactionProxy.delete(deletePath);
    Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
    assertEquals("Exists response", true, exists);
    assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
    assertEquals("Response NormalizedNode", mergeNode2, readOptional.get());
    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));
    verifyBatchedModifications(batchedModifications.get(1), false, new MergeModification(mergePath1, mergeNode1), new MergeModification(mergePath2, mergeNode2));
    verifyBatchedModifications(batchedModifications.get(2), false, new DeleteModification(deletePath));
    InOrder inOrder = Mockito.inOrder(mockActorContext);
    inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), isA(BatchedModifications.class), any(Timeout.class));
    inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(writePath2), any(Timeout.class));
    inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), isA(BatchedModifications.class), any(Timeout.class));
    inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(mergePath2), any(Timeout.class));
    inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), isA(BatchedModifications.class), any(Timeout.class));
    inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqDataExists(), any(Timeout.class));
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) InOrder(org.mockito.InOrder) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Aggregations

DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)9 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 Test (org.junit.Test)6 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)5 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)5 ActorRef (akka.actor.ActorRef)4 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)3 InOrder (org.mockito.InOrder)2 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)2 TestActorRef (akka.testkit.TestActorRef)1 TestKit (akka.testkit.javadsl.TestKit)1 Timeout (akka.util.Timeout)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)1 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)1 BatchedModificationsReply (org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply)1 Modification (org.opendaylight.controller.cluster.datastore.modification.Modification)1 DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)1 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)1