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