Search in sources :

Example 66 with YangInstanceIdentifier

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

the class PruningDataTreeModificationTest method testMergeWithInvalidNamespace.

@Test
public void testMergeWithInvalidNamespace() throws DataValidationFailedException {
    NormalizedNode<?, ?> normalizedNode = PeopleModel.emptyContainer();
    YangInstanceIdentifier path = PeopleModel.BASE_PATH;
    pruningDataTreeModification.merge(path, normalizedNode);
    verify(mockModification, times(1)).merge(path, normalizedNode);
    DataTreeCandidate candidate = getCandidate();
    assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().getModificationType());
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 67 with YangInstanceIdentifier

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

the class PruningDataTreeModificationTest method testWriteWithInvalidChildNodeNames.

@Test
public void testWriteWithInvalidChildNodeNames() throws DataValidationFailedException {
    ContainerNode augContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(AUG_CONTAINER)).withChild(ImmutableNodes.containerNode(AUG_INNER_CONTAINER)).build();
    DataContainerChild<?, ?> outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two")));
    ContainerNode normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).withChild(augContainer).withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")).withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")).build();
    YangInstanceIdentifier path = TestModel.TEST_PATH;
    pruningDataTreeModification.write(path, normalizedNode);
    dataTree.commit(getCandidate());
    ContainerNode prunedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")).build();
    Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(path);
    assertTrue("After pruning present", actual.isPresent());
    assertEquals("After pruning", prunedNode, actual.get());
}
Also used : ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 68 with YangInstanceIdentifier

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

the class DistributedShardedDOMDataTreeTest method testMultipleShardLevels.

// top level shard at TEST element, with subshards on each outer-list map entry
@Test
@Ignore
public void testMultipleShardLevels() throws Exception {
    initEmptyDatastores();
    final DistributedShardRegistration testShardReg = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, SINGLE_MEMBER), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    final ArrayList<DistributedShardRegistration> registrations = new ArrayList<>();
    final int listSize = 5;
    for (int i = 0; i < listSize; i++) {
        final YangInstanceIdentifier entryYID = getOuterListIdFor(i);
        final CompletionStage<DistributedShardRegistration> future = leaderShardFactory.createDistributedShard(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, entryYID), SINGLE_MEMBER);
        registrations.add(waitOnAsyncTask(future, DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION));
    }
    final DOMDataTreeIdentifier rootId = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
    final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singletonList(rootId));
    DOMDataTreeCursorAwareTransaction transaction = producer.createTransaction(false);
    DOMDataTreeWriteCursor cursor = transaction.createCursor(rootId);
    assertNotNull(cursor);
    final MapNode outerList = ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
    final ContainerNode testNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(outerList).build();
    cursor.write(testNode.getIdentifier(), testNode);
    cursor.close();
    transaction.submit().checkedGet();
    final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
    doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
    final MapNode wholeList = ImmutableMapNodeBuilder.create(outerList).withValue(createOuterEntries(listSize, "testing-values")).build();
    transaction = producer.createTransaction(false);
    cursor = transaction.createCursor(TEST_ID);
    assertNotNull(cursor);
    cursor.write(wholeList.getIdentifier(), wholeList);
    cursor.close();
    transaction.submit().checkedGet();
    leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID), true, Collections.emptyList());
    verify(mockedDataTreeListener, timeout(35000).atLeast(2)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture());
    verifyNoMoreInteractions(mockedDataTreeListener);
    final List<Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>>> allSubtrees = captorForSubtrees.getAllValues();
    final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> lastSubtree = allSubtrees.get(allSubtrees.size() - 1);
    final NormalizedNode<?, ?> actual = lastSubtree.get(TEST_ID);
    assertNotNull(actual);
    final NormalizedNode<?, ?> expected = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableMapNodeBuilder.create(outerList).withValue(createOuterEntries(listSize, "testing-values")).build()).build();
    for (final DistributedShardRegistration registration : registrations) {
        waitOnAsyncTask(registration.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    }
    waitOnAsyncTask(testShardReg.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    assertEquals(expected, actual);
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ArrayList(java.util.ArrayList) DOMDataTreeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeListener) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 69 with YangInstanceIdentifier

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

the class WriteModificationTest method testSerialization.

@Test
public void testSerialization() {
    YangInstanceIdentifier path = TestModel.TEST_PATH;
    NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
    WriteModification expected = new WriteModification(path, data);
    WriteModification clone = (WriteModification) SerializationUtils.clone(expected);
    assertEquals("getPath", expected.getPath(), clone.getPath());
    assertEquals("getData", expected.getData(), clone.getData());
}
Also used : YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 70 with YangInstanceIdentifier

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

the class CommitTransactionPayloadTest method testLeafNodeCandidate.

@Test
public void testLeafNodeCandidate() throws Exception {
    YangInstanceIdentifier leafPath = YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(TestModel.DESC_QNAME).build();
    LeafNode<Object> leafNode = Builders.leafBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.DESC_QNAME)).withValue("test").build();
    candidate = DataTreeCandidates.fromNormalizedNode(leafPath, leafNode);
    CommitTransactionPayload payload = CommitTransactionPayload.create(nextTransactionId(), candidate);
    assertCandidateEquals(candidate, payload.getCandidate().getValue());
}
Also used : YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

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