Search in sources :

Example 16 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class DataTreeCohortIntegrationTest method testAbortAfterCanCommit.

/**
 * FIXME: Since we invoke DOMDataTreeCommitCohort#canCommit on preCommit (as that's when we generate a
 * DataTreeCandidate) and since currently preCommit is a noop in the Shard backend (it is combined with commit),
 * we can't actually test abort after canCommit.
 */
@SuppressWarnings("unchecked")
@Test
@Ignore
public void testAbortAfterCanCommit() throws Exception {
    final DOMDataTreeCommitCohort cohortToAbort = mock(DOMDataTreeCommitCohort.class);
    final PostCanCommitStep stepToAbort = mock(PostCanCommitStep.class);
    doReturn(ThreePhaseCommitStep.NOOP_ABORT_FUTURE).when(stepToAbort).abort();
    doReturn(PostPreCommitStep.NOOP_FUTURE).when(stepToAbort).preCommit();
    doReturn(Futures.immediateCheckedFuture(stepToAbort)).when(cohortToAbort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
    IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
    try (AbstractDataStore dataStore = kit.setupAbstractDataStore(DistributedDataStore.class, "testAbortAfterCanCommit", "test-1", "cars-1")) {
        dataStore.registerCommitCohort(TEST_ID, cohortToAbort);
        IntegrationTestKit.verifyShardState(dataStore, "test-1", state -> assertEquals("Cohort registrations", 1, state.getCommitCohortActors().size()));
        DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
        writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
        writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
        DOMStoreThreePhaseCommitCohort dsCohort = writeTx.ready();
        dsCohort.canCommit().get(5, TimeUnit.SECONDS);
        dsCohort.preCommit().get(5, TimeUnit.SECONDS);
        dsCohort.abort().get(5, TimeUnit.SECONDS);
        verify(stepToAbort).abort();
    }
}
Also used : PostCanCommitStep(org.opendaylight.mdsal.common.api.PostCanCommitStep) DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) Collection(java.util.Collection) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) DOMDataTreeCommitCohort(org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class TransactionProxyTest method testReadyWithReplyFailure.

@Test
public void testReadyWithReplyFailure() throws Exception {
    dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true);
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
    NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    expectFailedBatchedModifications(actorRef);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
    transactionProxy.merge(TestModel.TEST_PATH, nodeToWrite);
    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof SingleCommitCohortProxy);
    verifyCohortFutures((SingleCommitCohortProxy) ready, TestException.class);
}
Also used : ActorRef(akka.actor.ActorRef) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 18 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class TransactionProxyTest method testReadyWithInvalidReplyMessageType.

@Test
public void testReadyWithInvalidReplyMessageType() throws Exception {
    dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true);
    ActorRef actorRef1 = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
    ActorRef actorRef2 = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY, "junk");
    doReturn(Futures.successful(new Object())).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef1)), isA(BatchedModifications.class), any(Timeout.class));
    expectBatchedModificationsReady(actorRef2);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
    transactionProxy.write(TestModel.JUNK_PATH, ImmutableNodes.containerNode(TestModel.JUNK_QNAME));
    transactionProxy.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof ThreePhaseCommitCohortProxy);
    verifyCohortFutures((ThreePhaseCommitCohortProxy) ready, actorSelection(actorRef2), IllegalArgumentException.class);
}
Also used : ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) 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 19 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class TransactionProxyTest method testWriteOnlyTxWithFindPrimaryShardFailure.

private void testWriteOnlyTxWithFindPrimaryShardFailure(final Exception toThrow) throws Exception {
    doReturn(Futures.failed(toThrow)).when(mockActorContext).findPrimaryShardAsync(anyString());
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
    NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    transactionProxy.merge(TestModel.TEST_PATH, nodeToWrite);
    transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
    transactionProxy.delete(TestModel.TEST_PATH);
    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof SingleCommitCohortProxy);
    verifyCohortFutures((SingleCommitCohortProxy) ready, toThrow.getClass());
}
Also used : DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)

Example 20 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class TransactionProxyTest method testReadyWithNoModifications.

@Test
public void testReadyWithNoModifications() throws Exception {
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
    doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class));
    expectBatchedModificationsReady(actorRef, true);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    transactionProxy.read(TestModel.TEST_PATH);
    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);
}
Also used : CommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) 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)

Aggregations

DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)40 Test (org.junit.Test)31 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)17 ActorRef (akka.actor.ActorRef)11 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)11 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)10 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)8 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)8 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)8 CountDownLatch (java.util.concurrent.CountDownLatch)6 ExecutionException (java.util.concurrent.ExecutionException)6 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)6 CommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply)6 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)6 AddressFromURIString (akka.actor.AddressFromURIString)5 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)5 DOMStoreTransactionChain (org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)5 IOException (java.io.IOException)4