X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardTransactionTest.java;h=e0b34925ab6116708e7b1f257ca959b815d0079e;hp=630dc3908ead988cd9f06b9a503ac3e082ac1b03;hb=8ec73bf853a9b6708b455c0321a585992e02b125;hpb=11e722671c6dc194761471038a4e3ca5f7fd8970 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 630dc3908e..e0b34925ab 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 @@ -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"); @@ -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 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; }