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.javadsl.TestKit;
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-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() throws Exception {
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);
207 tx.submit().checkedGet();
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.getActorContext(),
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");
237 tx.submit().checkedGet();
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 java.util.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 ActorContext actorContext = leaderDistributedDataStore.getActorContext();
262 final Props distributedDataStoreClientProps =
263 SimpleDataStoreClientActor.props(actorContext.getCurrentMemberName(),
264 "Shard-" + shardName, actorContext, shardName);
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 CheckedFuture<Optional<NormalizedNode<?, ?>>,
273 org.opendaylight.mdsal.common.api.ReadFailedException> read =
274 tx2.read(YangInstanceIdentifier.EMPTY);
276 final Optional<NormalizedNode<?, ?>> optional = read.checkedGet();
278 localHistory.close();
280 shardRegistration.close().toCompletableFuture().get();
285 public void testMultipleWritesIntoSingleMapEntry() throws Exception {
286 initEmptyDatastores();
288 final DistributedShardRegistration shardRegistration = waitOnAsyncTask(
289 leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
290 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
292 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
293 ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
295 LOG.warn("Got after waiting for nonleader");
296 final ActorRef leaderShardManager = leaderDistributedDataStore.getActorContext().getShardManager();
298 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
299 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
301 final YangInstanceIdentifier oid1 = getOuterListIdFor(0);
302 final DOMDataTreeIdentifier outerListPath = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1);
304 final DistributedShardRegistration outerListShardReg = waitOnAsyncTask(
305 leaderShardFactory.createDistributedShard(outerListPath, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
306 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
308 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
309 ClusterUtils.getCleanShardName(outerListPath.getRootIdentifier()));
311 final DOMDataTreeProducer shardProducer = leaderShardFactory.createProducer(
312 Collections.singletonList(outerListPath));
314 final DOMDataTreeCursorAwareTransaction tx = shardProducer.createTransaction(false);
315 final DOMDataTreeWriteCursor cursor =
316 tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1));
317 assertNotNull(cursor);
319 MapNode innerList = ImmutableMapNodeBuilder
321 .withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
324 cursor.write(new NodeIdentifier(TestModel.INNER_LIST_QNAME), innerList);
326 tx.submit().checkedGet();
328 final ArrayList<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
329 for (int i = 0; i < 1000; i++) {
330 final Collection<MapEntryNode> innerListMapEntries = createInnerListMapEntries(1000, "run-" + i);
331 for (final MapEntryNode innerListMapEntry : innerListMapEntries) {
332 final DOMDataTreeCursorAwareTransaction tx1 = shardProducer.createTransaction(false);
333 final DOMDataTreeWriteCursor cursor1 = tx1.createCursor(
334 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
335 oid1.node(new NodeIdentifier(TestModel.INNER_LIST_QNAME))));
336 cursor1.write(innerListMapEntry.getIdentifier(), innerListMapEntry);
338 futures.add(tx1.submit());
342 futures.get(futures.size() - 1).checkedGet();
344 final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
345 doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
347 leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_LIST_ID),
348 true, Collections.emptyList());
350 verify(mockedDataTreeListener, timeout(1000).times(1)).onDataTreeChanged(captorForChanges.capture(),
351 captorForSubtrees.capture());
352 verifyNoMoreInteractions(mockedDataTreeListener);
353 final List<Collection<DataTreeCandidate>> capturedValue = captorForChanges.getAllValues();
355 final NormalizedNode<?,?> expected =
356 ImmutableMapNodeBuilder
358 .withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
359 // only the values from the last run should be present
360 .withValue(createInnerListMapEntries(1000, "run-999"))
363 assertEquals("List values dont match the expected values from the last run",
364 expected, capturedValue.get(0).iterator().next().getRootNode().getDataAfter().get());
368 // top level shard at TEST element, with subshards on each outer-list map entry
371 public void testMultipleShardLevels() throws Exception {
372 initEmptyDatastores();
374 final DistributedShardRegistration testShardReg = waitOnAsyncTask(
375 leaderShardFactory.createDistributedShard(TEST_ID, SINGLE_MEMBER),
376 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
378 final ArrayList<DistributedShardRegistration> registrations = new ArrayList<>();
379 final int listSize = 5;
380 for (int i = 0; i < listSize; i++) {
381 final YangInstanceIdentifier entryYID = getOuterListIdFor(i);
382 final CompletionStage<DistributedShardRegistration> future = leaderShardFactory.createDistributedShard(
383 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, entryYID), SINGLE_MEMBER);
385 registrations.add(waitOnAsyncTask(future, DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION));
388 final DOMDataTreeIdentifier rootId =
389 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
390 final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singletonList(
393 DOMDataTreeCursorAwareTransaction transaction = producer.createTransaction(false);
395 DOMDataTreeWriteCursor cursor = transaction.createCursor(rootId);
396 assertNotNull(cursor);
398 final MapNode outerList =
399 ImmutableMapNodeBuilder.create()
400 .withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
402 final ContainerNode testNode =
403 ImmutableContainerNodeBuilder.create()
404 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
405 .withChild(outerList)
408 cursor.write(testNode.getIdentifier(), testNode);
411 transaction.submit().checkedGet();
413 final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
414 doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
416 final MapNode wholeList = ImmutableMapNodeBuilder.create(outerList)
417 .withValue(createOuterEntries(listSize, "testing-values")).build();
419 transaction = producer.createTransaction(false);
420 cursor = transaction.createCursor(TEST_ID);
421 assertNotNull(cursor);
423 cursor.write(wholeList.getIdentifier(), wholeList);
426 transaction.submit().checkedGet();
428 leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID),
429 true, Collections.emptyList());
431 verify(mockedDataTreeListener, timeout(35000).atLeast(2)).onDataTreeChanged(captorForChanges.capture(),
432 captorForSubtrees.capture());
433 verifyNoMoreInteractions(mockedDataTreeListener);
434 final List<Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>>> allSubtrees = captorForSubtrees.getAllValues();
436 final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> lastSubtree = allSubtrees.get(allSubtrees.size() - 1);
438 final NormalizedNode<?, ?> actual = lastSubtree.get(TEST_ID);
439 assertNotNull(actual);
441 final NormalizedNode<?, ?> expected =
442 ImmutableContainerNodeBuilder.create()
443 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
444 .withChild(ImmutableMapNodeBuilder.create(outerList)
445 .withValue(createOuterEntries(listSize, "testing-values")).build())
449 for (final DistributedShardRegistration registration : registrations) {
450 waitOnAsyncTask(registration.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
453 waitOnAsyncTask(testShardReg.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
455 assertEquals(expected, actual);
459 public void testMultipleRegistrationsAtOnePrefix() throws Exception {
460 initEmptyDatastores();
462 for (int i = 0; i < 10; i++) {
463 LOG.debug("Round {}", i);
464 final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(
465 TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
466 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
468 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
469 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
471 assertNotNull(findLocalShard(leaderDistributedDataStore.getActorContext(),
472 ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
474 waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
476 waitUntilShardIsDown(leaderDistributedDataStore.getActorContext(),
477 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
482 public void testCDSDataTreeProducer() throws Exception {
483 initEmptyDatastores();
485 final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(
486 TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
487 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
489 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
490 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
492 assertNotNull(findLocalShard(leaderDistributedDataStore.getActorContext(),
493 ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
496 final DOMDataTreeIdentifier configRoot =
497 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
498 final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot));
500 assertTrue(producer instanceof CDSDataTreeProducer);
502 final CDSDataTreeProducer cdsProducer = (CDSDataTreeProducer) producer;
503 CDSShardAccess shardAccess = cdsProducer.getShardAccess(TEST_ID);
504 assertEquals(shardAccess.getShardIdentifier(), TEST_ID);
506 shardAccess = cdsProducer.getShardAccess(INNER_LIST_ID);
507 assertEquals(TEST_ID, shardAccess.getShardIdentifier());
509 shardAccess = cdsProducer.getShardAccess(configRoot);
510 assertEquals(configRoot, shardAccess.getShardIdentifier());
512 waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
515 private static Collection<MapEntryNode> createOuterEntries(final int amount, final String valuePrefix) {
516 final Collection<MapEntryNode> ret = new ArrayList<>();
517 for (int i = 0; i < amount; i++) {
518 ret.add(ImmutableNodes.mapEntryBuilder()
519 .withNodeIdentifier(new NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME,
520 QName.create(TestModel.OUTER_LIST_QNAME, "id"), i))
521 .withChild(ImmutableNodes
522 .leafNode(QName.create(TestModel.OUTER_LIST_QNAME, "id"), i))
523 .withChild(createWholeInnerList(amount, "outer id: " + i + " " + valuePrefix))
530 private static MapNode createWholeInnerList(final int amount, final String valuePrefix) {
531 return ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
532 .withValue(createInnerListMapEntries(amount, valuePrefix)).build();
535 private static Collection<MapEntryNode> createInnerListMapEntries(final int amount, final String valuePrefix) {
536 final Collection<MapEntryNode> ret = new ArrayList<>();
537 for (int i = 0; i < amount; i++) {
538 ret.add(ImmutableNodes.mapEntryBuilder()
539 .withNodeIdentifier(new NodeIdentifierWithPredicates(TestModel.INNER_LIST_QNAME,
540 QName.create(TestModel.INNER_LIST_QNAME, "name"), Integer.toString(i)))
541 .withChild(ImmutableNodes
542 .leafNode(QName.create(TestModel.INNER_LIST_QNAME, "value"), valuePrefix + "-" + i))
549 private static YangInstanceIdentifier getOuterListIdFor(final int id) {
550 return TestModel.OUTER_LIST_PATH.node(new NodeIdentifierWithPredicates(
551 TestModel.OUTER_LIST_QNAME, QName.create(TestModel.OUTER_LIST_QNAME, "id"), id));