Search in sources :

Example 1 with CursorAwareDataTreeModification

use of org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification 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 CursorAwareDataTreeModification

use of org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification 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 CursorAwareDataTreeModification

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

the class DataTreeCandidatesTest method testApplyToCursorAwareModificationRoot.

@Test
public void testApplyToCursorAwareModificationRoot() {
    final DataTreeCandidate mockedDataTreeCandidate = mock(DataTreeCandidate.class);
    final CursorAwareDataTreeModification mockedModification = mock(CursorAwareDataTreeModification.class);
    final YangInstanceIdentifier mockedRootPath = mock(YangInstanceIdentifier.class);
    final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
    doReturn(mockedRootPath).when(mockedDataTreeCandidate).getRootPath();
    doReturn(null).when(mockedRootPath).getParent();
    doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
    doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
    IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate));
    assertEquals("Can not delete root.", thrown.getMessage());
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) CursorAwareDataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 4 with CursorAwareDataTreeModification

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

the class InMemoryDataTreeBenchmark method write50KSingleNodeWithTwoInnerItemsInOneCommitCursorBenchmark.

@Benchmark
@Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
public void write50KSingleNodeWithTwoInnerItemsInOneCommitCursorBenchmark() throws DataValidationFailedException {
    final CursorAwareDataTreeModification modification = begin();
    try (DataTreeModificationCursor cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).get()) {
        for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
            cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TWO_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 5 with CursorAwareDataTreeModification

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

the class DataTreeCandidates method applyToModification.

public static void applyToModification(final DataTreeModification modification, final DataTreeCandidate candidate) {
    if (modification instanceof CursorAwareDataTreeModification) {
        applyToCursorAwareModification((CursorAwareDataTreeModification) modification, candidate);
        return;
    }
    final DataTreeCandidateNode node = candidate.getRootNode();
    final YangInstanceIdentifier path = candidate.getRootPath();
    switch(node.getModificationType()) {
        case DELETE:
            modification.delete(path);
            LOG.debug("Modification {} deleted path {}", modification, path);
            break;
        case SUBTREE_MODIFIED:
            LOG.debug("Modification {} modified path {}", modification, path);
            NodeIterator iterator = new NodeIterator(null, path, node.getChildNodes().iterator());
            do {
                iterator = iterator.next(modification);
            } while (iterator != null);
            break;
        case UNMODIFIED:
            LOG.debug("Modification {} unmodified path {}", modification, path);
            // No-op
            break;
        case WRITE:
            modification.write(path, node.getDataAfter().get());
            LOG.debug("Modification {} written path {}", modification, path);
            break;
        default:
            throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
    }
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) CursorAwareDataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Aggregations

CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification)6 DataTreeModificationCursor (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)3 Benchmark (org.openjdk.jmh.annotations.Benchmark)3 Measurement (org.openjdk.jmh.annotations.Measurement)3 Warmup (org.openjdk.jmh.annotations.Warmup)3 Test (org.junit.Test)2 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)2