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.collect.Lists;
33 import com.google.common.util.concurrent.CheckedFuture;
34 import com.google.common.util.concurrent.FluentFuture;
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.ActorContext;
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.common.api.TransactionCommitFailedException;
76 import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction;
77 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
78 import org.opendaylight.mdsal.dom.api.DOMDataTreeListener;
79 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
80 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
81 import org.opendaylight.yangtools.yang.common.QName;
82 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
83 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
84 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
85 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
86 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
87 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
88 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
89 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
90 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
91 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
92 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
93 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
94 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
95 import org.slf4j.Logger;
96 import org.slf4j.LoggerFactory;
98 public class DistributedShardedDOMDataTreeTest extends AbstractTest {
100 private static final Logger LOG = LoggerFactory.getLogger(DistributedShardedDOMDataTreeRemotingTest.class);
102 private static final Address MEMBER_1_ADDRESS =
103 AddressFromURIString.parse("akka.tcp://cluster-test@127.0.0.1:2558");
105 private static final DOMDataTreeIdentifier TEST_ID =
106 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
108 private static final DOMDataTreeIdentifier INNER_LIST_ID =
109 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
110 YangInstanceIdentifier.create(getOuterListIdFor(0).getPathArguments())
111 .node(TestModel.INNER_LIST_QNAME));
112 private static final Set<MemberName> SINGLE_MEMBER = Collections.singleton(AbstractTest.MEMBER_NAME);
114 private static final String MODULE_SHARDS_CONFIG = "module-shards-default-member-1.conf";
116 private ActorSystem leaderSystem;
118 private final Builder leaderDatastoreContextBuilder =
119 DatastoreContext.newBuilder()
120 .shardHeartbeatIntervalInMillis(100)
121 .shardElectionTimeoutFactor(2)
122 .logicalStoreType(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 TestKit.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 java.util.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 FluentFuture<Optional<NormalizedNode<?, ?>>> read = tx2.read(YangInstanceIdentifier.EMPTY);
275 final Optional<NormalizedNode<?, ?>> optional = read.get();
277 localHistory.close();
279 shardRegistration.close().toCompletableFuture().get();
284 public void testMultipleWritesIntoSingleMapEntry() throws Exception {
285 initEmptyDatastores();
287 final DistributedShardRegistration shardRegistration = waitOnAsyncTask(
288 leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
289 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
291 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
292 ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
294 LOG.warn("Got after waiting for nonleader");
295 final ActorRef leaderShardManager = leaderDistributedDataStore.getActorContext().getShardManager();
297 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
298 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
300 final YangInstanceIdentifier oid1 = getOuterListIdFor(0);
301 final DOMDataTreeIdentifier outerListPath = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1);
303 final DistributedShardRegistration outerListShardReg = waitOnAsyncTask(
304 leaderShardFactory.createDistributedShard(outerListPath, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
305 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
307 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
308 ClusterUtils.getCleanShardName(outerListPath.getRootIdentifier()));
310 final DOMDataTreeProducer shardProducer = leaderShardFactory.createProducer(
311 Collections.singletonList(outerListPath));
313 final DOMDataTreeCursorAwareTransaction tx = shardProducer.createTransaction(false);
314 final DOMDataTreeWriteCursor cursor =
315 tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1));
316 assertNotNull(cursor);
318 MapNode innerList = ImmutableMapNodeBuilder
320 .withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
323 cursor.write(new NodeIdentifier(TestModel.INNER_LIST_QNAME), innerList);
325 tx.submit().checkedGet();
327 final ArrayList<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
328 for (int i = 0; i < 1000; i++) {
329 final Collection<MapEntryNode> innerListMapEntries = createInnerListMapEntries(1000, "run-" + i);
330 for (final MapEntryNode innerListMapEntry : innerListMapEntries) {
331 final DOMDataTreeCursorAwareTransaction tx1 = shardProducer.createTransaction(false);
332 final DOMDataTreeWriteCursor cursor1 = tx1.createCursor(
333 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
334 oid1.node(new NodeIdentifier(TestModel.INNER_LIST_QNAME))));
335 cursor1.write(innerListMapEntry.getIdentifier(), innerListMapEntry);
337 futures.add(tx1.submit());
341 futures.get(futures.size() - 1).checkedGet();
343 final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
344 doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
346 leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_LIST_ID),
347 true, Collections.emptyList());
349 verify(mockedDataTreeListener, timeout(1000).times(1)).onDataTreeChanged(captorForChanges.capture(),
350 captorForSubtrees.capture());
351 verifyNoMoreInteractions(mockedDataTreeListener);
352 final List<Collection<DataTreeCandidate>> capturedValue = captorForChanges.getAllValues();
354 final NormalizedNode<?,?> expected =
355 ImmutableMapNodeBuilder
357 .withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
358 // only the values from the last run should be present
359 .withValue(createInnerListMapEntries(1000, "run-999"))
362 assertEquals("List values dont match the expected values from the last run",
363 expected, capturedValue.get(0).iterator().next().getRootNode().getDataAfter().get());
367 // top level shard at TEST element, with subshards on each outer-list map entry
370 public void testMultipleShardLevels() throws Exception {
371 initEmptyDatastores();
373 final DistributedShardRegistration testShardReg = waitOnAsyncTask(
374 leaderShardFactory.createDistributedShard(TEST_ID, SINGLE_MEMBER),
375 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
377 final ArrayList<DistributedShardRegistration> registrations = new ArrayList<>();
378 final int listSize = 5;
379 for (int i = 0; i < listSize; i++) {
380 final YangInstanceIdentifier entryYID = getOuterListIdFor(i);
381 final CompletionStage<DistributedShardRegistration> future = leaderShardFactory.createDistributedShard(
382 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, entryYID), SINGLE_MEMBER);
384 registrations.add(waitOnAsyncTask(future, DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION));
387 final DOMDataTreeIdentifier rootId =
388 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
389 final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singletonList(
392 DOMDataTreeCursorAwareTransaction transaction = producer.createTransaction(false);
394 DOMDataTreeWriteCursor cursor = transaction.createCursor(rootId);
395 assertNotNull(cursor);
397 final MapNode outerList =
398 ImmutableMapNodeBuilder.create()
399 .withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
401 final ContainerNode testNode =
402 ImmutableContainerNodeBuilder.create()
403 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
404 .withChild(outerList)
407 cursor.write(testNode.getIdentifier(), testNode);
410 transaction.submit().checkedGet();
412 final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
413 doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
415 final MapNode wholeList = ImmutableMapNodeBuilder.create(outerList)
416 .withValue(createOuterEntries(listSize, "testing-values")).build();
418 transaction = producer.createTransaction(false);
419 cursor = transaction.createCursor(TEST_ID);
420 assertNotNull(cursor);
422 cursor.write(wholeList.getIdentifier(), wholeList);
425 transaction.submit().checkedGet();
427 leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID),
428 true, Collections.emptyList());
430 verify(mockedDataTreeListener, timeout(35000).atLeast(2)).onDataTreeChanged(captorForChanges.capture(),
431 captorForSubtrees.capture());
432 verifyNoMoreInteractions(mockedDataTreeListener);
433 final List<Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>>> allSubtrees = captorForSubtrees.getAllValues();
435 final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> lastSubtree = allSubtrees.get(allSubtrees.size() - 1);
437 final NormalizedNode<?, ?> actual = lastSubtree.get(TEST_ID);
438 assertNotNull(actual);
440 final NormalizedNode<?, ?> expected =
441 ImmutableContainerNodeBuilder.create()
442 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
443 .withChild(ImmutableMapNodeBuilder.create(outerList)
444 .withValue(createOuterEntries(listSize, "testing-values")).build())
448 for (final DistributedShardRegistration registration : registrations) {
449 waitOnAsyncTask(registration.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
452 waitOnAsyncTask(testShardReg.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
454 assertEquals(expected, actual);
458 public void testMultipleRegistrationsAtOnePrefix() throws Exception {
459 initEmptyDatastores();
461 for (int i = 0; i < 10; i++) {
462 LOG.debug("Round {}", i);
463 final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(
464 TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
465 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
467 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
468 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
470 assertNotNull(findLocalShard(leaderDistributedDataStore.getActorContext(),
471 ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
473 waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
475 waitUntilShardIsDown(leaderDistributedDataStore.getActorContext(),
476 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
481 public void testCDSDataTreeProducer() throws Exception {
482 initEmptyDatastores();
484 final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(
485 TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)),
486 DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
488 leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
489 ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
491 assertNotNull(findLocalShard(leaderDistributedDataStore.getActorContext(),
492 ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
495 final DOMDataTreeIdentifier configRoot =
496 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
497 final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot));
499 assertTrue(producer instanceof CDSDataTreeProducer);
501 final CDSDataTreeProducer cdsProducer = (CDSDataTreeProducer) producer;
502 CDSShardAccess shardAccess = cdsProducer.getShardAccess(TEST_ID);
503 assertEquals(shardAccess.getShardIdentifier(), TEST_ID);
505 shardAccess = cdsProducer.getShardAccess(INNER_LIST_ID);
506 assertEquals(TEST_ID, shardAccess.getShardIdentifier());
508 shardAccess = cdsProducer.getShardAccess(configRoot);
509 assertEquals(configRoot, shardAccess.getShardIdentifier());
511 waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
514 private static Collection<MapEntryNode> createOuterEntries(final int amount, final String valuePrefix) {
515 final Collection<MapEntryNode> ret = new ArrayList<>();
516 for (int i = 0; i < amount; i++) {
517 ret.add(ImmutableNodes.mapEntryBuilder()
518 .withNodeIdentifier(new NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME,
519 QName.create(TestModel.OUTER_LIST_QNAME, "id"), i))
520 .withChild(ImmutableNodes
521 .leafNode(QName.create(TestModel.OUTER_LIST_QNAME, "id"), i))
522 .withChild(createWholeInnerList(amount, "outer id: " + i + " " + valuePrefix))
529 private static MapNode createWholeInnerList(final int amount, final String valuePrefix) {
530 return ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
531 .withValue(createInnerListMapEntries(amount, valuePrefix)).build();
534 private static Collection<MapEntryNode> createInnerListMapEntries(final int amount, final String valuePrefix) {
535 final Collection<MapEntryNode> ret = new ArrayList<>();
536 for (int i = 0; i < amount; i++) {
537 ret.add(ImmutableNodes.mapEntryBuilder()
538 .withNodeIdentifier(new NodeIdentifierWithPredicates(TestModel.INNER_LIST_QNAME,
539 QName.create(TestModel.INNER_LIST_QNAME, "name"), Integer.toString(i)))
540 .withChild(ImmutableNodes
541 .leafNode(QName.create(TestModel.INNER_LIST_QNAME, "value"), valuePrefix + "-" + i))
548 private static YangInstanceIdentifier getOuterListIdFor(final int id) {
549 return TestModel.OUTER_LIST_PATH.node(new NodeIdentifierWithPredicates(
550 TestModel.OUTER_LIST_QNAME, QName.create(TestModel.OUTER_LIST_QNAME, "id"), id));