Search in sources :

Example 26 with WriteModification

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

the class TransactionProxyTest method testReadyWithWriteOnlyAndLastBatchEmpty.

@Test
public void testReadyWithWriteOnlyAndLastBatchEmpty() throws Exception {
    dataStoreContextBuilder.shardBatchedModificationCount(1).writeOnlyTransactionOptimizationsEnabled(true);
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
    NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    expectBatchedModificationsReady(actorRef, true);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
    transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof SingleCommitCohortProxy);
    verifyCohortFutures((SingleCommitCohortProxy) ready, new CommitTransactionReply().toSerializable());
    List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
    assertEquals("Captured BatchedModifications count", 2, batchedModifications.size());
    verifyBatchedModifications(batchedModifications.get(0), false, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
    verifyBatchedModifications(batchedModifications.get(1), true, true);
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) CommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply) ActorRef(akka.actor.ActorRef) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 27 with WriteModification

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

the class TransactionProxyTest method testWrite.

@Test
public void testWrite() throws Exception {
    dataStoreContextBuilder.shardBatchedModificationCount(1);
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
    NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    expectBatchedModifications(actorRef, 1);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
    transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
    verifyOneBatchedModification(actorRef, new WriteModification(TestModel.TEST_PATH, nodeToWrite), false);
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) ActorRef(akka.actor.ActorRef) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 28 with WriteModification

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

the class TransactionProxyTest method testReadyWithWriteOnlyAndLastBatchPending.

@Test
public void testReadyWithWriteOnlyAndLastBatchPending() throws Exception {
    dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true);
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
    NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    expectBatchedModificationsReady(actorRef, true);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
    transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof SingleCommitCohortProxy);
    verifyCohortFutures((SingleCommitCohortProxy) ready, new CommitTransactionReply().toSerializable());
    List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
    assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
    verifyBatchedModifications(batchedModifications.get(0), true, true, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) CommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply) ActorRef(akka.actor.ActorRef) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 29 with WriteModification

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

Example 30 with WriteModification

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

the class TransactionProxyTest method testReadWrite.

@Test
public void testReadWrite() throws Exception {
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
    final NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class));
    expectBatchedModifications(actorRef, 1);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    transactionProxy.read(TestModel.TEST_PATH);
    transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
    transactionProxy.read(TestModel.TEST_PATH);
    transactionProxy.read(TestModel.TEST_PATH);
    List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
    assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
    verifyBatchedModifications(batchedModifications.get(0), false, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Aggregations

WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)30 Test (org.junit.Test)22 ActorRef (akka.actor.ActorRef)16 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)14 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)11 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)11 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)8 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)7 Timeout (akka.util.Timeout)6 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)6 TestActorRef (akka.testkit.TestActorRef)4 TestKit (akka.testkit.javadsl.TestKit)4 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)4 Modification (org.opendaylight.controller.cluster.datastore.modification.Modification)4 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 CommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply)3 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)3