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%2FShardTransactionTest.java;h=73c81fe9b7b2a42181c6a045b1bb5402b8347f3f;hb=9412c00daf7c8c3f108d1284a6288753ba67f6ac;hp=ae9694a8572b7c71303a437558b204fd6e6f959b;hpb=28b2fd303b8e8bc757de6ead454ae06469113b34;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java index ae9694a857..73c81fe9b7 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java @@ -34,20 +34,12 @@ import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionR import org.opendaylight.controller.cluster.datastore.messages.CreateSnapshot; import org.opendaylight.controller.cluster.datastore.messages.DataExists; import org.opendaylight.controller.cluster.datastore.messages.DataExistsReply; -import org.opendaylight.controller.cluster.datastore.messages.DeleteData; -import org.opendaylight.controller.cluster.datastore.messages.DeleteDataReply; -import org.opendaylight.controller.cluster.datastore.messages.MergeData; -import org.opendaylight.controller.cluster.datastore.messages.MergeDataReply; import org.opendaylight.controller.cluster.datastore.messages.ReadData; import org.opendaylight.controller.cluster.datastore.messages.ReadDataReply; import org.opendaylight.controller.cluster.datastore.messages.ReadyTransactionReply; -import org.opendaylight.controller.cluster.datastore.messages.WriteData; -import org.opendaylight.controller.cluster.datastore.messages.WriteDataReply; import org.opendaylight.controller.cluster.datastore.modification.DeleteModification; import org.opendaylight.controller.cluster.datastore.modification.MergeModification; import org.opendaylight.controller.cluster.datastore.modification.WriteModification; -import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec; -import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Encoded; import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils; import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; @@ -125,17 +117,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.builder().build(), + DataStoreVersions.CURRENT_VERSION),getRef()); ReadDataReply reply = expectMsgClass(duration("5 seconds"), ReadDataReply.class); @@ -156,16 +139,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); @@ -173,22 +147,6 @@ public class ShardTransactionTest extends AbstractActorTest { }}; } - @Test - public void testOnReceiveReadDataHeliumR1() throws Exception { - new JavaTestKit(getSystem()) {{ - ActorRef transaction = newTransactionActor(RO, readOnlyTransaction(), - "testOnReceiveReadDataHeliumR1", DataStoreVersions.HELIUM_1_VERSION); - - transaction.tell(new ReadData(YangInstanceIdentifier.builder().build()).toSerializable(), - getRef()); - - ShardTransactionMessages.ReadDataReply replySerialized = - expectMsgClass(duration("5 seconds"), ShardTransactionMessages.ReadDataReply.class); - - assertNotNull(ReadDataReply.fromSerializable(replySerialized).getNormalizedNode()); - }}; - } - @Test public void testOnReceiveDataExistsPositive() throws Exception { new JavaTestKit(getSystem()) {{ @@ -202,16 +160,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.builder().build(), + DataStoreVersions.CURRENT_VERSION),getRef()); DataExistsReply reply = expectMsgClass(duration("5 seconds"), DataExistsReply.class); @@ -232,15 +182,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); @@ -248,102 +190,6 @@ public class ShardTransactionTest extends AbstractActorTest { }}; } - @Test - public void testOnReceiveWriteData() { - new JavaTestKit(getSystem()) {{ - final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), - "testOnReceiveWriteData"); - - transaction.tell(new WriteData(TestModel.TEST_PATH, - ImmutableNodes.containerNode(TestModel.TEST_QNAME), DataStoreVersions.HELIUM_2_VERSION). - toSerializable(), getRef()); - - expectMsgClass(duration("5 seconds"), ShardTransactionMessages.WriteDataReply.class); - - // unserialized write - transaction.tell(new WriteData(TestModel.TEST_PATH, - ImmutableNodes.containerNode(TestModel.TEST_QNAME), DataStoreVersions.CURRENT_VERSION), - getRef()); - - expectMsgClass(duration("5 seconds"), WriteDataReply.class); - }}; - } - - @Test - public void testOnReceiveHeliumR1WriteData() { - new JavaTestKit(getSystem()) {{ - final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), - "testOnReceiveHeliumR1WriteData", DataStoreVersions.HELIUM_1_VERSION); - - Encoded encoded = new NormalizedNodeToNodeCodec(null).encode(TestModel.TEST_PATH, - ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - ShardTransactionMessages.WriteData serialized = ShardTransactionMessages.WriteData.newBuilder() - .setInstanceIdentifierPathArguments(encoded.getEncodedPath()) - .setNormalizedNode(encoded.getEncodedNode().getNormalizedNode()).build(); - - transaction.tell(serialized, getRef()); - - expectMsgClass(duration("5 seconds"), ShardTransactionMessages.WriteDataReply.class); - }}; - } - - @Test - public void testOnReceiveMergeData() { - new JavaTestKit(getSystem()) {{ - final ActorRef transaction = newTransactionActor(RW, readWriteTransaction(), - "testMergeData"); - - transaction.tell(new MergeData(TestModel.TEST_PATH, - ImmutableNodes.containerNode(TestModel.TEST_QNAME), DataStoreVersions.HELIUM_2_VERSION). - toSerializable(), getRef()); - - expectMsgClass(duration("5 seconds"), ShardTransactionMessages.MergeDataReply.class); - - //unserialized merge - transaction.tell(new MergeData(TestModel.TEST_PATH, - ImmutableNodes.containerNode(TestModel.TEST_QNAME), DataStoreVersions.CURRENT_VERSION), - getRef()); - - expectMsgClass(duration("5 seconds"), MergeDataReply.class); - }}; - } - - @Test - public void testOnReceiveHeliumR1MergeData() throws Exception { - new JavaTestKit(getSystem()) {{ - final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), - "testOnReceiveHeliumR1MergeData", DataStoreVersions.HELIUM_1_VERSION); - - Encoded encoded = new NormalizedNodeToNodeCodec(null).encode(TestModel.TEST_PATH, - ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - ShardTransactionMessages.MergeData serialized = ShardTransactionMessages.MergeData.newBuilder() - .setInstanceIdentifierPathArguments(encoded.getEncodedPath()) - .setNormalizedNode(encoded.getEncodedNode().getNormalizedNode()).build(); - - transaction.tell(serialized, getRef()); - - expectMsgClass(duration("5 seconds"), ShardTransactionMessages.MergeDataReply.class); - }}; - } - - @Test - public void testOnReceiveDeleteData() throws Exception { - new JavaTestKit(getSystem()) {{ - final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), - "testDeleteData"); - - transaction.tell(new DeleteData(TestModel.TEST_PATH, DataStoreVersions.HELIUM_2_VERSION). - toSerializable(), getRef()); - - expectMsgClass(duration("5 seconds"), ShardTransactionMessages.DeleteDataReply.class); - - //unserialized - transaction.tell(new DeleteData(TestModel.TEST_PATH, DataStoreVersions.CURRENT_VERSION), getRef()); - - expectMsgClass(duration("5 seconds"), DeleteDataReply.class); - }}; - } - @Test public void testOnReceiveBatchedModifications() throws Exception { new JavaTestKit(getSystem()) {{ @@ -435,7 +281,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); }}; } @@ -542,7 +388,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); }}; } @@ -557,7 +403,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); }}; } @@ -583,8 +429,8 @@ public class ShardTransactionTest extends AbstractActorTest { datastoreContext, shardStats, "txn", DataStoreVersions.CURRENT_VERSION); final TestActorRef transaction = TestActorRef.apply(props,getSystem()); - transaction.receive(new DeleteData(TestModel.TEST_PATH, DataStoreVersions.CURRENT_VERSION). - toSerializable(), ActorRef.noSender()); + transaction.receive(new BatchedModifications("tx1", DataStoreVersions.CURRENT_VERSION, null), + ActorRef.noSender()); } @Test @@ -603,6 +449,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; }