import com.google.common.collect.Streams;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification;
import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
-import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor;
import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
import org.openjdk.jmh.annotations.Benchmark;
private static final NodeIdentifierWithPredicates[] OUTER_LIST_IDS = Streams.mapWithIndex(
IntStream.range(0, OUTER_LIST_100K),
(i, index) -> NodeIdentifierWithPredicates.of(BenchmarkModel.OUTER_LIST_QNAME, BenchmarkModel.ID_QNAME, i))
- .collect(Collectors.toList()).toArray(new NodeIdentifierWithPredicates[0]);
+ .toArray(NodeIdentifierWithPredicates[]::new);
private static final YangInstanceIdentifier[] OUTER_LIST_PATHS = Arrays.stream(OUTER_LIST_IDS)
.map(id -> BenchmarkModel.OUTER_LIST_PATH.node(id).toOptimized())
- .collect(Collectors.toList()).toArray(new YangInstanceIdentifier[0]);
+ .toArray(YangInstanceIdentifier[]::new);
- private static final MapNode EMPTY_OUTER_LIST = ImmutableNodes.mapNodeBuilder(BenchmarkModel.OUTER_LIST).build();
+ private static final MapNode EMPTY_OUTER_LIST = ImmutableNodes.newSystemMapBuilder()
+ .withNodeIdentifier(BenchmarkModel.OUTER_LIST)
+ .build();
private static final MapNode ONE_ITEM_INNER_LIST = initInnerListItems(1);
private static final MapNode TWO_ITEM_INNER_LIST = initInnerListItems(2);
private static final MapNode TEN_ITEM_INNER_LIST = initInnerListItems(10);
private static MapNode initInnerListItems(final int count) {
- final var mapEntryBuilder = ImmutableNodes.mapNodeBuilder(BenchmarkModel.INNER_LIST);
+ final var mapEntryBuilder = ImmutableNodes.newSystemMapBuilder()
+ .withNodeIdentifier(BenchmarkModel.INNER_LIST);
for (int i = 0; i < count; ++i) {
- mapEntryBuilder
- .withChild(ImmutableNodes.mapEntry(BenchmarkModel.INNER_LIST_QNAME, BenchmarkModel.NAME_QNAME, i));
+ mapEntryBuilder.withChild(ImmutableNodes.newMapEntryBuilder()
+ .withNodeIdentifier(
+ NodeIdentifierWithPredicates.of(BenchmarkModel.INNER_LIST_QNAME, BenchmarkModel.NAME_QNAME, i))
+ .withChild(ImmutableNodes.leafNode(BenchmarkModel.NAME_QNAME, i))
+ .build());
}
return mapEntryBuilder.build();
private static MapEntryNode[] initOuterListItems(final int outerListItemsCount, final MapNode innerList) {
return Arrays.stream(OUTER_LIST_IDS)
.limit(outerListItemsCount)
- .map(id -> ImmutableNodes.mapEntryBuilder().withNodeIdentifier(id).withChild(innerList).build())
+ .map(id -> ImmutableNodes.newMapEntryBuilder().withNodeIdentifier(id).withChild(innerList).build())
.toArray(MapEntryNode[]::new);
}
BenchmarkModel.createTestContext());
final DataTreeModification modification = begin();
- modification.write(BenchmarkModel.TEST_PATH, Builders.containerBuilder()
+ modification.write(BenchmarkModel.TEST_PATH, ImmutableNodes.newContainerBuilder()
.withNodeIdentifier(BenchmarkModel.TEST)
.withChild(EMPTY_OUTER_LIST)
.build());
@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()) {
+ try (var cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).orElseThrow()) {
for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
}
@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()) {
+ try (var cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).orElseThrow()) {
for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
}
@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()) {
+ try (var cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).orElseThrow()) {
for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
}