X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Futils%2FPruningDataTreeModificationTest.java;h=1f5f92c03ca0ae115b1768133adbaebe5c0c8dd2;hb=24ee386f244cafa9bd3126ddbba1435969aa76c2;hp=7a8d065b14e0834a8ad0e921d3285b5d2af2fee9;hpb=5464f50be733df1bbbe31cf05665d542d3b7c5e7;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java index 7a8d065b14..1f5f92c03c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java @@ -5,7 +5,6 @@ * 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.controller.cluster.datastore.utils; import static org.junit.Assert.assertEquals; @@ -23,16 +22,19 @@ import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.i import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.outerNode; import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.outerNodeEntry; -import com.google.common.base.Optional; import com.google.common.reflect.Reflection; import java.lang.reflect.InvocationTargetException; +import java.util.Optional; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.controller.cluster.datastore.Shard; import org.opendaylight.controller.cluster.datastore.ShardDataTree; +import org.opendaylight.controller.cluster.datastore.node.utils.transformer.ReusableNormalizedNodePruner; import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; import org.opendaylight.controller.md.cluster.datastore.model.PeopleModel; import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper; @@ -43,40 +45,48 @@ import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory; import org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFailedException; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; +@RunWith(MockitoJUnitRunner.class) public class PruningDataTreeModificationTest { - static final SchemaContext SCHEMA_CONTEXT = SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, - SchemaContextHelper.ODL_DATASTORE_TEST_YANG); - static final QName INVALID_TEST_QNAME = QName.create(TestModel.TEST_QNAME, "invalid"); static final YangInstanceIdentifier INVALID_TEST_PATH = YangInstanceIdentifier.of(INVALID_TEST_QNAME); + private static EffectiveModelContext SCHEMA_CONTEXT; + private static DataSchemaContextTree CONTEXT_TREE; + @Mock private DataTreeModification mockModification; - private TipProducingDataTree dataTree; + private DataTree dataTree; private DataTreeModification realModification; private DataTreeModification proxyModification; private PruningDataTreeModification pruningDataTreeModification; + @BeforeClass + public static void beforeClass() { + SCHEMA_CONTEXT = SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, + SchemaContextHelper.ODL_DATASTORE_TEST_YANG); + CONTEXT_TREE = DataSchemaContextTree.from(SCHEMA_CONTEXT); + } + @Before + @SuppressWarnings("checkstyle:avoidHidingCauseException") public void setUp() { - MockitoAnnotations.initMocks(this); - - dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION); - dataTree.setSchemaContext(SCHEMA_CONTEXT); + dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, + SCHEMA_CONTEXT); realModification = dataTree.takeSnapshot().newModification(); proxyModification = Reflection.newProxy(DataTreeModification.class, (proxy, method, args) -> { @@ -88,7 +98,9 @@ public class PruningDataTreeModificationTest { } }); - pruningDataTreeModification = new PruningDataTreeModification(proxyModification, dataTree, SCHEMA_CONTEXT); + pruningDataTreeModification = new PruningDataTreeModification.Reactive(proxyModification, dataTree, + // Cannot reuse with parallel tests + ReusableNormalizedNodePruner.forDataSchemaContext(CONTEXT_TREE)); } @Test @@ -111,7 +123,7 @@ public class PruningDataTreeModificationTest { @Test public void testMerge() { - NormalizedNode normalizedNode = CarsModel.create(); + NormalizedNode normalizedNode = CarsModel.create(); YangInstanceIdentifier path = CarsModel.BASE_PATH; pruningDataTreeModification.merge(path, normalizedNode); @@ -120,14 +132,14 @@ public class PruningDataTreeModificationTest { @Test public void testMergeWithInvalidNamespace() throws DataValidationFailedException { - NormalizedNode normalizedNode = PeopleModel.emptyContainer(); + NormalizedNode normalizedNode = PeopleModel.emptyContainer(); YangInstanceIdentifier path = PeopleModel.BASE_PATH; pruningDataTreeModification.merge(path, normalizedNode); verify(mockModification, times(1)).merge(path, normalizedNode); - DataTreeCandidateTip candidate = getCandidate(); + DataTreeCandidate candidate = getCandidate(); assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().getModificationType()); } @@ -137,7 +149,7 @@ public class PruningDataTreeModificationTest { new YangInstanceIdentifier.NodeIdentifier(AUG_CONTAINER)).withChild( ImmutableNodes.containerNode(AUG_INNER_CONTAINER)).build(); - DataContainerChild outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two"))); + DataContainerChild outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two"))); ContainerNode normalizedNode = ImmutableContainerNodeBuilder.create() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode) .withChild(augContainer).withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")).build(); @@ -151,27 +163,27 @@ public class PruningDataTreeModificationTest { ContainerNode prunedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier( new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).build(); - Optional> actual = dataTree.takeSnapshot().readNode(path); - assertEquals("After pruning present", true, actual.isPresent()); + Optional actual = dataTree.takeSnapshot().readNode(path); + assertTrue("After pruning present", actual.isPresent()); assertEquals("After pruning", prunedNode, actual.get()); } @Test public void testMergeWithValidNamespaceAndInvalidNodeName() throws DataValidationFailedException { - NormalizedNode normalizedNode = ImmutableNodes.containerNode(INVALID_TEST_QNAME); + NormalizedNode normalizedNode = ImmutableNodes.containerNode(INVALID_TEST_QNAME); YangInstanceIdentifier path = INVALID_TEST_PATH; pruningDataTreeModification.merge(path, normalizedNode); verify(mockModification, times(1)).merge(path, normalizedNode); - DataTreeCandidateTip candidate = getCandidate(); + DataTreeCandidate candidate = getCandidate(); assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().getModificationType()); } @Test public void testWrite() { - NormalizedNode normalizedNode = CarsModel.create(); + NormalizedNode normalizedNode = CarsModel.create(); YangInstanceIdentifier path = CarsModel.BASE_PATH; pruningDataTreeModification.write(path, normalizedNode); @@ -180,8 +192,8 @@ public class PruningDataTreeModificationTest { @Test public void testWriteRootNode() throws Exception { - final DataTree localDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION); - localDataTree.setSchemaContext(SCHEMA_CONTEXT); + final DataTree localDataTree = new InMemoryDataTreeFactory().create( + DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT); DataTreeModification mod = localDataTree.takeSnapshot().newModification(); mod.write(CarsModel.BASE_PATH, CarsModel.create()); @@ -189,12 +201,12 @@ public class PruningDataTreeModificationTest { localDataTree.validate(mod); localDataTree.commit(localDataTree.prepare(mod)); - NormalizedNode normalizedNode = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get(); - pruningDataTreeModification.write(YangInstanceIdentifier.EMPTY, normalizedNode); + NormalizedNode normalizedNode = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.empty()).get(); + pruningDataTreeModification.write(YangInstanceIdentifier.empty(), normalizedNode); dataTree.commit(getCandidate()); - Optional> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY); - assertEquals("Root present", true, actual.isPresent()); + Optional actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.empty()); + assertTrue("Root present", actual.isPresent()); assertEquals("Root node", normalizedNode, actual.get()); } @@ -203,15 +215,15 @@ public class PruningDataTreeModificationTest { final Shard mockShard = Mockito.mock(Shard.class); ShardDataTree shardDataTree = new ShardDataTree(mockShard, SCHEMA_CONTEXT, TreeType.CONFIGURATION); - NormalizedNode root = shardDataTree.readNode(YangInstanceIdentifier.EMPTY).get(); + NormalizedNode root = shardDataTree.readNode(YangInstanceIdentifier.empty()).get(); - NormalizedNode normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier( - new YangInstanceIdentifier.NodeIdentifier(root.getNodeType())).withChild( + NormalizedNode normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier( + new YangInstanceIdentifier.NodeIdentifier(root.getIdentifier().getNodeType())).withChild( ImmutableNodes.containerNode(AUG_CONTAINER)).build(); - pruningDataTreeModification.write(YangInstanceIdentifier.EMPTY, normalizedNode); + pruningDataTreeModification.write(YangInstanceIdentifier.empty(), normalizedNode); dataTree.commit(getCandidate()); - Optional> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY); + Optional actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.empty()); assertEquals("Root present", true, actual.isPresent()); assertEquals("Root node", root, actual.get()); @@ -219,14 +231,14 @@ public class PruningDataTreeModificationTest { @Test public void testWriteWithInvalidNamespace() throws DataValidationFailedException { - NormalizedNode normalizedNode = PeopleModel.emptyContainer(); + NormalizedNode normalizedNode = PeopleModel.emptyContainer(); YangInstanceIdentifier path = PeopleModel.BASE_PATH; pruningDataTreeModification.write(path, normalizedNode); verify(mockModification, times(1)).write(path, normalizedNode); - DataTreeCandidateTip candidate = getCandidate(); + DataTreeCandidate candidate = getCandidate(); assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().getModificationType()); } @@ -236,7 +248,7 @@ public class PruningDataTreeModificationTest { new YangInstanceIdentifier.NodeIdentifier(AUG_CONTAINER)).withChild( ImmutableNodes.containerNode(AUG_INNER_CONTAINER)).build(); - DataContainerChild outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two"))); + DataContainerChild outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two"))); ContainerNode normalizedNode = ImmutableContainerNodeBuilder.create() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode) .withChild(augContainer).withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")) @@ -252,8 +264,8 @@ public class PruningDataTreeModificationTest { .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode) .withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")).build(); - Optional> actual = dataTree.takeSnapshot().readNode(path); - assertEquals("After pruning present", true, actual.isPresent()); + Optional actual = dataTree.takeSnapshot().readNode(path); + assertTrue("After pruning present", actual.isPresent()); assertEquals("After pruning", prunedNode, actual.get()); } @@ -288,12 +300,11 @@ public class PruningDataTreeModificationTest { dataTreeModification instanceof PruningDataTreeModification); } - private DataTreeCandidateTip getCandidate() throws DataValidationFailedException { + private DataTreeCandidate getCandidate() throws DataValidationFailedException { pruningDataTreeModification.ready(); DataTreeModification mod = pruningDataTreeModification.delegate(); mod = mod == proxyModification ? realModification : mod; dataTree.validate(mod); - DataTreeCandidateTip candidate = dataTree.prepare(mod); - return candidate; + return dataTree.prepare(mod); } }