@Test
public void testMockedSubshards() throws Exception {
final WriteableDOMDataTreeShard mockedInnerShard = Mockito.mock(WriteableDOMDataTreeShard.class);
+ final DOMDataTreeShardProducer mockedProducer = Mockito.mock(DOMDataTreeShardProducer.class);
+ doReturn(mockedProducer).when(mockedInnerShard).createProducer(anyCollection());
final ShardedDOMDataTreeProducer shardRegProducer = Mockito.mock(ShardedDOMDataTreeProducer.class);
doReturn(Collections.singleton(INNER_CONTAINER_ID)).when(shardRegProducer).getSubtrees();
doNothing().when(shardRegProducer).subshardAdded(anyMap());
dataTreeService.registerDataTreeShard(INNER_CONTAINER_ID, mockedInnerShard, shardRegProducer);
- final DOMDataTreeShardProducer mockedProducer = Mockito.mock(DOMDataTreeShardProducer.class);
- doReturn(mockedProducer).when(mockedInnerShard).createProducer(any(Collection.class));
final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID));
}
- private ContainerNode createCrossShardContainer() {
+ private static ContainerNode createCrossShardContainer() {
final LeafNode<String> shardedValue1 =
ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(
new NodeIdentifier(TestModel.SHARDED_VALUE_1)).withValue("sharded value 1").build();
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@Beta
public class InMemoryDOMDataTreeShard implements ReadableWriteableDOMDataTreeShard, SchemaContextListener {
-
- private static final int DEFAULT_SUBMIT_QUEUE_SIZE = 1000;
-
private static final class SubshardProducerSpecification {
private final Collection<DOMDataTreeIdentifier> prefixes = new ArrayList<>(1);
private final ChildShardContext shard;
return shard.getShard().createProducer(prefixes);
}
- public DOMDataTreeIdentifier getPrefix() {
+ DOMDataTreeIdentifier getPrefix() {
return shard.getPrefix();
}
}
+ private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataTreeShard.class);
+ private static final int DEFAULT_SUBMIT_QUEUE_SIZE = 1000;
+
private final DOMDataTreePrefixTable<ChildShardContext> childShardsTable = DOMDataTreePrefixTable.create();
private final Map<DOMDataTreeIdentifier, ChildShardContext> childShards = new HashMap<>();
- private final DOMDataTreeIdentifier prefix;
- private final DataTree dataTree;
+ private final Collection<InMemoryDOMDataTreeShardProducer> producers = new HashSet<>();
private final InMemoryDOMDataTreeShardChangePublisher shardChangePublisher;
private final ListeningExecutorService executor;
+ private final DOMDataTreeIdentifier prefix;
+ private final DataTree dataTree;
private InMemoryDOMDataTreeShard(final DOMDataTreeIdentifier prefix, final Executor dataTreeChangeExecutor,
final int maxDataChangeListenerQueueSize, final int submitQueueSize) {
public void onChildAttached(final DOMDataTreeIdentifier prefix, final DOMDataTreeShard child) {
Preconditions.checkArgument(child != this, "Attempted to attach child %s onto self", this);
reparentChildShards(prefix, child);
- addChildShard(prefix, child);
+
+ final ChildShardContext context = createContextFor(prefix, child);
+ childShards.put(prefix, context);
+ childShardsTable.store(prefix, context);
+ updateProducers();
}
@Override
public void onChildDetached(final DOMDataTreeIdentifier prefix, final DOMDataTreeShard child) {
childShards.remove(prefix);
childShardsTable.remove(prefix);
+ updateProducers();
+ }
+
+ private void updateProducers() {
+ for (InMemoryDOMDataTreeShardProducer p : producers) {
+ p.setModificationFactory(createModificationFactory(p.getPrefixes()));
+ }
+ }
+
+ @VisibleForTesting
+ ShardDataModificationFactory createModificationFactory(final Collection<DOMDataTreeIdentifier> prefixes) {
+ final Map<DOMDataTreeIdentifier, SubshardProducerSpecification> affected = new HashMap<>();
+ for (final DOMDataTreeIdentifier producerPrefix : prefixes) {
+ for (final ChildShardContext child : childShards.values()) {
+ final DOMDataTreeIdentifier bindPath;
+ if (producerPrefix.contains(child.getPrefix())) {
+ bindPath = child.getPrefix();
+ } else if (child.getPrefix().contains(producerPrefix)) {
+ // Bound path is inside subshard
+ bindPath = producerPrefix;
+ } else {
+ continue;
+ }
+
+ SubshardProducerSpecification spec = affected.get(child.getPrefix());
+ if (spec == null) {
+ spec = new SubshardProducerSpecification(child);
+ affected.put(child.getPrefix(), spec);
+ }
+ spec.addPrefix(bindPath);
+ }
+ }
+
+ final ShardDataModificationFactoryBuilder builder = new ShardDataModificationFactoryBuilder(prefix);
+ for (final SubshardProducerSpecification spec : affected.values()) {
+ final ForeignShardModificationContext foreignContext =
+ new ForeignShardModificationContext(spec.getPrefix(), spec.createProducer());
+ builder.addSubshard(foreignContext);
+ builder.addSubshard(spec.getPrefix(), foreignContext);
+ }
+
+ return builder.build();
}
@Override
Preconditions.checkArgument(prefix.contains(prodPrefix), "Prefix %s is not contained under shart root",
prodPrefix, prefix);
}
- return new InMemoryDOMDataTreeShardProducer(this, prefixes);
+
+ final InMemoryDOMDataTreeShardProducer ret = new InMemoryDOMDataTreeShardProducer(this, prefixes,
+ createModificationFactory(prefixes));
+ producers.add(ret);
+ return ret;
+ }
+
+ void closeProducer(final InMemoryDOMDataTreeShardProducer producer) {
+ if (!producers.remove(producer)) {
+ LOG.warn("Producer {} not found in shard {}", producer, this);
+ }
}
@Nonnull
return shardChangePublisher.registerTreeChangeListener(treeId, listener);
}
- private void addChildShard(final DOMDataTreeIdentifier prefix, final DOMDataTreeShard child) {
- final ChildShardContext context = createContextFor(prefix, child);
- childShards.put(prefix, context);
- childShardsTable.store(prefix, context);
- }
-
private void reparentChildShards(final DOMDataTreeIdentifier newChildPrefix, final DOMDataTreeShard newChild) {
final Iterator<Entry<DOMDataTreeIdentifier, ChildShardContext>> actualChildren =
childShards.entrySet().iterator();
}
InmemoryDOMDataTreeShardWriteTransaction createTransaction(final String transactionId,
- final InMemoryDOMDataTreeShardProducer producer,
- final Collection<DOMDataTreeIdentifier> prefixes,
- final DataTreeSnapshot snapshot) {
-
- return createTxForSnapshot(producer, prefixes, (CursorAwareDataTreeSnapshot) snapshot);
- }
-
- private InmemoryDOMDataTreeShardWriteTransaction createTxForSnapshot(
- final InMemoryDOMDataTreeShardProducer producer,
- final Collection<DOMDataTreeIdentifier> prefixes,
- final CursorAwareDataTreeSnapshot snapshot) {
-
- final Map<DOMDataTreeIdentifier, SubshardProducerSpecification> affectedSubshards = new HashMap<>();
- for (final DOMDataTreeIdentifier producerPrefix : prefixes) {
- for (final ChildShardContext maybeAffected : childShards.values()) {
- final DOMDataTreeIdentifier bindPath;
- if (producerPrefix.contains(maybeAffected.getPrefix())) {
- bindPath = maybeAffected.getPrefix();
- } else if (maybeAffected.getPrefix().contains(producerPrefix)) {
- // Bound path is inside subshard
- bindPath = producerPrefix;
- } else {
- continue;
- }
-
- SubshardProducerSpecification spec = affectedSubshards.get(maybeAffected.getPrefix());
- if (spec == null) {
- spec = new SubshardProducerSpecification(maybeAffected);
- affectedSubshards.put(maybeAffected.getPrefix(), spec);
- }
- spec.addPrefix(bindPath);
- }
- }
+ final InMemoryDOMDataTreeShardProducer producer, final DataTreeSnapshot snapshot) {
+ Preconditions.checkArgument(snapshot instanceof CursorAwareDataTreeSnapshot);
- final ShardRootModificationContext rootContext = new ShardRootModificationContext(prefix, snapshot);
- final ShardDataModificationBuilder builder = new ShardDataModificationBuilder(rootContext);
- for (final SubshardProducerSpecification spec : affectedSubshards.values()) {
- final ForeignShardModificationContext foreignContext =
- new ForeignShardModificationContext(spec.getPrefix(), spec.createProducer());
- builder.addSubshard(foreignContext);
- builder.addSubshard(spec.getPrefix(), foreignContext);
- }
-
- return new InmemoryDOMDataTreeShardWriteTransaction(producer, builder.build(),
- dataTree, shardChangePublisher, executor);
+ return new InmemoryDOMDataTreeShardWriteTransaction(producer,
+ producer.getModificationFactory().createModification((CursorAwareDataTreeSnapshot)snapshot), dataTree,
+ shardChangePublisher, executor);
}
-
}
AtomicReferenceFieldUpdater.newUpdater(InMemoryDOMDataTreeShardProducer.class, State.class, "state");
private volatile State state;
+ private ShardDataModificationFactory modificationFactory;
+
InMemoryDOMDataTreeShardProducer(final InMemoryDOMDataTreeShard parentShard,
- final Collection<DOMDataTreeIdentifier> prefixes) {
+ final Collection<DOMDataTreeIdentifier> prefixes, final ShardDataModificationFactory modificationFactory) {
this.parentShard = Preconditions.checkNotNull(parentShard);
this.prefixes = ImmutableSet.copyOf(prefixes);
+ this.modificationFactory = Preconditions.checkNotNull(modificationFactory);
state = idleState;
}
InmemoryDOMDataTreeShardWriteTransaction ret;
do {
localState = state;
- ret = parentShard.createTransaction(transactionId, this, prefixes, localState.getSnapshot(transactionId));
+ ret = parentShard.createTransaction(transactionId, this, localState.getSnapshot(transactionId));
} while (!STATE_UPDATER.compareAndSet(this, localState, new Allocated(ret)));
return ret;
public Collection<DOMDataTreeIdentifier> getPrefixes() {
return prefixes;
}
+
+ ShardDataModificationFactory getModificationFactory() {
+ return modificationFactory;
+ }
+
+ void setModificationFactory(final ShardDataModificationFactory modificationFactory) {
+ this.modificationFactory = Preconditions.checkNotNull(modificationFactory);
+ }
}
package org.opendaylight.mdsal.dom.store.inmemory;
+import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.Map;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-abstract class ModificationContextNodeBuilder<T extends WriteableModificationNode> {
+abstract class ModificationContextNodeBuilder {
private final Map<PathArgument, InteriorNodeBuilder> interiorChildren = new HashMap<>();
private final Map<PathArgument, WriteableSubshardBoundaryNode> boundaryChildren = new HashMap<>();
- protected InteriorNodeBuilder getInterior(final PathArgument arg) {
+ protected ModificationContextNodeBuilder getInterior(final PathArgument arg) {
InteriorNodeBuilder potential = interiorChildren.get(arg);
if (potential == null) {
potential = new InteriorNodeBuilder(arg);
boundaryChildren.put(arg, subshardNode);
}
- final T build() {
+ final Map<PathArgument, WriteableModificationNode> buildChildren() {
final Map<PathArgument, WriteableModificationNode> builtChildren = new HashMap<>(boundaryChildren);
for (InteriorNodeBuilder interiorNode : interiorChildren.values()) {
WriteableModificationNode builded = interiorNode.build();
builtChildren.put(builded.getIdentifier(), builded);
}
- return build(builtChildren);
+ return builtChildren;
}
- abstract T build(Map<PathArgument, WriteableModificationNode> children);
-
- private static class InteriorNodeBuilder extends ModificationContextNodeBuilder<WritableInteriorNode> {
-
+ private static final class InteriorNodeBuilder extends ModificationContextNodeBuilder {
private final PathArgument arg;
InteriorNodeBuilder(final PathArgument arg) {
- this.arg = arg;
+ this.arg = Preconditions.checkNotNull(arg);
}
- @Override
- WritableInteriorNode build(final Map<PathArgument, WriteableModificationNode> children) {
- return new WritableInteriorNode(arg, children);
+ WritableInteriorNode build() {
+ return new WritableInteriorNode(arg, buildChildren());
}
}
-
}
\ No newline at end of file
import java.util.Map;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
return rootContext.getIdentifier().getRootIdentifier().getLastPathArgument();
}
- static ShardDataModification from(final ShardRootModificationContext root,
- final Map<YangInstanceIdentifier, ForeignShardModificationContext> shards) {
-
- ShardDataModificationBuilder builder = new ShardDataModificationBuilder(root);
- for (ForeignShardModificationContext subshard : shards.values()) {
- builder.addSubshard(subshard);
- }
- return builder.build();
- }
-
DOMDataTreeIdentifier getPrefix() {
return rootContext.getIdentifier();
}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.mdsal.dom.store.inmemory;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-
-class ShardDataModificationBuilder extends ModificationContextNodeBuilder<ShardDataModification> {
-
- private final ShardRootModificationContext root;
- private final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards =
- new HashMap<>();
-
- ShardDataModificationBuilder(final ShardRootModificationContext root) {
- this.root = root;
- }
-
- public void addSubshard(final ForeignShardModificationContext value) {
- WriteableSubshardBoundaryNode leafNode = WriteableSubshardBoundaryNode.from(value);
- putNode(value.getIdentifier().getRootIdentifier(), leafNode);
- }
-
- public void addSubshard(final DOMDataTreeIdentifier prefix, final ForeignShardModificationContext value) {
- childShards.put(prefix, value);
- }
-
- private void putNode(final YangInstanceIdentifier key, final WriteableSubshardBoundaryNode subshardNode) {
- ModificationContextNodeBuilder<?> current = this;
- Iterator<PathArgument> toBoundary = toRelative(key).getPathArguments().iterator();
- while (toBoundary.hasNext()) {
- PathArgument nextArg = toBoundary.next();
- if (toBoundary.hasNext()) {
- current = getInterior(nextArg);
- } else {
- current.addBoundary(nextArg, subshardNode);
- }
- }
- }
-
-
- @Override
- ShardDataModification build(final Map<PathArgument, WriteableModificationNode> children) {
- return new ShardDataModification(root, children, childShards);
- }
-
- private YangInstanceIdentifier toRelative(final YangInstanceIdentifier key) {
- return key.relativeTo(root.getIdentifier().getRootIdentifier()).get();
- }
-}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.dom.store.inmemory;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeSnapshot;
+
+final class ShardDataModificationFactory {
+ private final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards;
+ private final Map<PathArgument, WriteableModificationNode> children;
+ private final DOMDataTreeIdentifier root;
+
+ ShardDataModificationFactory(final DOMDataTreeIdentifier root,
+ final Map<PathArgument, WriteableModificationNode> children,
+ final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards) {
+ this.root = Preconditions.checkNotNull(root);
+ this.children = ImmutableMap.copyOf(children);
+ this.childShards = ImmutableMap.copyOf(childShards);
+ }
+
+ @VisibleForTesting
+ Map<PathArgument, WriteableModificationNode> getChildren() {
+ return children;
+ }
+
+ @VisibleForTesting
+ Map<DOMDataTreeIdentifier, ForeignShardModificationContext> getChildShards() {
+ return childShards;
+ }
+
+ ShardDataModification createModification(final CursorAwareDataTreeSnapshot snapshot) {
+ return new ShardDataModification(new ShardRootModificationContext(root, snapshot), children, childShards);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.mdsal.dom.store.inmemory;
+
+import com.google.common.base.Preconditions;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+
+class ShardDataModificationFactoryBuilder extends ModificationContextNodeBuilder
+ implements Builder<ShardDataModificationFactory> {
+
+ private final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards = new HashMap<>();
+ private final DOMDataTreeIdentifier root;
+
+ ShardDataModificationFactoryBuilder(final DOMDataTreeIdentifier root) {
+ this.root = Preconditions.checkNotNull(root);
+ }
+
+ void addSubshard(final ForeignShardModificationContext value) {
+ WriteableSubshardBoundaryNode leafNode = WriteableSubshardBoundaryNode.from(value);
+ putNode(value.getIdentifier().getRootIdentifier(), leafNode);
+ }
+
+ void addSubshard(final DOMDataTreeIdentifier prefix, final ForeignShardModificationContext value) {
+ childShards.put(prefix, value);
+ }
+
+ private void putNode(final YangInstanceIdentifier key, final WriteableSubshardBoundaryNode subshardNode) {
+ final Iterator<PathArgument> toBoundary = toRelative(key).getPathArguments().iterator();
+ if (toBoundary.hasNext()) {
+ ModificationContextNodeBuilder current = this;
+ while (true) {
+ final PathArgument nextArg = toBoundary.next();
+ if (!toBoundary.hasNext()) {
+ current.addBoundary(nextArg, subshardNode);
+ break;
+ }
+
+ current = getInterior(nextArg);
+ }
+ }
+ }
+
+ @Override
+ public ShardDataModificationFactory build() {
+ return new ShardDataModificationFactory(root, buildChildren(), childShards);
+ }
+
+ private YangInstanceIdentifier toRelative(final YangInstanceIdentifier key) {
+ return key.relativeTo(root.getRootIdentifier()).get();
+ }
+}
\ No newline at end of file
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyCollectionOf;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_IDENTIFIER;
import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.resetMocks;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.junit.Test;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeSnapshot;
public class InMemoryDOMDataTreeShardProducerTest {
doReturn(inmemoryDOMDataTreeShardWriteTransaction).when(inMemoryDOMDataTreeShard)
.createTransaction(any(String.class), any(InMemoryDOMDataTreeShardProducer.class),
- anyCollectionOf((DOMDataTreeIdentifier.class)), any(CursorAwareDataTreeSnapshot.class));
+ any(CursorAwareDataTreeSnapshot.class));
final InMemoryDOMDataTreeShardProducer inMemoryDOMDataTreeShardProducer =
new InMemoryDOMDataTreeShardProducer(inMemoryDOMDataTreeShard,
- ImmutableSet.of(DOM_DATA_TREE_IDENTIFIER));
+ ImmutableSet.of(DOM_DATA_TREE_IDENTIFIER),
+ new ShardDataModificationFactory(DOM_DATA_TREE_IDENTIFIER, ImmutableMap.of(),
+ ImmutableMap.of()));
assertNotNull(inMemoryDOMDataTreeShardProducer.createTransaction());
verify(inMemoryDOMDataTreeShard).createTransaction(
any(String.class),
any(InMemoryDOMDataTreeShardProducer.class),
- anyCollectionOf(DOMDataTreeIdentifier.class),
any(CursorAwareDataTreeSnapshot.class));
resetMocks();
}
-}
\ No newline at end of file
+}
public void basicTest() throws Exception {
final InMemoryDOMDataTreeShard inMemoryDOMDataTreeShard =
InMemoryDOMDataTreeShard.create(DOM_DATA_TREE_IDENTIFIER,
- MoreExecutors.newDirectExecutorService(), 1);
+ MoreExecutors.directExecutor(), 1);
final DOMDataTreeIdentifier domDataTreeIdentifier =
new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
assertEquals(prefixes.toString(), inMemoryDOMDataTreeShard.createProducer(prefixes).getPrefixes().toString());
final InMemoryDOMDataTreeShardProducer mockProducer = mock(InMemoryDOMDataTreeShardProducer.class);
+ doReturn(prefixes).when(mockProducer).getPrefixes();
+ doReturn(inMemoryDOMDataTreeShard.createModificationFactory(prefixes))
+ .when(mockProducer).getModificationFactory();
inMemoryDOMDataTreeShard.onGlobalContextUpdated(createTestContext());
- inMemoryDOMDataTreeShard.createTransaction("", mockProducer, prefixes, mock(CursorAwareDataTreeSnapshot.class));
+ inMemoryDOMDataTreeShard.createTransaction("", mockProducer, mock(CursorAwareDataTreeSnapshot.class));
final DOMDataTreeChangeListener domDataTreeChangeListener = mock(DOMDataTreeChangeListener.class);
- final ListenerRegistration listenerRegistration = mock(ListenerRegistration.class);
+ final ListenerRegistration<?> listenerRegistration = mock(ListenerRegistration.class);
doReturn(listenerRegistration).when(domDataTreeShard).registerTreeChangeListener(any(), any());
doNothing().when(domDataTreeChangeListener).onDataTreeChanged(any());
inMemoryDOMDataTreeShard.registerTreeChangeListener(YangInstanceIdentifier.EMPTY, domDataTreeChangeListener);
final InmemoryDOMDataTreeShardWriteTransaction inmemoryDOMDataTreeShardWriteTransaction =
mock(InmemoryDOMDataTreeShardWriteTransaction.class);
doReturn(dataTreeModification).when(inmemoryDOMDataTreeShardWriteTransaction).getRootModification();
- final InMemoryDOMDataTreeShardProducer mockProducer = mock(InMemoryDOMDataTreeShardProducer.class);
final Collection<DOMDataTreeIdentifier> prefixes = ImmutableList.of(DOM_DATA_TREE_IDENTIFIER);
+ final InMemoryDOMDataTreeShardProducer mockProducer = mock(InMemoryDOMDataTreeShardProducer.class);
+ doReturn(prefixes).when(mockProducer).getPrefixes();
+ doReturn(inMemoryDOMDataTreeShard.createModificationFactory(prefixes))
+ .when(mockProducer).getModificationFactory();
- inMemoryDOMDataTreeShard.createTransaction("", mockProducer, prefixes, mock(CursorAwareDataTreeSnapshot.class));
+ inMemoryDOMDataTreeShard.createTransaction("", mockProducer, mock(CursorAwareDataTreeSnapshot.class));
}
@After
doReturn("testDataTreeModification").when(dataTreeModification).toString();
doReturn(dataTreeModification).when(SHARD_ROOT_MODIFICATION_CONTEXT).ready();
doReturn(DOM_DATA_TREE_IDENTIFIER).when(SHARD_ROOT_MODIFICATION_CONTEXT).getIdentifier();
- shardDataModification = ShardDataModification.from(SHARD_ROOT_MODIFICATION_CONTEXT,
+ shardDataModification = TestUtils.createModification(SHARD_ROOT_MODIFICATION_CONTEXT,
ImmutableMap.of(YANG_INSTANCE_IDENTIFIER, FOREIGN_SHARD_MODIFICATION_CONTEXT));
final DataTreeModificationCursor dataTreeModificationCursor = mock(DataTreeModificationCursor.class);
doReturn(DataTreeModificationCursorAdaptor.of( dataTreeModificationCursor))
*/
package org.opendaylight.mdsal.dom.store.inmemory;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_IDENTIFIER;
import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_SHARD_PRODUCER;
import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.PATH_ARGUMENT;
-import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.WRITEABLE_MODIFICATION_NODE;
-import java.util.Map;
import org.junit.Test;
public class ModificationContextNodeBuilderTest extends ModificationContextNodeBuilder {
super.addBoundary(PATH_ARGUMENT, writeableSubshardBoundaryNode);
assertNotNull(super.getInterior(PATH_ARGUMENT));
- assertEquals(WRITEABLE_MODIFICATION_NODE, super.build());
- }
-
- @Override
- WriteableModificationNode build(Map children) {
- return WRITEABLE_MODIFICATION_NODE;
}
}
\ No newline at end of file
import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.resetMocks;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import java.lang.reflect.Field;
import java.util.Deque;
import java.util.HashMap;
final ShardRootModificationContext shardRootModificationContext = mock(ShardRootModificationContext.class);
final Map<PathArgument, WriteableModificationNode> children = new HashMap<>();
children.put(PATH_ARGUMENT, WRITEABLE_MODIFICATION_NODE);
- final ShardDataModification root =
- new ShardDataModificationBuilder(shardRootModificationContext).build(children);
+ final ShardDataModification root = new ShardDataModification(shardRootModificationContext, children,
+ ImmutableMap.of());
+
doReturn(dataTreeModificationCursorAdaptor).when(shardRootModificationContext).cursor();
InmemoryDOMDataTreeShardWriteTransaction inmemoryDOMDataTreeShardWriteTransaction =
mock(InmemoryDOMDataTreeShardWriteTransaction.class);
@Before
public void setUp() throws Exception {
doReturn(DOM_DATA_TREE_IDENTIFIER).when(SHARD_ROOT_MODIFICATION_CONTEXT).getIdentifier();
- shardDataModification = ShardDataModification.from(SHARD_ROOT_MODIFICATION_CONTEXT,
+ shardDataModification = TestUtils.createModification(SHARD_ROOT_MODIFICATION_CONTEXT,
ImmutableMap.of(YangInstanceIdentifier.of(QName.create("test")), FOREIGN_SHARD_MODIFICATION_CONTEXT));
final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> children =
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Map;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
private TestUtils() throws UnsupportedOperationException {
throw new UnsupportedOperationException("Utility class should not be instantiated");
}
-}
\ No newline at end of file
+
+ static ShardDataModification createModification(final ShardRootModificationContext root,
+ final Map<YangInstanceIdentifier, ForeignShardModificationContext> shards) {
+
+ final ShardDataModificationFactoryBuilder builder = new ShardDataModificationFactoryBuilder(
+ root.getIdentifier());
+ for (ForeignShardModificationContext subshard : shards.values()) {
+ builder.addSubshard(subshard);
+ }
+
+ final ShardDataModificationFactory factory = builder.build();
+ return new ShardDataModification(root, factory.getChildren(), factory.getChildShards());
+ }
+
+}