Search in sources :

Example 21 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification in project yangtools by opendaylight.

the class Bug5968MergeTest method validMapEntryMultiCommitMergeTest2.

/*
     * This test consists of two transactions (i.e. data tree modifications) on
     * empty data tree. The first one writes mandatory data and second one
     * writes common data without any mandatory data.
     */
@Test
public void validMapEntryMultiCommitMergeTest2() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMapBuilder().build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createEmptyMapEntryBuilder("1").build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createMapEntryM("1", "mandatory-value"));
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare);
    modificationTree2.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createMapEntry("1", "common-value"));
    modificationTree2.ready();
    inMemoryDataTree.validate(modificationTree2);
    final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
    inMemoryDataTree.commit(prepare2);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTree(org.opendaylight.yangtools.yang.data.tree.api.DataTree) Test(org.junit.Test)

Example 22 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification in project yangtools by opendaylight.

the class Bug4295Test method secondModification.

private void secondModification(final int testScenarioNumber) throws DataValidationFailedException {
    /*  MERGE */
    SystemMapNode outerListNode = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(outerList)).withChild(createOuterListEntry("3", "o-3")).withChild(createOuterListEntry("4", "o-4")).withChild(createOuterListEntry("5", "o-5")).build();
    ContainerNode rootContainerNode = createRootContainerBuilder().withChild(createSubRootContainerBuilder().withChild(outerListNode).build()).build();
    YangInstanceIdentifier path = YangInstanceIdentifier.of(root);
    DataTreeModification modification = inMemoryDataTree.takeSnapshot().newModification();
    modification.merge(path, rootContainerNode);
    if (testScenarioNumber == 1) {
        /* WRITE EMPTY INNER LIST */
        writeEmptyInnerList(modification, "2");
    } else if (testScenarioNumber == 2) {
        /* WRITE INNER LIST ENTRY */
        MapEntryNode innerListEntryA = createInnerListEntry("a", "i-a-2");
        path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList).node(createOuterListEntryPath("2")).node(innerList).node(createInnerListEntryPath("a"));
        modification.write(path, innerListEntryA);
    } else if (testScenarioNumber == 3) {
        /* WRITE INNER LIST WITH ENTRIES */
        SystemMapNode innerListNode = createInnerListBuilder().withChild(createInnerListEntry("a", "i-a-3")).withChild(createInnerListEntry("c", "i-c")).build();
        path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList).node(createOuterListEntryPath("2")).node(innerList);
        modification.write(path, innerListNode);
    }
    /*  COMMIT */
    modification.ready();
    inMemoryDataTree.validate(modification);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(modification));
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 23 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification in project yangtools by opendaylight.

the class ListConstraintsValidation method minMaxListTestPass.

@Test
public void minMaxListTestPass() throws DataValidationFailedException {
    final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "foo");
    final MapEntryNode barEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "bar");
    final MapNode mapNode1 = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME)).withChild(fooEntryNode).build();
    final MapNode mapNode2 = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME)).withChild(barEntryNode).build();
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.write(MIN_MAX_LIST_PATH, mapNode1);
    modificationTree.merge(MIN_MAX_LIST_PATH, mapNode2);
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare);
    final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
    final Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
    assertTrue(minMaxListRead.isPresent());
    assertEquals(2, ((NormalizedNodeContainer<?>) minMaxListRead.get()).size());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 24 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification in project yangtools by opendaylight.

the class ListConstraintsValidation method unkeyedListTestPass.

@Test
public void unkeyedListTestPass() throws DataValidationFailedException {
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    final UnkeyedListEntryNode foo = ImmutableUnkeyedListEntryNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(UNKEYED_LEAF_QNAME)).withChild(ImmutableNodes.leafNode(UNKEYED_LEAF_QNAME, "foo")).build();
    final List<UnkeyedListEntryNode> unkeyedEntries = new ArrayList<>();
    unkeyedEntries.add(foo);
    final UnkeyedListNode unkeyedListNode = ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME)).withValue(unkeyedEntries).build();
    modificationTree.write(MASTER_CONTAINER_PATH, ImmutableNodes.containerNode(MASTER_CONTAINER_QNAME));
    modificationTree.merge(UNKEYED_LIST_PATH, unkeyedListNode);
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare1);
    final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
    final Optional<NormalizedNode> unkeyedListRead = snapshotAfterCommit.readNode(UNKEYED_LIST_PATH);
    assertTrue(unkeyedListRead.isPresent());
    assertEquals(1, ((UnkeyedListNode) unkeyedListRead.get()).size());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ArrayList(java.util.ArrayList) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) Test(org.junit.Test)

Example 25 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification in project yangtools by opendaylight.

the class ListConstraintsValidation method minMaxLeafListPass.

@Test
public void minMaxLeafListPass() throws DataValidationFailedException {
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    final NodeWithValue<Object> barPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "bar");
    final NodeWithValue<Object> gooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "goo");
    final LeafSetEntryNode<Object> barLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(barPath).withValue("bar").build();
    final LeafSetEntryNode<Object> gooLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(gooPath).withValue("goo").build();
    final LeafSetNode<Object> fooLeafSetNode = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME)).withChildValue("foo").build();
    modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode);
    modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
    modificationTree.merge(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry);
    modificationTree.delete(MIN_MAX_LEAF_LIST_PATH.node(gooPath));
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare1);
    final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
    final Optional<NormalizedNode> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
    assertTrue(masterContainer.isPresent());
    final NormalizedNodeContainer<?> leafList = (NormalizedNodeContainer<?>) ((DistinctNodeContainer) masterContainer.get()).childByArg(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
    assertNotNull(leafList);
    assertEquals(2, leafList.size());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NormalizedNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer) NodeWithValue(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)162 Test (org.junit.Test)112 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)102 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)44 DataTree (org.opendaylight.yangtools.yang.data.tree.api.DataTree)43 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)36 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)32 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)31 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)23 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory)17 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)12 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification)11 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException)10 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)9 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)9 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)7 Benchmark (org.openjdk.jmh.annotations.Benchmark)6 Measurement (org.openjdk.jmh.annotations.Measurement)6 Warmup (org.openjdk.jmh.annotations.Warmup)6 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)5