Do not use ShardDataTree in PruningDataTreeModificationTest 75/42975/5
authorRobert Varga <rovarga@cisco.com>
Tue, 2 Aug 2016 13:33:25 +0000 (15:33 +0200)
committerTom Pantelis <tpanteli@brocade.com>
Wed, 3 Aug 2016 15:15:30 +0000 (15:15 +0000)
This test requires on a DataTree, hence use that.

Change-Id: I37697121f6686cdfe6b1d71ca87ff79281619532
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java

index e4be06e..3296280 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import java.util.AbstractMap.SimpleEntry;
@@ -16,8 +17,8 @@ import java.util.Map.Entry;
 import javax.annotation.concurrent.NotThreadSafe;
 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
-import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot;
 import org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot;
+import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
@@ -228,6 +229,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
         return dataTree.takeSnapshot().newModification();
     }
 
+    @VisibleForTesting
     // FIXME: This should be removed, it violates encapsulation
     public DataTreeCandidate commit(final DataTreeModification modification) throws DataValidationFailedException {
         modification.ready();
index 5e7c1ca..7bf7d50 100644 (file)
@@ -41,6 +41,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 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.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
@@ -180,21 +181,23 @@ public class PruningDataTreeModificationTest {
     }
 
     @Test
-    public void testWriteRootNode() throws Exception{
-        ShardDataTree shardDataTree = new ShardDataTree(SCHEMA_CONTEXT, TreeType.CONFIGURATION);
-        DataTreeModification mod = shardDataTree.newModification();
+    public void testWriteRootNode() throws Exception {
+        final DataTree localDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION);
+        localDataTree.setSchemaContext(SCHEMA_CONTEXT);
 
+        DataTreeModification mod = localDataTree.takeSnapshot().newModification();
         mod.write(CarsModel.BASE_PATH, CarsModel.create());
-        shardDataTree.commit(mod);
+        mod.ready();
+        localDataTree.validate(mod);
+        localDataTree.commit(localDataTree.prepare(mod));
 
-        NormalizedNode<?, ?> normalizedNode = shardDataTree.readNode(YangInstanceIdentifier.EMPTY).get();
+        NormalizedNode<?, ?> normalizedNode = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get();
         pruningDataTreeModification.write(YangInstanceIdentifier.EMPTY, normalizedNode);
         dataTree.commit(getCandidate());
 
         Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY);
         assertEquals("Root present", true, actual.isPresent());
         assertEquals("Root node", normalizedNode, actual.get());
-
     }
 
     @Test
@@ -292,4 +295,4 @@ public class PruningDataTreeModificationTest {
         DataTreeCandidateTip candidate = dataTree.prepare(mod);
         return candidate;
     }
-}
\ No newline at end of file
+}