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);
}
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);
}
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());
}
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);
}
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());
}
}
Aggregations