Force pruning during data migration
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / utils / PruningDataTreeModificationTest.java
index 18949ac21ecd5ec3d491933b9f15e0041a8f79fe..6ec01cfbbf0ad10909ec36038f45d8a2d59745b3 100644 (file)
@@ -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;
@@ -27,12 +26,15 @@ 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;
@@ -54,15 +56,17 @@ 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.data.util.DataSchemaContextTree;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
+@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 SchemaContext SCHEMA_CONTEXT;
+    private static DataSchemaContextTree CONTEXT_TREE;
+
     @Mock
     private DataTreeModification mockModification;
 
@@ -71,11 +75,16 @@ public class PruningDataTreeModificationTest {
     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 = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION,
             SCHEMA_CONTEXT);
 
@@ -89,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
@@ -190,11 +201,11 @@ 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<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY);
+        Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.empty());
         assertTrue("Root present", actual.isPresent());
         assertEquals("Root node", normalizedNode, actual.get());
     }
@@ -204,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(
                         ImmutableNodes.containerNode(AUG_CONTAINER)).build();
-        pruningDataTreeModification.write(YangInstanceIdentifier.EMPTY, normalizedNode);
+        pruningDataTreeModification.write(YangInstanceIdentifier.empty(), normalizedNode);
         dataTree.commit(getCandidate());
 
-        Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY);
+        Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.empty());
         assertEquals("Root present", true, actual.isPresent());
         assertEquals("Root node", root, actual.get());