Use YangInstanceIdentifier.EMPTY
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / ShardTransactionTest.java
index 51e46c000cd316ab54f2305d445f313835448434..e0b34925ab6116708e7b1f257ca959b815d0079e 100644 (file)
@@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
 import org.junit.Test;
 import org.mockito.InOrder;
 import org.mockito.Mockito;
+import org.opendaylight.controller.cluster.access.concepts.MemberName;
 import org.opendaylight.controller.cluster.datastore.exceptions.UnknownMessageException;
 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
@@ -61,8 +62,7 @@ public class ShardTransactionTest extends AbstractActorTest {
     private static final TransactionType WO = TransactionType.WRITE_ONLY;
 
     private static final ShardIdentifier SHARD_IDENTIFIER =
-        ShardIdentifier.builder().memberName("member-1")
-            .shardName("inventory").type("config").build();
+        ShardIdentifier.create("inventory", MemberName.forName("member-1"), "config");
 
     private DatastoreContext datastoreContext = DatastoreContext.newBuilder().build();
 
@@ -80,21 +80,12 @@ public class ShardTransactionTest extends AbstractActorTest {
     }
 
     private ActorRef newTransactionActor(TransactionType type, AbstractShardDataTreeTransaction<?> transaction, String name) {
-        return newTransactionActor(type, transaction, name, DataStoreVersions.CURRENT_VERSION);
-    }
-
-    private ActorRef newTransactionActor(TransactionType type, AbstractShardDataTreeTransaction<?> transaction, String name, short version) {
-        return newTransactionActor(type, transaction, null, name, version);
+        return newTransactionActor(type, transaction, null, name);
     }
 
     private ActorRef newTransactionActor(TransactionType type, AbstractShardDataTreeTransaction<?> transaction, ActorRef shard, String name) {
-        return newTransactionActor(type, transaction, null, name, DataStoreVersions.CURRENT_VERSION);
-    }
-
-    private ActorRef newTransactionActor(TransactionType type, AbstractShardDataTreeTransaction<?> transaction, ActorRef shard, String name,
-            short version) {
         Props props = ShardTransaction.props(type, transaction, shard != null ? shard : createShard(),
-                datastoreContext, shardStats, "txn", version);
+                datastoreContext, shardStats, "txn");
         return getSystem().actorOf(props, name);
     }
 
@@ -117,17 +108,8 @@ public class ShardTransactionTest extends AbstractActorTest {
         }
 
         private void testOnReceiveReadData(final ActorRef transaction) {
-            //serialized read
-            transaction.tell(new ReadData(YangInstanceIdentifier.builder().build()).toSerializable(),
-                getRef());
-
-            Object replySerialized =
-                    expectMsgClass(duration("5 seconds"), ReadDataReply.SERIALIZABLE_CLASS);
-
-            assertNotNull(ReadDataReply.fromSerializable(replySerialized).getNormalizedNode());
-
-            // unserialized read
-            transaction.tell(new ReadData(YangInstanceIdentifier.builder().build()),getRef());
+            transaction.tell(new ReadData(YangInstanceIdentifier.EMPTY,
+                    DataStoreVersions.CURRENT_VERSION), getRef());
 
             ReadDataReply reply = expectMsgClass(duration("5 seconds"), ReadDataReply.class);
 
@@ -148,16 +130,7 @@ public class ShardTransactionTest extends AbstractActorTest {
         }
 
         private void testOnReceiveReadDataWhenDataNotFound(final ActorRef transaction) {
-            // serialized read
-            transaction.tell(new ReadData(TestModel.TEST_PATH).toSerializable(), getRef());
-
-            Object replySerialized =
-                    expectMsgClass(duration("5 seconds"), ReadDataReply.SERIALIZABLE_CLASS);
-
-            assertTrue(ReadDataReply.fromSerializable(replySerialized).getNormalizedNode() == null);
-
-            // unserialized read
-            transaction.tell(new ReadData(TestModel.TEST_PATH),getRef());
+            transaction.tell(new ReadData(TestModel.TEST_PATH, DataStoreVersions.CURRENT_VERSION),getRef());
 
             ReadDataReply reply = expectMsgClass(duration("5 seconds"), ReadDataReply.class);
 
@@ -178,16 +151,8 @@ public class ShardTransactionTest extends AbstractActorTest {
         }
 
         private void testOnReceiveDataExistsPositive(final ActorRef transaction) {
-            transaction.tell(new DataExists(YangInstanceIdentifier.builder().build()).toSerializable(),
-                getRef());
-
-            ShardTransactionMessages.DataExistsReply replySerialized =
-                expectMsgClass(duration("5 seconds"), ShardTransactionMessages.DataExistsReply.class);
-
-            assertTrue(DataExistsReply.fromSerializable(replySerialized).exists());
-
-            // unserialized read
-            transaction.tell(new DataExists(YangInstanceIdentifier.builder().build()),getRef());
+            transaction.tell(new DataExists(YangInstanceIdentifier.EMPTY,
+                    DataStoreVersions.CURRENT_VERSION), getRef());
 
             DataExistsReply reply = expectMsgClass(duration("5 seconds"), DataExistsReply.class);
 
@@ -208,15 +173,7 @@ public class ShardTransactionTest extends AbstractActorTest {
         }
 
         private void testOnReceiveDataExistsNegative(final ActorRef transaction) {
-            transaction.tell(new DataExists(TestModel.TEST_PATH).toSerializable(), getRef());
-
-            ShardTransactionMessages.DataExistsReply replySerialized =
-                expectMsgClass(duration("5 seconds"), ShardTransactionMessages.DataExistsReply.class);
-
-            assertFalse(DataExistsReply.fromSerializable(replySerialized).exists());
-
-            // unserialized read
-            transaction.tell(new DataExists(TestModel.TEST_PATH),getRef());
+            transaction.tell(new DataExists(TestModel.TEST_PATH, DataStoreVersions.CURRENT_VERSION),getRef());
 
             DataExistsReply reply = expectMsgClass(duration("5 seconds"), DataExistsReply.class);
 
@@ -315,7 +272,7 @@ public class ShardTransactionTest extends AbstractActorTest {
             batched.setTotalMessagesSent(1);
 
             transaction.tell(batched, getRef());
-            expectMsgClass(duration("5 seconds"), CommitTransactionReply.SERIALIZABLE_CLASS);
+            expectMsgClass(duration("5 seconds"), CommitTransactionReply.class);
             watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
         }};
     }
@@ -390,7 +347,7 @@ public class ShardTransactionTest extends AbstractActorTest {
                     ImmutableNodes.containerNode(TestModel.TEST_QNAME));
 
             NormalizedNode<?,?> expectedRoot = ShardTest.readStore(store.getDataTree(),
-                    YangInstanceIdentifier.builder().build());
+                    YangInstanceIdentifier.EMPTY);
 
             final ActorRef transaction = newTransactionActor(TransactionType.READ_ONLY, readOnlyTransaction(),
                     "testOnReceiveCreateSnapshot");
@@ -422,7 +379,7 @@ public class ShardTransactionTest extends AbstractActorTest {
 
             transaction.tell(new CloseTransaction().toSerializable(), getRef());
 
-            expectMsgClass(duration("3 seconds"), CloseTransactionReply.SERIALIZABLE_CLASS);
+            expectMsgClass(duration("3 seconds"), CloseTransactionReply.class);
             expectTerminated(duration("3 seconds"), transaction);
         }};
     }
@@ -437,7 +394,7 @@ public class ShardTransactionTest extends AbstractActorTest {
 
             transaction.tell(new CloseTransaction().toSerializable(), getRef());
 
-            expectMsgClass(duration("3 seconds"), CloseTransactionReply.SERIALIZABLE_CLASS);
+            expectMsgClass(duration("3 seconds"), CloseTransactionReply.class);
             expectTerminated(duration("3 seconds"), transaction);
         }};
     }
@@ -460,7 +417,7 @@ public class ShardTransactionTest extends AbstractActorTest {
     public void testNegativePerformingWriteOperationOnReadTransaction() throws Exception {
         final ActorRef shard = createShard();
         final Props props = ShardTransaction.props(TransactionType.READ_ONLY, readOnlyTransaction(), shard,
-                datastoreContext, shardStats, "txn", DataStoreVersions.CURRENT_VERSION);
+                datastoreContext, shardStats, "txn");
         final TestActorRef<ShardTransaction> transaction = TestActorRef.apply(props,getSystem());
 
         transaction.receive(new BatchedModifications("tx1", DataStoreVersions.CURRENT_VERSION, null),
@@ -483,6 +440,35 @@ public class ShardTransactionTest extends AbstractActorTest {
         }};
     }
 
+    @Test
+    public void testOnReceivePreBoronReadData() throws Exception {
+        new JavaTestKit(getSystem()) {{
+            ActorRef transaction = newTransactionActor(RO, readOnlyTransaction(), createShard(),
+                    "testOnReceivePreBoronReadData");
+
+            transaction.tell(new ReadData(YangInstanceIdentifier.EMPTY, DataStoreVersions.LITHIUM_VERSION).
+                    toSerializable(), getRef());
+
+            Object replySerialized = expectMsgClass(duration("5 seconds"), ReadDataReply.class);
+            assertNotNull(ReadDataReply.fromSerializable(replySerialized).getNormalizedNode());
+        }};
+    }
+
+    @Test
+    public void testOnReceivePreBoronDataExists() throws Exception {
+        new JavaTestKit(getSystem()) {{
+            ActorRef transaction = newTransactionActor(RO, readOnlyTransaction(), createShard(),
+                    "testOnReceivePreBoronDataExists");
+
+            transaction.tell(new DataExists(YangInstanceIdentifier.EMPTY, DataStoreVersions.LITHIUM_VERSION).
+                    toSerializable(), getRef());
+
+            Object replySerialized = expectMsgClass(duration("5 seconds"),
+                    ShardTransactionMessages.DataExistsReply.class);
+            assertTrue(DataExistsReply.fromSerializable(replySerialized).exists());
+        }};
+    }
+
     public static class TestException extends RuntimeException {
         private static final long serialVersionUID = 1L;
     }