Search in sources :

Example 1 with DataTreeModificationCursor

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

the class InMemoryDataTreeBenchmark method write10KSingleNodeWithTenInnerItemsInOneCommitCursorBenchmark.

@Benchmark
@Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
public void write10KSingleNodeWithTenInnerItemsInOneCommitCursorBenchmark() throws DataValidationFailedException {
    final CursorAwareDataTreeModification modification = begin();
    try (DataTreeModificationCursor cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).get()) {
        for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
            cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
        }
    }
    commit(modification);
}
Also used : DataTreeModificationCursor(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor) CursorAwareDataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification) Measurement(org.openjdk.jmh.annotations.Measurement) Warmup(org.openjdk.jmh.annotations.Warmup) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 2 with DataTreeModificationCursor

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

the class InMemoryDataTreeBenchmark method write100KSingleNodeWithOneInnerItemInOneCommitCursorBenchmark.

@Benchmark
@Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
public void write100KSingleNodeWithOneInnerItemInOneCommitCursorBenchmark() throws DataValidationFailedException {
    final CursorAwareDataTreeModification modification = begin();
    try (DataTreeModificationCursor cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).get()) {
        for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
            cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
        }
    }
    commit(modification);
}
Also used : DataTreeModificationCursor(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor) CursorAwareDataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification) Measurement(org.openjdk.jmh.annotations.Measurement) Warmup(org.openjdk.jmh.annotations.Warmup) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 3 with DataTreeModificationCursor

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

the class DataTreeCandidatesTest method setUp.

@Before
public void setUp() throws Exception {
    dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
    final ContainerNode testContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME)).build()).build();
    final InMemoryDataTreeModification modification = (InMemoryDataTreeModification) dataTree.takeSnapshot().newModification();
    final DataTreeModificationCursor cursor = modification.openCursor();
    cursor.write(TestModel.TEST_PATH.getLastPathArgument(), testContainer);
    modification.ready();
    dataTree.validate(modification);
    final DataTreeCandidate candidate = dataTree.prepare(modification);
    dataTree.commit(candidate);
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DataTreeModificationCursor(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) Before(org.junit.Before)

Example 4 with DataTreeModificationCursor

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

the class DataTreeCandidates method applyToCursorAwareModification.

private static void applyToCursorAwareModification(final CursorAwareDataTreeModification modification, final DataTreeCandidate candidate) {
    final YangInstanceIdentifier candidatePath = candidate.getRootPath();
    final YangInstanceIdentifier parent = candidatePath.getParent();
    if (parent == null) {
        try (DataTreeModificationCursor cursor = modification.openCursor()) {
            DataTreeCandidateNodes.applyRootToCursor(cursor, candidate.getRootNode());
        }
    } else {
        try (DataTreeModificationCursor cursor = modification.openCursor(parent).orElseThrow()) {
            DataTreeCandidateNodes.applyRootedNodeToCursor(cursor, candidatePath, candidate.getRootNode());
        }
    }
}
Also used : DataTreeModificationCursor(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 5 with DataTreeModificationCursor

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

the class DataTreeCandidateNodesTest method testApplyRootToCursorWithUnsupportedModificationType.

@Test
public void testApplyRootToCursorWithUnsupportedModificationType() {
    final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
    final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
    doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).getModificationType();
    final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> DataTreeCandidateNodes.applyRootToCursor(mockedCursor, mockedDataTreeCandidateNode));
    assertThat(ex.getMessage(), containsString("Unsupported modification"));
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) DataTreeModificationCursor(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor) Test(org.junit.Test)

Aggregations

DataTreeModificationCursor (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor)18 Test (org.junit.Test)13 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)13 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)6 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)3 Benchmark (org.openjdk.jmh.annotations.Benchmark)3 Measurement (org.openjdk.jmh.annotations.Measurement)3 Warmup (org.openjdk.jmh.annotations.Warmup)3 Before (org.junit.Before)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory)1