Search in sources :

Example 26 with BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications 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 BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications 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 28 with BatchedModifications

use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications 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 29 with BatchedModifications

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

Example 30 with BatchedModifications

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

the class RemoteTransactionContextTest method testLimiterOnFailure.

/**
 * OperationLimiter should be correctly released when a failure, like AskTimeoutException occurs. Future reads
 * need to complete immediately with the failure and modifications should not be throttled and thrown away
 * immediately.
 */
@Test
public void testLimiterOnFailure() throws TimeoutException, InterruptedException {
    txContext.executeModification(DELETE);
    txContext.executeModification(DELETE);
    assertEquals(2, limiter.availablePermits());
    Future<Object> future = txContext.sendBatchedModifications();
    assertEquals(2, limiter.availablePermits());
    BatchedModifications msg = kit.expectMsgClass(BatchedModifications.class);
    assertEquals(2, msg.getModifications().size());
    assertEquals(1, msg.getTotalMessagesSent());
    sendReply(new Failure(new NullPointerException()));
    assertFuture(future, new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object success) {
            assertTrue(failure instanceof NullPointerException);
            assertEquals(4, limiter.availablePermits());
            // The transaction has failed, no throttling should occur
            txContext.executeModification(DELETE);
            assertEquals(4, limiter.availablePermits());
            // Executing a read should result in immediate failure
            final SettableFuture<Boolean> readFuture = SettableFuture.create();
            txContext.executeRead(new DataExists(), readFuture);
            assertTrue(readFuture.isDone());
            try {
                readFuture.get();
                fail("Read future did not fail");
            } catch (ExecutionException | InterruptedException e) {
                assertTrue(e.getCause() instanceof NullPointerException);
            }
        }
    });
    future = txContext.directCommit();
    msg = kit.expectMsgClass(BatchedModifications.class);
    // Modification should have been thrown away by the dropped transmit induced by executeRead()
    assertEquals(0, msg.getModifications().size());
    assertTrue(msg.isDoCommitOnReady());
    assertTrue(msg.isReady());
    assertEquals(2, msg.getTotalMessagesSent());
    sendReply(new Failure(new IllegalStateException()));
    assertFuture(future, new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object success) {
            assertTrue(failure instanceof IllegalStateException);
        }
    });
    kit.expectNoMsg();
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) DataExists(org.opendaylight.controller.cluster.datastore.messages.DataExists) Failure(akka.actor.Status.Failure) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Test(org.junit.Test)

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