X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDataTreeCohortIntegrationTest.java;h=4ec8bc36657875a3fadfb68cae43df4bc5387c25;hp=11462b26d22ae0cf64c860109344420927019f36;hb=HEAD;hpb=baf24349053f1097e311de0b6632a7463bff7b1b diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeCohortIntegrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeCohortIntegrationTest.java index 11462b26d2..7eb534c334 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeCohortIntegrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeCohortIntegrationTest.java @@ -12,6 +12,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyCollection; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; @@ -26,9 +27,7 @@ import akka.testkit.javadsl.TestKit; import com.google.common.base.Throwables; import com.google.common.util.concurrent.FluentFuture; import com.typesafe.config.ConfigFactory; -import java.math.BigInteger; import java.util.Collection; -import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.junit.AfterClass; @@ -36,6 +35,7 @@ import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.opendaylight.controller.cluster.databroker.ClientBackedDataStore; import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.mdsal.common.api.DataValidationFailedException; @@ -48,15 +48,14 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction; -import org.opendaylight.yangtools.concepts.ObjectRegistration; import org.opendaylight.yangtools.util.concurrent.FluentFutures; +import org.opendaylight.yangtools.yang.common.Uint64; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.data.tree.api.ModificationType; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; public class DataTreeCohortIntegrationTest { @@ -93,36 +92,36 @@ public class DataTreeCohortIntegrationTest { @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testSuccessfulCanCommitWithNoopPostStep() throws Exception { - final DOMDataTreeCommitCohort cohort = mock(DOMDataTreeCommitCohort.class); + final var cohort = mock(DOMDataTreeCommitCohort.class); doReturn(PostCanCommitStep.NOOP_SUCCESSFUL_FUTURE).when(cohort).canCommit(any(Object.class), - any(SchemaContext.class), any(Collection.class)); + any(EffectiveModelContext.class), anyCollection()); ArgumentCaptor candidateCapt = ArgumentCaptor.forClass(Collection.class); IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder); - try (AbstractDataStore dataStore = kit.setupAbstractDataStore( - DistributedDataStore.class, "testSuccessfulCanCommitWithNoopPostStep", "test-1")) { - final ObjectRegistration cohortReg = dataStore.registerCommitCohort(TEST_ID, - cohort); + try (var dataStore = kit.setupDataStore(ClientBackedDataStore.class, "testSuccessfulCanCommitWithNoopPostStep", + "test-1")) { + + final var cohortReg = dataStore.registerCommitCohort(TEST_ID, cohort); assertNotNull(cohortReg); IntegrationTestKit.verifyShardState(dataStore, "test-1", state -> assertEquals("Cohort registrations", 1, state.getCommitCohortActors().size())); - final ContainerNode node = ImmutableNodes.containerNode(TestModel.TEST_QNAME); + final var node = ImmutableNodes.containerNode(TestModel.TEST_QNAME); kit.testWriteTransaction(dataStore, TestModel.TEST_PATH, node); - verify(cohort).canCommit(any(Object.class), any(SchemaContext.class), candidateCapt.capture()); + verify(cohort).canCommit(any(Object.class), any(EffectiveModelContext.class), candidateCapt.capture()); assertDataTreeCandidate((DOMDataTreeCandidate) candidateCapt.getValue().iterator().next(), TEST_ID, - ModificationType.WRITE, Optional.of(node), Optional.empty()); + ModificationType.WRITE, node, null); reset(cohort); doReturn(PostCanCommitStep.NOOP_SUCCESSFUL_FUTURE).when(cohort).canCommit(any(Object.class), - any(SchemaContext.class), any(Collection.class)); + any(EffectiveModelContext.class), anyCollection()); kit.testWriteTransaction(dataStore, TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME) .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 42)) .build()); - verify(cohort).canCommit(any(Object.class), any(SchemaContext.class), any(Collection.class)); + verify(cohort).canCommit(any(Object.class), any(EffectiveModelContext.class), anyCollection()); cohortReg.close(); @@ -134,17 +133,15 @@ public class DataTreeCohortIntegrationTest { } } - @SuppressWarnings("unchecked") @Test public void testFailedCanCommit() throws Exception { - final DOMDataTreeCommitCohort failedCohort = mock(DOMDataTreeCommitCohort.class); + final var failedCohort = mock(DOMDataTreeCommitCohort.class); doReturn(FAILED_CAN_COMMIT_FUTURE).when(failedCohort).canCommit(any(Object.class), - any(SchemaContext.class), any(Collection.class)); + any(EffectiveModelContext.class), anyCollection()); - IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder); - try (AbstractDataStore dataStore = kit.setupAbstractDataStore( - DistributedDataStore.class, "testFailedCanCommit", "test-1")) { + final var kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder); + try (var dataStore = kit.setupDataStore(ClientBackedDataStore.class, "testFailedCanCommit", "test-1")) { dataStore.registerCommitCohort(TEST_ID, failedCohort); IntegrationTestKit.verifyShardState(dataStore, "test-1", @@ -165,14 +162,15 @@ public class DataTreeCohortIntegrationTest { @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testCanCommitWithListEntries() throws Exception { - final DOMDataTreeCommitCohort cohort = mock(DOMDataTreeCommitCohort.class); + final var cohort = mock(DOMDataTreeCommitCohort.class); doReturn(PostCanCommitStep.NOOP_SUCCESSFUL_FUTURE).when(cohort).canCommit(any(Object.class), - any(SchemaContext.class), any(Collection.class)); - IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder); + any(EffectiveModelContext.class), anyCollection()); + final var kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder); - try (AbstractDataStore dataStore = kit.setupAbstractDataStore( - DistributedDataStore.class, "testCanCommitWithMultipleListEntries", "cars-1")) { - final ObjectRegistration cohortReg = dataStore.registerCommitCohort( + try (var dataStore = kit.setupDataStore(ClientBackedDataStore.class, "testCanCommitWithMultipleListEntries", + "cars-1")) { + + final var cohortReg = dataStore.registerCommitCohort( new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH .node(CarsModel.CAR_QNAME)), cohort); assertNotNull(cohortReg); @@ -192,15 +190,15 @@ public class DataTreeCohortIntegrationTest { writeTx = dataStore.newWriteOnlyTransaction(); final YangInstanceIdentifier optimaPath = CarsModel.newCarPath("optima"); - final MapEntryNode optimaNode = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000)); + final MapEntryNode optimaNode = CarsModel.newCarEntry("optima", Uint64.valueOf(20000)); writeTx.write(optimaPath, optimaNode); kit.doCommit(writeTx.ready()); ArgumentCaptor candidateCapture = ArgumentCaptor.forClass(Collection.class); - verify(cohort).canCommit(any(Object.class), any(SchemaContext.class), candidateCapture.capture()); + verify(cohort).canCommit(any(Object.class), any(EffectiveModelContext.class), candidateCapture.capture()); assertDataTreeCandidate((DOMDataTreeCandidate) candidateCapture.getValue().iterator().next(), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, optimaPath), ModificationType.WRITE, - Optional.of(optimaNode), Optional.empty()); + optimaNode, null); // Write replace the cars container with 2 new car entries. The cohort should get invoked with 3 // DOMDataTreeCandidates: once for each of the 2 new car entries (WRITE mod) and once for the deleted prior @@ -208,51 +206,51 @@ public class DataTreeCohortIntegrationTest { reset(cohort); doReturn(PostCanCommitStep.NOOP_SUCCESSFUL_FUTURE).when(cohort).canCommit(any(Object.class), - any(SchemaContext.class), any(Collection.class)); + any(EffectiveModelContext.class), anyCollection()); writeTx = dataStore.newWriteOnlyTransaction(); final YangInstanceIdentifier sportagePath = CarsModel.newCarPath("sportage"); - final MapEntryNode sportageNode = CarsModel.newCarEntry("sportage", BigInteger.valueOf(20000)); + final MapEntryNode sportageNode = CarsModel.newCarEntry("sportage", Uint64.valueOf(20000)); final YangInstanceIdentifier soulPath = CarsModel.newCarPath("soul"); - final MapEntryNode soulNode = CarsModel.newCarEntry("soul", BigInteger.valueOf(20000)); + final MapEntryNode soulNode = CarsModel.newCarEntry("soul", Uint64.valueOf(20000)); writeTx.write(CarsModel.BASE_PATH, CarsModel.newCarsNode(CarsModel.newCarsMapNode(sportageNode,soulNode))); kit.doCommit(writeTx.ready()); candidateCapture = ArgumentCaptor.forClass(Collection.class); - verify(cohort).canCommit(any(Object.class), any(SchemaContext.class), candidateCapture.capture()); + verify(cohort).canCommit(any(Object.class), any(EffectiveModelContext.class), candidateCapture.capture()); assertDataTreeCandidate(findCandidate(candidateCapture, sportagePath), new DOMDataTreeIdentifier( LogicalDatastoreType.CONFIGURATION, sportagePath), ModificationType.WRITE, - Optional.of(sportageNode), Optional.empty()); + sportageNode, null); assertDataTreeCandidate(findCandidate(candidateCapture, soulPath), new DOMDataTreeIdentifier( LogicalDatastoreType.CONFIGURATION, soulPath), ModificationType.WRITE, - Optional.of(soulNode), Optional.empty()); + soulNode, null); assertDataTreeCandidate(findCandidate(candidateCapture, optimaPath), new DOMDataTreeIdentifier( LogicalDatastoreType.CONFIGURATION, optimaPath), ModificationType.DELETE, - Optional.empty(), Optional.of(optimaNode)); + null, optimaNode); // Delete the cars container - cohort should be invoked for the 2 deleted car entries. reset(cohort); doReturn(PostCanCommitStep.NOOP_SUCCESSFUL_FUTURE).when(cohort).canCommit(any(Object.class), - any(SchemaContext.class), any(Collection.class)); + any(EffectiveModelContext.class), anyCollection()); writeTx = dataStore.newWriteOnlyTransaction(); writeTx.delete(CarsModel.BASE_PATH); kit.doCommit(writeTx.ready()); candidateCapture = ArgumentCaptor.forClass(Collection.class); - verify(cohort).canCommit(any(Object.class), any(SchemaContext.class), candidateCapture.capture()); + verify(cohort).canCommit(any(Object.class), any(EffectiveModelContext.class), candidateCapture.capture()); assertDataTreeCandidate(findCandidate(candidateCapture, sportagePath), new DOMDataTreeIdentifier( LogicalDatastoreType.CONFIGURATION, sportagePath), ModificationType.DELETE, - Optional.empty(), Optional.of(sportageNode)); + null, sportageNode); assertDataTreeCandidate(findCandidate(candidateCapture, soulPath), new DOMDataTreeIdentifier( LogicalDatastoreType.CONFIGURATION, soulPath), ModificationType.DELETE, - Optional.empty(), Optional.of(soulNode)); + null, soulNode); } } @@ -275,29 +273,28 @@ public class DataTreeCohortIntegrationTest { * 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); + final var cohortToAbort = mock(DOMDataTreeCommitCohort.class); + final var stepToAbort = mock(PostCanCommitStep.class); doReturn(ThreePhaseCommitStep.NOOP_ABORT_FUTURE).when(stepToAbort).abort(); doReturn(PostPreCommitStep.NOOP_FUTURE).when(stepToAbort).preCommit(); doReturn(FluentFutures.immediateFluentFuture(stepToAbort)).when(cohortToAbort).canCommit(any(Object.class), - any(SchemaContext.class), any(Collection.class)); + any(EffectiveModelContext.class), anyCollection()); - IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder); - try (AbstractDataStore dataStore = kit.setupAbstractDataStore( - DistributedDataStore.class, "testAbortAfterCanCommit", "test-1", "cars-1")) { + var kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder); + try (var dataStore = kit.setupDataStore(ClientBackedDataStore.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(); + var writeTx = dataStore.newWriteOnlyTransaction(); writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()); - DOMStoreThreePhaseCommitCohort dsCohort = writeTx.ready(); + var dsCohort = writeTx.ready(); dsCohort.canCommit().get(5, TimeUnit.SECONDS); dsCohort.preCommit().get(5, TimeUnit.SECONDS); @@ -308,20 +305,11 @@ public class DataTreeCohortIntegrationTest { private static void assertDataTreeCandidate(final DOMDataTreeCandidate candidate, final DOMDataTreeIdentifier expTreeId, final ModificationType expType, - final Optional> expDataAfter, final Optional> expDataBefore) { + final NormalizedNode expDataAfter, final NormalizedNode expDataBefore) { assertNotNull("Expected candidate for path " + expTreeId.getRootIdentifier(), candidate); assertEquals("rootPath", expTreeId, candidate.getRootPath()); - assertEquals("modificationType", expType, candidate.getRootNode().getModificationType()); - - assertEquals("dataAfter present", expDataAfter.isPresent(), candidate.getRootNode().getDataAfter().isPresent()); - if (expDataAfter.isPresent()) { - assertEquals("dataAfter", expDataAfter.get(), candidate.getRootNode().getDataAfter().get()); - } - - assertEquals("dataBefore present", expDataBefore.isPresent(), - candidate.getRootNode().getDataBefore().isPresent()); - if (expDataBefore.isPresent()) { - assertEquals("dataBefore", expDataBefore.get(), candidate.getRootNode().getDataBefore().get()); - } + assertEquals("modificationType", expType, candidate.getRootNode().modificationType()); + assertEquals("dataAfter", expDataAfter, candidate.getRootNode().dataAfter()); + assertEquals("dataBefore", expDataBefore, candidate.getRootNode().dataBefore()); } }