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.Matchers.anyCollection;
15 import static org.mockito.Matchers.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.JavaTestKit;
32 import com.google.common.base.Optional;
33 import com.google.common.collect.Lists;
34 import com.google.common.util.concurrent.CheckedFuture;
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;
42 import java.util.concurrent.CompletionStage;
43 import java.util.concurrent.TimeUnit;
44 import org.junit.After;
45 import org.junit.Assert;
46 import org.junit.Before;
47 import org.junit.Ignore;
48 import org.junit.Test;
49 import org.mockito.ArgumentCaptor;
50 import org.mockito.Captor;
51 import org.mockito.Mockito;
52 import org.mockito.MockitoAnnotations;
53 import org.opendaylight.controller.cluster.ActorSystemProvider;
54 import org.opendaylight.controller.cluster.access.concepts.MemberName;
55 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory;
56 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
57 import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
58 import org.opendaylight.controller.cluster.databroker.actors.dds.SimpleDataStoreClientActor;
59 import org.opendaylight.controller.cluster.datastore.AbstractTest;
60 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
61 import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder;
62 import org.opendaylight.controller.cluster.datastore.DistributedDataStore;
63 import org.opendaylight.controller.cluster.datastore.IntegrationTestKit;
64 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
65 import org.opendaylight.controller.cluster.datastore.utils.ClusterUtils;
66 import org.opendaylight.controller.cluster.dom.api.CDSDataTreeProducer;
67 import org.opendaylight.controller.cluster.dom.api.CDSShardAccess;
68 import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal;
69 import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore;
70 import org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration;
71 import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper;
72 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
73 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
74 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
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-cars-member-1.conf";
115 private ActorSystem leaderSystem;
117 private final Builder leaderDatastoreContextBuilder =
118 DatastoreContext.newBuilder()
119 .shardHeartbeatIntervalInMillis(100)
120 .shardElectionTimeoutFactor(2)
122 org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION);
124 private DistributedDataStore leaderDistributedDataStore;
125 private DistributedDataStore operDistributedDatastore;
126 private IntegrationTestKit leaderTestKit;
128 private DistributedShardedDOMDataTree leaderShardFactory;
131 private ArgumentCaptor<Collection<DataTreeCandidate>> captorForChanges;
133 private ArgumentCaptor<Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>>> captorForSubtrees;
135 private ActorSystemProvider leaderSystemProvider;
138 public void setUp() {
139 MockitoAnnotations.initMocks(this);
141 InMemoryJournal.clear();
142 InMemorySnapshotStore.clear();
144 leaderSystem = ActorSystem.create("cluster-test", ConfigFactory.load().getConfig("Member1"));
145 Cluster.get(leaderSystem).join(MEMBER_1_ADDRESS);
147 leaderSystemProvider = Mockito.mock(ActorSystemProvider.class);
148 doReturn(leaderSystem).when(leaderSystemProvider).getActorSystem();
152 public void tearDown() throws Exception {
153 if (leaderDistributedDataStore != null) {
154 leaderDistributedDataStore.close();
157 if (operDistributedDatastore != null) {
158 operDistributedDatastore.close();
161 JavaTestKit.shutdownActorSystem(leaderSystem);
163 InMemoryJournal.clear();
164 InMemorySnapshotStore.clear();
167 private void initEmptyDatastores() throws Exception {
168 leaderTestKit = new IntegrationTestKit(leaderSystem, leaderDatastoreContextBuilder);
170 leaderDistributedDataStore = leaderTestKit.setupDistributedDataStore(
171 "config", MODULE_SHARDS_CONFIG, "empty-modules.conf", true,
172 SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext());
174 operDistributedDatastore = leaderTestKit.setupDistributedDataStore(
175 "operational", MODULE_SHARDS_CONFIG, "empty-modules.conf",true,
176 SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext());
178 leaderShardFactory = new DistributedShardedDOMDataTree(leaderSystemProvider,
179 operDistributedDatastore,
180 leaderDistributedDataStore);
182 leaderShardFactory.init();
187 public void testWritesIntoDefaultShard() throws Exception {
188 initEmptyDatastores();
190 final DOMDataTreeIdentifier configRoot =
191 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
193 final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot));
195 final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(true);
196 final DOMDataTreeWriteCursor cursor =
197 tx.createCursor(new DOMDataTreeIdentifier(
198 LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY));
199 Assert.assertNotNull(cursor);
201 final ContainerNode test =
202 ImmutableContainerNodeBuilder.create()
203 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).build();
205 cursor.write(test.getIdentifier(), test);
208 tx.submit().checkedGet();
212 public void testSingleNodeWritesAndRead() throws Exception {
213 initEmptyDatastores();
215 final DistributedShardRegistration shardRegistration = waitOnAsyncTask(
216 leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
217 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
219 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
220 ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
222 final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
224 final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(true);
225 final DOMDataTreeWriteCursor cursor = tx.createCursor(TEST_ID);
226 Assert.assertNotNull(cursor);
227 final YangInstanceIdentifier nameId =
228 YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(TestModel.NAME_QNAME).build();
229 final LeafNode<String> valueToCheck = ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(
230 new NodeIdentifier(TestModel.NAME_QNAME)).withValue("Test Value").build();
231 LOG.debug("Writing data {} at {}, cursor {}", nameId.getLastPathArgument(), valueToCheck, cursor);
232 cursor.write(nameId.getLastPathArgument(),
236 LOG.debug("Got to pre submit");
238 tx.submit().checkedGet();
240 final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
241 doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
243 leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID),
244 true, Collections.emptyList());
246 verify(mockedDataTreeListener, timeout(1000).times(1)).onDataTreeChanged(captorForChanges.capture(),
247 captorForSubtrees.capture());
248 final List<Collection<DataTreeCandidate>> capturedValue = captorForChanges.getAllValues();
250 final Optional<NormalizedNode<?, ?>> dataAfter =
251 capturedValue.get(0).iterator().next().getRootNode().getDataAfter();
253 final NormalizedNode<?,?> expected = ImmutableContainerNodeBuilder.create()
254 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(valueToCheck).build();
255 assertEquals(expected, dataAfter.get());
257 verifyNoMoreInteractions(mockedDataTreeListener);
259 final String shardName = ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier());
260 LOG.debug("Creating distributed datastore client for shard {}", shardName);
262 final ActorContext actorContext = leaderDistributedDataStore.getActorContext();
263 final Props distributedDataStoreClientProps =
264 SimpleDataStoreClientActor.props(actorContext.getCurrentMemberName(),
265 "Shard-" + shardName, actorContext, shardName);
267 final ActorRef clientActor = leaderSystem.actorOf(distributedDataStoreClientProps);
268 final DataStoreClient distributedDataStoreClient = SimpleDataStoreClientActor
269 .getDistributedDataStoreClient(clientActor, 30, TimeUnit.SECONDS);
271 final ClientLocalHistory localHistory = distributedDataStoreClient.createLocalHistory();
272 final ClientTransaction tx2 = localHistory.createTransaction();
273 final CheckedFuture<Optional<NormalizedNode<?, ?>>,
274 org.opendaylight.mdsal.common.api.ReadFailedException> read =
275 tx2.read(YangInstanceIdentifier.EMPTY);
277 final Optional<NormalizedNode<?, ?>> optional = read.checkedGet();
279 localHistory.close();
281 shardRegistration.close().toCompletableFuture().get();
286 public void testMultipleWritesIntoSingleMapEntry() throws Exception {
287 initEmptyDatastores();
289 final DistributedShardRegistration shardRegistration = waitOnAsyncTask(
290 leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
291 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
293 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
294 ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
296 LOG.warn("Got after waiting for nonleader");
297 final ActorRef leaderShardManager = leaderDistributedDataStore.getActorContext().getShardManager();
299 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
300 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
302 final YangInstanceIdentifier oid1 = getOuterListIdFor(0);
303 final DOMDataTreeIdentifier outerListPath = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1);
305 final DistributedShardRegistration outerListShardReg = waitOnAsyncTask(
306 leaderShardFactory.createDistributedShard(outerListPath, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
307 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
309 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
310 ClusterUtils.getCleanShardName(outerListPath.getRootIdentifier()));
312 final DOMDataTreeProducer shardProducer = leaderShardFactory.createProducer(
313 Collections.singletonList(outerListPath));
315 final DOMDataTreeCursorAwareTransaction tx = shardProducer.createTransaction(false);
316 final DOMDataTreeWriteCursor cursor =
317 tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1));
318 assertNotNull(cursor);
320 MapNode innerList = ImmutableMapNodeBuilder
322 .withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
325 cursor.write(new NodeIdentifier(TestModel.INNER_LIST_QNAME), innerList);
327 tx.submit().checkedGet();
329 final ArrayList<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
330 for (int i = 0; i < 1000; i++) {
331 final Collection<MapEntryNode> innerListMapEntries = createInnerListMapEntries(1000, "run-" + i);
332 for (final MapEntryNode innerListMapEntry : innerListMapEntries) {
333 final DOMDataTreeCursorAwareTransaction tx1 = shardProducer.createTransaction(false);
334 final DOMDataTreeWriteCursor cursor1 = tx1.createCursor(
335 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
336 oid1.node(new NodeIdentifier(TestModel.INNER_LIST_QNAME))));
337 cursor1.write(innerListMapEntry.getIdentifier(), innerListMapEntry);
339 futures.add(tx1.submit());
343 futures.get(futures.size() - 1).checkedGet();
345 final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
346 doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
348 leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_LIST_ID),
349 true, Collections.emptyList());
351 verify(mockedDataTreeListener, timeout(1000).times(1)).onDataTreeChanged(captorForChanges.capture(),
352 captorForSubtrees.capture());
353 verifyNoMoreInteractions(mockedDataTreeListener);
354 final List<Collection<DataTreeCandidate>> capturedValue = captorForChanges.getAllValues();
356 final NormalizedNode<?,?> expected =
357 ImmutableMapNodeBuilder
359 .withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
360 // only the values from the last run should be present
361 .withValue(createInnerListMapEntries(1000, "run-999"))
364 assertEquals("List values dont match the expected values from the last run",
365 expected, capturedValue.get(0).iterator().next().getRootNode().getDataAfter().get());
369 // top level shard at TEST element, with subshards on each outer-list map entry
372 public void testMultipleShardLevels() throws Exception {
373 initEmptyDatastores();
375 final DistributedShardRegistration testShardReg = waitOnAsyncTask(
376 leaderShardFactory.createDistributedShard(TEST_ID, SINGLE_MEMBER),
377 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
379 final ArrayList<DistributedShardRegistration> registrations = new ArrayList<>();
380 final int listSize = 5;
381 for (int i = 0; i < listSize; i++) {
382 final YangInstanceIdentifier entryYID = getOuterListIdFor(i);
383 final CompletionStage<DistributedShardRegistration> future = leaderShardFactory.createDistributedShard(
384 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, entryYID), SINGLE_MEMBER);
386 registrations.add(waitOnAsyncTask(future, DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION));
389 final DOMDataTreeIdentifier rootId =
390 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
391 final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singletonList(
394 DOMDataTreeCursorAwareTransaction transaction = producer.createTransaction(false);
396 DOMDataTreeWriteCursor cursor = transaction.createCursor(rootId);
397 assertNotNull(cursor);
399 final MapNode outerList =
400 ImmutableMapNodeBuilder.create()
401 .withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
403 final ContainerNode testNode =
404 ImmutableContainerNodeBuilder.create()
405 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
406 .withChild(outerList)
409 cursor.write(testNode.getIdentifier(), testNode);
412 transaction.submit().checkedGet();
414 final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
415 doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
417 final MapNode wholeList = ImmutableMapNodeBuilder.create(outerList)
418 .withValue(createOuterEntries(listSize, "testing-values")).build();
420 transaction = producer.createTransaction(false);
421 cursor = transaction.createCursor(TEST_ID);
422 assertNotNull(cursor);
424 cursor.write(wholeList.getIdentifier(), wholeList);
427 transaction.submit().checkedGet();
429 leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID),
430 true, Collections.emptyList());
432 verify(mockedDataTreeListener, timeout(35000).atLeast(2)).onDataTreeChanged(captorForChanges.capture(),
433 captorForSubtrees.capture());
434 verifyNoMoreInteractions(mockedDataTreeListener);
435 final List<Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>>> allSubtrees = captorForSubtrees.getAllValues();
437 final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> lastSubtree = allSubtrees.get(allSubtrees.size() - 1);
439 final NormalizedNode<?, ?> actual = lastSubtree.get(TEST_ID);
440 assertNotNull(actual);
442 final NormalizedNode<?, ?> expected =
443 ImmutableContainerNodeBuilder.create()
444 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
445 .withChild(ImmutableMapNodeBuilder.create(outerList)
446 .withValue(createOuterEntries(listSize, "testing-values")).build())
450 for (final DistributedShardRegistration registration : registrations) {
451 waitOnAsyncTask(registration.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
454 waitOnAsyncTask(testShardReg.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
456 assertEquals(expected, actual);
460 public void testMultipleRegistrationsAtOnePrefix() throws Exception {
461 initEmptyDatastores();
463 for (int i = 0; i < 10; i++) {
464 LOG.debug("Round {}", i);
465 final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(
466 TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
467 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
469 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
470 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
472 assertNotNull(findLocalShard(leaderDistributedDataStore.getActorContext(),
473 ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
475 waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
477 waitUntilShardIsDown(leaderDistributedDataStore.getActorContext(),
478 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
483 public void testCDSDataTreeProducer() throws Exception {
484 initEmptyDatastores();
486 final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(
487 TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
488 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
490 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
491 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
493 assertNotNull(findLocalShard(leaderDistributedDataStore.getActorContext(),
494 ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
497 final DOMDataTreeIdentifier configRoot =
498 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
499 final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot));
501 assertTrue(producer instanceof CDSDataTreeProducer);
503 final CDSDataTreeProducer cdsProducer = (CDSDataTreeProducer) producer;
504 CDSShardAccess shardAccess = cdsProducer.getShardAccess(TEST_ID);
505 assertEquals(shardAccess.getShardIdentifier(), TEST_ID);
507 shardAccess = cdsProducer.getShardAccess(INNER_LIST_ID);
508 assertEquals(TEST_ID, shardAccess.getShardIdentifier());
510 shardAccess = cdsProducer.getShardAccess(configRoot);
511 assertEquals(configRoot, shardAccess.getShardIdentifier());
513 waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
516 private static Collection<MapEntryNode> createOuterEntries(final int amount, final String valuePrefix) {
517 final Collection<MapEntryNode> ret = new ArrayList<>();
518 for (int i = 0; i < amount; i++) {
519 ret.add(ImmutableNodes.mapEntryBuilder()
520 .withNodeIdentifier(new NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME,
521 QName.create(TestModel.OUTER_LIST_QNAME, "id"), i))
522 .withChild(ImmutableNodes
523 .leafNode(QName.create(TestModel.OUTER_LIST_QNAME, "id"), i))
524 .withChild(createWholeInnerList(amount, "outer id: " + i + " " + valuePrefix))
531 private static MapNode createWholeInnerList(final int amount, final String valuePrefix) {
532 return ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
533 .withValue(createInnerListMapEntries(amount, valuePrefix)).build();
536 private static Collection<MapEntryNode> createInnerListMapEntries(final int amount, final String valuePrefix) {
537 final Collection<MapEntryNode> ret = new ArrayList<>();
538 for (int i = 0; i < amount; i++) {
539 ret.add(ImmutableNodes.mapEntryBuilder()
540 .withNodeIdentifier(new NodeIdentifierWithPredicates(TestModel.INNER_LIST_QNAME,
541 QName.create(TestModel.INNER_LIST_QNAME, "name"), Integer.toString(i)))
542 .withChild(ImmutableNodes
543 .leafNode(QName.create(TestModel.INNER_LIST_QNAME, "value"), valuePrefix + "-" + i))
550 private static YangInstanceIdentifier getOuterListIdFor(final int id) {
551 return TestModel.OUTER_LIST_PATH.node(new NodeIdentifierWithPredicates(
552 TestModel.OUTER_LIST_QNAME, QName.create(TestModel.OUTER_LIST_QNAME, "id"), id));