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%2FShardTransactionFailureTest.java;h=6375e3c7fba51fa02c077ac49d01def5eed5d22a;hp=127f9f55f89f0bedf78e2f748cd116de3819066a;hb=2b99f613b5f2a63bd0579ea6fd47a0db4f5a457e;hpb=945a63ae76181f7cda4b052fa8fcdf115da4cf2d diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java index 127f9f55f8..6375e3c7fb 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java @@ -12,25 +12,26 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorRef; import akka.actor.Props; +import akka.pattern.AskTimeoutException; import akka.testkit.TestActorRef; - import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; - import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier; +import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats; +import org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeSerializer; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; 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.impl.schema.Builders; import org.opendaylight.yangtools.yang.model.api.SchemaContext; - import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; - import java.util.Collections; import java.util.concurrent.TimeUnit; @@ -54,21 +55,27 @@ public class ShardTransactionFailureTest extends AbstractActorTest { ShardIdentifier.builder().memberName("member-1") .shardName("inventory").type("operational").build(); - private final ShardContext shardContext = new ShardContext(); + private final DatastoreContext datastoreContext = DatastoreContext.newBuilder().build(); + + private final ShardStats shardStats = new ShardStats(SHARD_IDENTIFIER.toString(), "DataStore"); @BeforeClass public static void staticSetup() { store.onGlobalContextUpdated(testSchemaContext); } + private ActorRef createShard(){ + return getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, datastoreContext, + TestModel.createTestContext())); + } + @Test(expected = ReadFailedException.class) public void testNegativeReadWithReadOnlyTransactionClosed() throws Throwable { - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, new ShardContext())); + final ActorRef shard = createShard(); final Props props = ShardTransaction.props(store.newReadOnlyTransaction(), shard, - testSchemaContext, shardContext); + testSchemaContext, datastoreContext, shardStats, "txn"); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -95,10 +102,9 @@ public class ShardTransactionFailureTest extends AbstractActorTest { public void testNegativeReadWithReadWriteTransactionClosed() throws Throwable { - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, new ShardContext())); + final ActorRef shard = createShard(); final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, - testSchemaContext, shardContext); + testSchemaContext, datastoreContext, shardStats, "txn"); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -125,10 +131,9 @@ public class ShardTransactionFailureTest extends AbstractActorTest { public void testNegativeExistsWithReadWriteTransactionClosed() throws Throwable { - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, new ShardContext())); + final ActorRef shard = createShard(); final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, - testSchemaContext, shardContext); + testSchemaContext, datastoreContext, shardStats, "txn"); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -151,14 +156,13 @@ public class ShardTransactionFailureTest extends AbstractActorTest { Await.result(future, Duration.create(3, TimeUnit.SECONDS)); } - @Test(expected = IllegalStateException.class) + @Test(expected = AskTimeoutException.class) public void testNegativeWriteWithTransactionReady() throws Exception { - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, new ShardContext())); + final ActorRef shard = createShard(); final Props props = ShardTransaction.props(store.newWriteOnlyTransaction(), shard, - testSchemaContext, shardContext); + testSchemaContext, datastoreContext, shardStats, "txn"); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -176,7 +180,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest { .setInstanceIdentifierPathArguments( NormalizedNodeMessages.InstanceIdentifier.newBuilder() .build()).setNormalizedNode( - NormalizedNodeMessages.Node.newBuilder().build() + buildNormalizedNode() ).build(); @@ -184,14 +188,13 @@ public class ShardTransactionFailureTest extends AbstractActorTest { Await.result(future, Duration.create(3, TimeUnit.SECONDS)); } - @Test(expected = IllegalStateException.class) + @Test(expected = AskTimeoutException.class) public void testNegativeReadWriteWithTransactionReady() throws Exception { - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, new ShardContext())); + final ActorRef shard = createShard(); final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, - testSchemaContext, shardContext); + testSchemaContext, datastoreContext, shardStats, "txn"); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -208,23 +211,27 @@ public class ShardTransactionFailureTest extends AbstractActorTest { ShardTransactionMessages.WriteData.newBuilder() .setInstanceIdentifierPathArguments( NormalizedNodeMessages.InstanceIdentifier.newBuilder() - .build()).setNormalizedNode( - NormalizedNodeMessages.Node.newBuilder().build() - - ).build(); + .build() + ) + .setNormalizedNode(buildNormalizedNode()) + .build(); future = akka.pattern.Patterns.ask(subject, writeData, 3000); Await.result(future, Duration.create(3, TimeUnit.SECONDS)); } - @Test(expected = IllegalStateException.class) + private NormalizedNodeMessages.Node buildNormalizedNode() { + return NormalizedNodeSerializer + .serialize(Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).build()); + } + + @Test(expected = AskTimeoutException.class) public void testNegativeMergeTransactionReady() throws Exception { - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, new ShardContext())); + final ActorRef shard = createShard(); final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, - testSchemaContext, shardContext); + testSchemaContext, datastoreContext, shardStats, "txn"); final TestActorRef subject = TestActorRef .create(getSystem(), props, "testNegativeMergeTransactionReady"); @@ -241,7 +248,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest { .setInstanceIdentifierPathArguments( NormalizedNodeMessages.InstanceIdentifier.newBuilder() .build()).setNormalizedNode( - NormalizedNodeMessages.Node.newBuilder().build() + buildNormalizedNode() ).build(); @@ -250,14 +257,13 @@ public class ShardTransactionFailureTest extends AbstractActorTest { } - @Test(expected = IllegalStateException.class) + @Test(expected = AskTimeoutException.class) public void testNegativeDeleteDataWhenTransactionReady() throws Exception { - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, new ShardContext())); + final ActorRef shard = createShard(); final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, - testSchemaContext, shardContext); + testSchemaContext, datastoreContext, shardStats, "txn"); final TestActorRef subject = TestActorRef .create(getSystem(), props,