BUG-1014: expose a proper ShardDataTree constructor 45/29645/6
authorRobert Varga <rovarga@cisco.com>
Fri, 13 Nov 2015 12:02:33 +0000 (13:02 +0100)
committerRobert Varga <rovarga@cisco.com>
Thu, 26 Nov 2015 09:33:55 +0000 (10:33 +0100)
This patch exposes the proper constructor, deprecating the previous one
(which defaults to TreeType.OPERATIONAL). Furthermore convert all tests
to explicitly use OPERATIONAL tree.

The final bit which remains to be figured out is instantiation inside a
Shard instance, which is marked with a FIXME.

Change-Id: Ic8941c8fa5782b162e6faed7bc2d34920debc46e
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregator.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardRecoveryCoordinatorTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListenerTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipServiceTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnerChangeListenerTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipStatisticsTest.java

index e4cab8d..0bb886a 100644 (file)
@@ -134,6 +134,7 @@ public class Shard extends RaftActor {
 
         LOG.info("Shard created : {}, persistent : {}", name, datastoreContext.isPersistent());
 
+        // FIXME: BUG-1014: pass down the proper TreeType
         store = new ShardDataTree(builder.getSchemaContext());
 
         shardMBean = ShardMBeanFactory.getShardStatsMBean(name.toString(),
index abe1061..be2e6d4 100644 (file)
@@ -31,6 +31,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 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.tree.InMemoryDataTreeFactory;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
@@ -54,10 +55,17 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
     private final TipProducingDataTree dataTree;
     private SchemaContext schemaContext;
 
-    public ShardDataTree(final SchemaContext schemaContext) {
-        dataTree = InMemoryDataTreeFactory.getInstance().create();
+    public ShardDataTree(final SchemaContext schemaContext, final TreeType treeType) {
+        dataTree = InMemoryDataTreeFactory.getInstance().create(treeType);
         updateSchemaContext(schemaContext);
+    }
 
+    /**
+     * @deprecated Use {@link #ShardDataTree(SchemaContext, TreeType)} instead.
+     */
+    @Deprecated
+    public ShardDataTree(final SchemaContext schemaContext) {
+        this(schemaContext, TreeType.OPERATIONAL);
     }
 
     public TipProducingDataTree getDataTree() {
index efb1497..1860458 100644 (file)
@@ -27,6 +27,7 @@ public class NormalizedNodeAggregator {
                              final SchemaContext schemaContext) {
         this.rootIdentifier = rootIdentifier;
         this.nodes = nodes;
+        // FIXME: BUG-1014: pass down proper DataTree
         this.dataTree = InMemoryDataTreeFactory.getInstance().create();
         this.dataTree.setSchemaContext(schemaContext);
     }
index 4064dd0..c31db32 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class ShardDataTreeTest {
@@ -38,12 +39,12 @@ public class ShardDataTreeTest {
 
     @Test
     public void testWrite() throws ExecutionException, InterruptedException {
-        modify(new ShardDataTree(fullSchema), false, true, true);
+        modify(new ShardDataTree(fullSchema, TreeType.OPERATIONAL), false, true, true);
     }
 
     @Test
     public void testMerge() throws ExecutionException, InterruptedException {
-        modify(new ShardDataTree(fullSchema), true, true, true);
+        modify(new ShardDataTree(fullSchema, TreeType.OPERATIONAL), true, true, true);
     }
 
 
@@ -87,7 +88,7 @@ public class ShardDataTreeTest {
 
     @Test
     public void bug4359AddRemoveCarOnce() throws ExecutionException, InterruptedException {
-        ShardDataTree shardDataTree = new ShardDataTree(fullSchema);
+        ShardDataTree shardDataTree = new ShardDataTree(fullSchema, TreeType.OPERATIONAL);
 
         List<DataTreeCandidateTip> candidates = new ArrayList<>();
         candidates.add(addCar(shardDataTree));
@@ -104,7 +105,7 @@ public class ShardDataTreeTest {
 
     @Test
     public void bug4359AddRemoveCarTwice() throws ExecutionException, InterruptedException {
-        ShardDataTree shardDataTree = new ShardDataTree(fullSchema);
+        ShardDataTree shardDataTree = new ShardDataTree(fullSchema, TreeType.OPERATIONAL);
 
         List<DataTreeCandidateTip> candidates = new ArrayList<>();
         candidates.add(addCar(shardDataTree));
index bbcda6d..b730150 100644 (file)
@@ -46,7 +46,7 @@ public class ShardRecoveryCoordinatorTest {
         peopleSchemaContext = SchemaContextHelper.select(SchemaContextHelper.PEOPLE_YANG);
         carsSchemaContext = SchemaContextHelper.select(SchemaContextHelper.CARS_YANG);
 
-        peopleDataTree = new ShardDataTree(peopleSchemaContext);
+        peopleDataTree = new ShardDataTree(peopleSchemaContext, TreeType.OPERATIONAL);
     }
 
     @Test
index c3f66fb..fc1af28 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import scala.concurrent.Await;
@@ -40,7 +41,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest {
     private static final TransactionType RW = TransactionType.READ_WRITE;
     private static final TransactionType WO = TransactionType.WRITE_ONLY;
 
-    private static final ShardDataTree store = new ShardDataTree(testSchemaContext);
+    private static final ShardDataTree store = new ShardDataTree(testSchemaContext, TreeType.OPERATIONAL);
 
     private static final ShardIdentifier SHARD_IDENTIFIER =
         ShardIdentifier.builder().memberName("member-1")
index ab695f9..8d8db5e 100644 (file)
@@ -60,6 +60,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.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
+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.model.api.SchemaContext;
@@ -79,7 +80,7 @@ public class ShardTransactionTest extends AbstractActorTest {
 
     private final ShardStats shardStats = new ShardStats(SHARD_IDENTIFIER.toString(), "DataStore");
 
-    private final ShardDataTree store = new ShardDataTree(testSchemaContext);
+    private final ShardDataTree store = new ShardDataTree(testSchemaContext, TreeType.OPERATIONAL);
 
     private int txCounter = 0;
 
index 7516242..33fb4e3 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import scala.concurrent.duration.FiniteDuration;
 
 /**
@@ -39,7 +40,8 @@ public class CandidateListChangeListenerTest extends AbstractActorTest {
     private static final YangInstanceIdentifier ENTITY_ID2 =
             YangInstanceIdentifier.of(QName.create("test", "2015-08-14", "entity2"));
 
-    private final ShardDataTree shardDataTree = new ShardDataTree(SchemaContextHelper.entityOwners());
+    private final ShardDataTree shardDataTree = new ShardDataTree(SchemaContextHelper.entityOwners(),
+        TreeType.OPERATIONAL);
 
     @Test
     public void testOnDataTreeChanged() throws Exception {
index cedd942..31accd1 100644 (file)
@@ -61,6 +61,7 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 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.TreeType;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import scala.concurrent.Await;
 import scala.concurrent.Future;
@@ -263,7 +264,7 @@ public class DistributedEntityOwnershipServiceTest extends AbstractEntityOwnersh
 
         service.start();
 
-        ShardDataTree shardDataTree = new ShardDataTree(SchemaContextHelper.entityOwners());
+        ShardDataTree shardDataTree = new ShardDataTree(SchemaContextHelper.entityOwners(), TreeType.OPERATIONAL);
         shardBuilder.setDataTree(shardDataTree.getDataTree());
 
         Entity entity1 = new Entity(ENTITY_TYPE, "one");
index e13f456..cc228a4 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 ;
 
 /**
@@ -45,7 +46,8 @@ public class EntityOwnerChangeListenerTest {
     private static final Entity ENTITY1 = new Entity(ENTITY_TYPE, ENTITY_ID1);
     private static final Entity ENTITY2 = new Entity(ENTITY_TYPE, ENTITY_ID2);
 
-    private final ShardDataTree shardDataTree = new ShardDataTree(SchemaContextHelper.entityOwners());
+    private final ShardDataTree shardDataTree = new ShardDataTree(SchemaContextHelper.entityOwners(),
+        TreeType.OPERATIONAL);
     private final EntityOwnershipListenerSupport mockListenerSupport = mock(EntityOwnershipListenerSupport.class);
     private EntityOwnerChangeListener listener;
 
index de299c9..a621ac6 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 
 public class EntityOwnershipStatisticsTest extends AbstractActorTest {
     private static final String LOCAL_MEMBER_NAME = "member-1";
@@ -34,7 +35,8 @@ public class EntityOwnershipStatisticsTest extends AbstractActorTest {
     private static final YangInstanceIdentifier ENTITY_ID2 =
             YangInstanceIdentifier.of(QName.create("test", "2015-08-14", "entity2"));
 
-    private final ShardDataTree shardDataTree = new ShardDataTree(SchemaContextHelper.entityOwners());
+    private final ShardDataTree shardDataTree = new ShardDataTree(SchemaContextHelper.entityOwners(),
+        TreeType.OPERATIONAL);
     private EntityOwnershipStatistics ownershipStatistics;
 
     @Before