2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.sharding;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.mockito.ArgumentMatchers.anyCollection;
15 import static org.mockito.ArgumentMatchers.anyMap;
16 import static org.mockito.Mockito.doNothing;
17 import static org.mockito.Mockito.doReturn;
18 import static org.mockito.Mockito.mock;
19 import static org.mockito.Mockito.timeout;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.verifyNoMoreInteractions;
22 import static org.opendaylight.controller.cluster.datastore.IntegrationTestKit.findLocalShard;
23 import static org.opendaylight.controller.cluster.datastore.IntegrationTestKit.waitUntilShardIsDown;
25 import akka.actor.ActorRef;
26 import akka.actor.ActorSystem;
27 import akka.actor.Address;
28 import akka.actor.AddressFromURIString;
29 import akka.actor.Props;
30 import akka.cluster.Cluster;
31 import akka.testkit.javadsl.TestKit;
32 import com.google.common.collect.Lists;
33 import com.google.common.util.concurrent.FluentFuture;
34 import com.google.common.util.concurrent.ListenableFuture;
35 import com.typesafe.config.ConfigFactory;
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.Collections;
39 import java.util.List;
41 import java.util.Optional;
43 import java.util.concurrent.CompletionStage;
44 import java.util.concurrent.TimeUnit;
45 import org.junit.After;
46 import org.junit.Assert;
47 import org.junit.Before;
48 import org.junit.Ignore;
49 import org.junit.Test;
50 import org.mockito.ArgumentCaptor;
51 import org.mockito.Captor;
52 import org.mockito.Mockito;
53 import org.mockito.MockitoAnnotations;
54 import org.opendaylight.controller.cluster.ActorSystemProvider;
55 import org.opendaylight.controller.cluster.access.concepts.MemberName;
56 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory;
57 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
58 import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
59 import org.opendaylight.controller.cluster.databroker.actors.dds.SimpleDataStoreClientActor;
60 import org.opendaylight.controller.cluster.datastore.AbstractTest;
61 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
62 import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder;
63 import org.opendaylight.controller.cluster.datastore.DistributedDataStore;
64 import org.opendaylight.controller.cluster.datastore.IntegrationTestKit;
65 import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
66 import org.opendaylight.controller.cluster.datastore.utils.ClusterUtils;
67 import org.opendaylight.controller.cluster.dom.api.CDSDataTreeProducer;
68 import org.opendaylight.controller.cluster.dom.api.CDSShardAccess;
69 import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal;
70 import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore;
71 import org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration;
72 import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper;
73 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
74 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
75 import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction;
76 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
77 import org.opendaylight.mdsal.dom.api.DOMDataTreeListener;
78 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
79 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
80 import org.opendaylight.yangtools.yang.common.QName;
81 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
82 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
83 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
84 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
85 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
86 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
87 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
88 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
89 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
90 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
91 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
92 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
93 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
94 import org.slf4j.Logger;
95 import org.slf4j.LoggerFactory;
97 public class DistributedShardedDOMDataTreeTest extends AbstractTest {
99 private static final Logger LOG = LoggerFactory.getLogger(DistributedShardedDOMDataTreeRemotingTest.class);
101 private static final Address MEMBER_1_ADDRESS =
102 AddressFromURIString.parse("akka.tcp://cluster-test@127.0.0.1:2558");
104 private static final DOMDataTreeIdentifier TEST_ID =
105 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
107 private static final DOMDataTreeIdentifier INNER_LIST_ID =
108 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
109 YangInstanceIdentifier.create(getOuterListIdFor(0).getPathArguments())
110 .node(TestModel.INNER_LIST_QNAME));
111 private static final Set<MemberName> SINGLE_MEMBER = Collections.singleton(AbstractTest.MEMBER_NAME);
113 private static final String MODULE_SHARDS_CONFIG = "module-shards-default-member-1.conf";
115 private ActorSystem leaderSystem;
117 private final Builder leaderDatastoreContextBuilder =
118 DatastoreContext.newBuilder()
119 .shardHeartbeatIntervalInMillis(100)
120 .shardElectionTimeoutFactor(2)
121 .logicalStoreType(LogicalDatastoreType.CONFIGURATION);
123 private DistributedDataStore leaderDistributedDataStore;
124 private DistributedDataStore operDistributedDatastore;
125 private IntegrationTestKit leaderTestKit;
127 private DistributedShardedDOMDataTree leaderShardFactory;
130 private ArgumentCaptor<Collection<DataTreeCandidate>> captorForChanges;
132 private ArgumentCaptor<Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>>> captorForSubtrees;
134 private ActorSystemProvider leaderSystemProvider;
137 public void setUp() {
138 MockitoAnnotations.initMocks(this);
140 InMemoryJournal.clear();
141 InMemorySnapshotStore.clear();
143 leaderSystem = ActorSystem.create("cluster-test", ConfigFactory.load().getConfig("Member1"));
144 Cluster.get(leaderSystem).join(MEMBER_1_ADDRESS);
146 leaderSystemProvider = Mockito.mock(ActorSystemProvider.class);
147 doReturn(leaderSystem).when(leaderSystemProvider).getActorSystem();
151 public void tearDown() {
152 if (leaderDistributedDataStore != null) {
153 leaderDistributedDataStore.close();
156 if (operDistributedDatastore != null) {
157 operDistributedDatastore.close();
160 TestKit.shutdownActorSystem(leaderSystem);
162 InMemoryJournal.clear();
163 InMemorySnapshotStore.clear();
166 private void initEmptyDatastores() throws Exception {
167 leaderTestKit = new IntegrationTestKit(leaderSystem, leaderDatastoreContextBuilder);
169 leaderDistributedDataStore = leaderTestKit.setupDistributedDataStore(
170 "config", MODULE_SHARDS_CONFIG, "empty-modules.conf", true,
171 SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext());
173 operDistributedDatastore = leaderTestKit.setupDistributedDataStore(
174 "operational", MODULE_SHARDS_CONFIG, "empty-modules.conf",true,
175 SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext());
177 leaderShardFactory = new DistributedShardedDOMDataTree(leaderSystemProvider,
178 operDistributedDatastore,
179 leaderDistributedDataStore);
181 leaderShardFactory.init();
186 public void testWritesIntoDefaultShard() throws Exception {
187 initEmptyDatastores();
189 final DOMDataTreeIdentifier configRoot =
190 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
192 final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot));
194 final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(true);
195 final DOMDataTreeWriteCursor cursor =
196 tx.createCursor(new DOMDataTreeIdentifier(
197 LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY));
198 Assert.assertNotNull(cursor);
200 final ContainerNode test =
201 ImmutableContainerNodeBuilder.create()
202 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).build();
204 cursor.write(test.getIdentifier(), test);
211 public void testSingleNodeWritesAndRead() throws Exception {
212 initEmptyDatastores();
214 final DistributedShardRegistration shardRegistration = waitOnAsyncTask(
215 leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
216 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
218 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorUtils(),
219 ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
221 final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
223 final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(true);
224 final DOMDataTreeWriteCursor cursor = tx.createCursor(TEST_ID);
225 Assert.assertNotNull(cursor);
226 final YangInstanceIdentifier nameId =
227 YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(TestModel.NAME_QNAME).build();
228 final LeafNode<String> valueToCheck = ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(
229 new NodeIdentifier(TestModel.NAME_QNAME)).withValue("Test Value").build();
230 LOG.debug("Writing data {} at {}, cursor {}", nameId.getLastPathArgument(), valueToCheck, cursor);
231 cursor.write(nameId.getLastPathArgument(),
235 LOG.debug("Got to pre submit");
239 final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
240 doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
242 leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID),
243 true, Collections.emptyList());
245 verify(mockedDataTreeListener, timeout(1000).times(1)).onDataTreeChanged(captorForChanges.capture(),
246 captorForSubtrees.capture());
247 final List<Collection<DataTreeCandidate>> capturedValue = captorForChanges.getAllValues();
249 final Optional<NormalizedNode<?, ?>> dataAfter =
250 capturedValue.get(0).iterator().next().getRootNode().getDataAfter();
252 final NormalizedNode<?,?> expected = ImmutableContainerNodeBuilder.create()
253 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(valueToCheck).build();
254 assertEquals(expected, dataAfter.get());
256 verifyNoMoreInteractions(mockedDataTreeListener);
258 final String shardName = ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier());
259 LOG.debug("Creating distributed datastore client for shard {}", shardName);
261 final ActorUtils actorUtils = leaderDistributedDataStore.getActorUtils();
262 final Props distributedDataStoreClientProps =
263 SimpleDataStoreClientActor.props(actorUtils.getCurrentMemberName(), "Shard-" + shardName, actorUtils,
266 final ActorRef clientActor = leaderSystem.actorOf(distributedDataStoreClientProps);
267 final DataStoreClient distributedDataStoreClient = SimpleDataStoreClientActor
268 .getDistributedDataStoreClient(clientActor, 30, TimeUnit.SECONDS);
270 final ClientLocalHistory localHistory = distributedDataStoreClient.createLocalHistory();
271 final ClientTransaction tx2 = localHistory.createTransaction();
272 final FluentFuture<Optional<NormalizedNode<?, ?>>> read = tx2.read(YangInstanceIdentifier.EMPTY);
274 final Optional<NormalizedNode<?, ?>> optional = read.get();
276 localHistory.close();
278 shardRegistration.close().toCompletableFuture().get();
283 public void testMultipleWritesIntoSingleMapEntry() throws Exception {
284 initEmptyDatastores();
286 final DistributedShardRegistration shardRegistration = waitOnAsyncTask(
287 leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
288 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
290 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorUtils(),
291 ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
293 LOG.warn("Got after waiting for nonleader");
294 final ActorRef leaderShardManager = leaderDistributedDataStore.getActorUtils().getShardManager();
296 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorUtils(),
297 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
299 final YangInstanceIdentifier oid1 = getOuterListIdFor(0);
300 final DOMDataTreeIdentifier outerListPath = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1);
302 final DistributedShardRegistration outerListShardReg = waitOnAsyncTask(
303 leaderShardFactory.createDistributedShard(outerListPath, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
304 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
306 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorUtils(),
307 ClusterUtils.getCleanShardName(outerListPath.getRootIdentifier()));
309 final DOMDataTreeProducer shardProducer = leaderShardFactory.createProducer(
310 Collections.singletonList(outerListPath));
312 final DOMDataTreeCursorAwareTransaction tx = shardProducer.createTransaction(false);
313 final DOMDataTreeWriteCursor cursor =
314 tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1));
315 assertNotNull(cursor);
317 MapNode innerList = ImmutableMapNodeBuilder
319 .withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
322 cursor.write(new NodeIdentifier(TestModel.INNER_LIST_QNAME), innerList);
326 final ArrayList<ListenableFuture<?>> futures = new ArrayList<>();
327 for (int i = 0; i < 1000; i++) {
328 final Collection<MapEntryNode> innerListMapEntries = createInnerListMapEntries(1000, "run-" + i);
329 for (final MapEntryNode innerListMapEntry : innerListMapEntries) {
330 final DOMDataTreeCursorAwareTransaction tx1 = shardProducer.createTransaction(false);
331 final DOMDataTreeWriteCursor cursor1 = tx1.createCursor(
332 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
333 oid1.node(new NodeIdentifier(TestModel.INNER_LIST_QNAME))));
334 cursor1.write(innerListMapEntry.getIdentifier(), innerListMapEntry);
336 futures.add(tx1.commit());
340 futures.get(futures.size() - 1).get();
342 final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
343 doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
345 leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_LIST_ID),
346 true, Collections.emptyList());
348 verify(mockedDataTreeListener, timeout(1000).times(1)).onDataTreeChanged(captorForChanges.capture(),
349 captorForSubtrees.capture());
350 verifyNoMoreInteractions(mockedDataTreeListener);
351 final List<Collection<DataTreeCandidate>> capturedValue = captorForChanges.getAllValues();
353 final NormalizedNode<?,?> expected =
354 ImmutableMapNodeBuilder
356 .withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
357 // only the values from the last run should be present
358 .withValue(createInnerListMapEntries(1000, "run-999"))
361 assertEquals("List values dont match the expected values from the last run",
362 expected, capturedValue.get(0).iterator().next().getRootNode().getDataAfter().get());
366 // top level shard at TEST element, with subshards on each outer-list map entry
369 public void testMultipleShardLevels() throws Exception {
370 initEmptyDatastores();
372 final DistributedShardRegistration testShardReg = waitOnAsyncTask(
373 leaderShardFactory.createDistributedShard(TEST_ID, SINGLE_MEMBER),
374 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
376 final ArrayList<DistributedShardRegistration> registrations = new ArrayList<>();
377 final int listSize = 5;
378 for (int i = 0; i < listSize; i++) {
379 final YangInstanceIdentifier entryYID = getOuterListIdFor(i);
380 final CompletionStage<DistributedShardRegistration> future = leaderShardFactory.createDistributedShard(
381 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, entryYID), SINGLE_MEMBER);
383 registrations.add(waitOnAsyncTask(future, DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION));
386 final DOMDataTreeIdentifier rootId =
387 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
388 final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singletonList(
391 DOMDataTreeCursorAwareTransaction transaction = producer.createTransaction(false);
393 DOMDataTreeWriteCursor cursor = transaction.createCursor(rootId);
394 assertNotNull(cursor);
396 final MapNode outerList =
397 ImmutableMapNodeBuilder.create()
398 .withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
400 final ContainerNode testNode =
401 ImmutableContainerNodeBuilder.create()
402 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
403 .withChild(outerList)
406 cursor.write(testNode.getIdentifier(), testNode);
409 transaction.commit().get();
411 final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
412 doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
414 final MapNode wholeList = ImmutableMapNodeBuilder.create(outerList)
415 .withValue(createOuterEntries(listSize, "testing-values")).build();
417 transaction = producer.createTransaction(false);
418 cursor = transaction.createCursor(TEST_ID);
419 assertNotNull(cursor);
421 cursor.write(wholeList.getIdentifier(), wholeList);
424 transaction.commit().get();
426 leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID),
427 true, Collections.emptyList());
429 verify(mockedDataTreeListener, timeout(35000).atLeast(2)).onDataTreeChanged(captorForChanges.capture(),
430 captorForSubtrees.capture());
431 verifyNoMoreInteractions(mockedDataTreeListener);
432 final List<Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>>> allSubtrees = captorForSubtrees.getAllValues();
434 final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> lastSubtree = allSubtrees.get(allSubtrees.size() - 1);
436 final NormalizedNode<?, ?> actual = lastSubtree.get(TEST_ID);
437 assertNotNull(actual);
439 final NormalizedNode<?, ?> expected =
440 ImmutableContainerNodeBuilder.create()
441 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
442 .withChild(ImmutableMapNodeBuilder.create(outerList)
443 .withValue(createOuterEntries(listSize, "testing-values")).build())
447 for (final DistributedShardRegistration registration : registrations) {
448 waitOnAsyncTask(registration.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
451 waitOnAsyncTask(testShardReg.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
453 assertEquals(expected, actual);
457 public void testMultipleRegistrationsAtOnePrefix() throws Exception {
458 initEmptyDatastores();
460 for (int i = 0; i < 10; i++) {
461 LOG.debug("Round {}", i);
462 final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(
463 TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
464 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
466 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorUtils(),
467 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
469 assertNotNull(findLocalShard(leaderDistributedDataStore.getActorUtils(),
470 ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
472 waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
474 waitUntilShardIsDown(leaderDistributedDataStore.getActorUtils(),
475 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
480 public void testCDSDataTreeProducer() throws Exception {
481 initEmptyDatastores();
483 final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(
484 TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
485 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
487 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorUtils(),
488 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
490 assertNotNull(findLocalShard(leaderDistributedDataStore.getActorUtils(),
491 ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
494 final DOMDataTreeIdentifier configRoot =
495 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
496 final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot));
498 assertTrue(producer instanceof CDSDataTreeProducer);
500 final CDSDataTreeProducer cdsProducer = (CDSDataTreeProducer) producer;
501 CDSShardAccess shardAccess = cdsProducer.getShardAccess(TEST_ID);
502 assertEquals(shardAccess.getShardIdentifier(), TEST_ID);
504 shardAccess = cdsProducer.getShardAccess(INNER_LIST_ID);
505 assertEquals(TEST_ID, shardAccess.getShardIdentifier());
507 shardAccess = cdsProducer.getShardAccess(configRoot);
508 assertEquals(configRoot, shardAccess.getShardIdentifier());
510 waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
513 private static Collection<MapEntryNode> createOuterEntries(final int amount, final String valuePrefix) {
514 final Collection<MapEntryNode> ret = new ArrayList<>();
515 for (int i = 0; i < amount; i++) {
516 ret.add(ImmutableNodes.mapEntryBuilder()
517 .withNodeIdentifier(NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME,
518 QName.create(TestModel.OUTER_LIST_QNAME, "id"), i))
519 .withChild(ImmutableNodes
520 .leafNode(QName.create(TestModel.OUTER_LIST_QNAME, "id"), i))
521 .withChild(createWholeInnerList(amount, "outer id: " + i + " " + valuePrefix))
528 private static MapNode createWholeInnerList(final int amount, final String valuePrefix) {
529 return ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
530 .withValue(createInnerListMapEntries(amount, valuePrefix)).build();
533 private static Collection<MapEntryNode> createInnerListMapEntries(final int amount, final String valuePrefix) {
534 final Collection<MapEntryNode> ret = new ArrayList<>();
535 for (int i = 0; i < amount; i++) {
536 ret.add(ImmutableNodes.mapEntryBuilder()
537 .withNodeIdentifier(NodeIdentifierWithPredicates.of(TestModel.INNER_LIST_QNAME,
538 QName.create(TestModel.INNER_LIST_QNAME, "name"), Integer.toString(i)))
539 .withChild(ImmutableNodes
540 .leafNode(QName.create(TestModel.INNER_LIST_QNAME, "value"), valuePrefix + "-" + i))
547 private static YangInstanceIdentifier getOuterListIdFor(final int id) {
548 return TestModel.OUTER_LIST_PATH.node(NodeIdentifierWithPredicates.of(
549 TestModel.OUTER_LIST_QNAME, QName.create(TestModel.OUTER_LIST_QNAME, "id"), id));