Search in sources :

Example 41 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class DataTreeCohortIntegrationTest method testCanCommitWithListEntries.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testCanCommitWithListEntries() throws Exception {
    final DOMDataTreeCommitCohort cohort = mock(DOMDataTreeCommitCohort.class);
    doReturn(PostCanCommitStep.NOOP_SUCCESS_FUTURE).when(cohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
    IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
    try (AbstractDataStore dataStore = kit.setupAbstractDataStore(DistributedDataStore.class, "testCanCommitWithMultipleListEntries", "cars-1")) {
        final ObjectRegistration<DOMDataTreeCommitCohort> cohortReg = dataStore.registerCommitCohort(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH.node(CarsModel.CAR_QNAME)), cohort);
        assertNotNull(cohortReg);
        IntegrationTestKit.verifyShardState(dataStore, "cars-1", state -> assertEquals("Cohort registrations", 1, state.getCommitCohortActors().size()));
        // First write an empty base container and verify the cohort isn't invoked.
        DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
        writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
        writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
        kit.doCommit(writeTx.ready());
        verifyNoMoreInteractions(cohort);
        // Write a single car entry and verify the cohort is invoked.
        writeTx = dataStore.newWriteOnlyTransaction();
        final YangInstanceIdentifier optimaPath = CarsModel.newCarPath("optima");
        final MapEntryNode optimaNode = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
        writeTx.write(optimaPath, optimaNode);
        kit.doCommit(writeTx.ready());
        ArgumentCaptor<Collection> candidateCapture = ArgumentCaptor.forClass(Collection.class);
        verify(cohort).canCommit(any(Object.class), candidateCapture.capture(), any(SchemaContext.class));
        assertDataTreeCandidate((DOMDataTreeCandidate) candidateCapture.getValue().iterator().next(), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, optimaPath), ModificationType.WRITE, Optional.of(optimaNode), Optional.absent());
        // 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
        // car entry (DELETE mod).
        reset(cohort);
        doReturn(PostCanCommitStep.NOOP_SUCCESS_FUTURE).when(cohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
        writeTx = dataStore.newWriteOnlyTransaction();
        final YangInstanceIdentifier sportagePath = CarsModel.newCarPath("sportage");
        final MapEntryNode sportageNode = CarsModel.newCarEntry("sportage", BigInteger.valueOf(20000));
        final YangInstanceIdentifier soulPath = CarsModel.newCarPath("soul");
        final MapEntryNode soulNode = CarsModel.newCarEntry("soul", BigInteger.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), candidateCapture.capture(), any(SchemaContext.class));
        assertDataTreeCandidate(findCandidate(candidateCapture, sportagePath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, sportagePath), ModificationType.WRITE, Optional.of(sportageNode), Optional.absent());
        assertDataTreeCandidate(findCandidate(candidateCapture, soulPath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, soulPath), ModificationType.WRITE, Optional.of(soulNode), Optional.absent());
        assertDataTreeCandidate(findCandidate(candidateCapture, optimaPath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, optimaPath), ModificationType.DELETE, Optional.absent(), Optional.of(optimaNode));
        // Delete the cars container - cohort should be invoked for the 2 deleted car entries.
        reset(cohort);
        doReturn(PostCanCommitStep.NOOP_SUCCESS_FUTURE).when(cohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
        writeTx = dataStore.newWriteOnlyTransaction();
        writeTx.delete(CarsModel.BASE_PATH);
        kit.doCommit(writeTx.ready());
        candidateCapture = ArgumentCaptor.forClass(Collection.class);
        verify(cohort).canCommit(any(Object.class), candidateCapture.capture(), any(SchemaContext.class));
        assertDataTreeCandidate(findCandidate(candidateCapture, sportagePath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, sportagePath), ModificationType.DELETE, Optional.absent(), Optional.of(sportageNode));
        assertDataTreeCandidate(findCandidate(candidateCapture, soulPath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, soulPath), ModificationType.DELETE, Optional.absent(), Optional.of(soulNode));
    }
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) Collection(java.util.Collection) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) DOMDataTreeCommitCohort(org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 42 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class AbstractEntityOwnershipTest method verifyOwner.

static void verifyOwner(final String expected, final String entityType, final YangInstanceIdentifier entityId, final Function<YangInstanceIdentifier, NormalizedNode<?, ?>> reader) {
    AssertionError lastError = null;
    YangInstanceIdentifier entityPath = entityPath(entityType, entityId).node(ENTITY_OWNER_QNAME);
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) {
        try {
            NormalizedNode<?, ?> node = reader.apply(entityPath);
            Assert.assertNotNull("Owner was not set for entityId: " + entityId, node);
            Assert.assertEquals("Entity owner", expected, node.getValue().toString());
            return;
        } catch (AssertionError e) {
            lastError = e;
            Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
        }
    }
    throw lastError;
}
Also used : Stopwatch(com.google.common.base.Stopwatch) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 43 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class LocalTransactionContextTest method testMerge.

@Test
public void testMerge() {
    YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
    NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
    localTransactionContext.executeModification(new MergeModification(yangInstanceIdentifier, normalizedNode));
    verify(readWriteTransaction).merge(yangInstanceIdentifier, normalizedNode);
}
Also used : MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 44 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class LocalTransactionContextTest method testDelete.

@Test
public void testDelete() {
    YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
    localTransactionContext.executeModification(new DeleteModification(yangInstanceIdentifier));
    verify(readWriteTransaction).delete(yangInstanceIdentifier);
}
Also used : DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 45 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class LocalTransactionContextTest method testReadyWithWriteError.

@Test
public void testReadyWithWriteError() {
    YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
    NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
    RuntimeException error = new RuntimeException("mock");
    doThrow(error).when(readWriteTransaction).write(yangInstanceIdentifier, normalizedNode);
    localTransactionContext.executeModification(new WriteModification(yangInstanceIdentifier, normalizedNode));
    localTransactionContext.executeModification(new WriteModification(yangInstanceIdentifier, normalizedNode));
    verify(readWriteTransaction).write(yangInstanceIdentifier, normalizedNode);
    doReadyWithExpectedError(error);
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)187 Test (org.junit.Test)111 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)34 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)21 ActorRef (akka.actor.ActorRef)19 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)19 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)15 TestActorRef (akka.testkit.TestActorRef)14 TestKit (akka.testkit.javadsl.TestKit)13 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)12 ArrayList (java.util.ArrayList)11 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)10 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)10 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)10 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)10 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)9 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)9 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)9 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9