Search in sources :

Example 1 with PostCanCommitStep

use of org.opendaylight.mdsal.common.api.PostCanCommitStep 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)

Aggregations

Collection (java.util.Collection)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 PostCanCommitStep (org.opendaylight.mdsal.common.api.PostCanCommitStep)1 DOMDataTreeCommitCohort (org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort)1 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)1 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)1 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)1