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=16b73040a5b6e5375a24570fb5b1617240eadb04;hp=86016a677b3f6f357e3ad8cf31c86e174a3a2a3b;hb=63b36aa3537d77bd9be323e1113716ef2cd54098;hpb=f3bc7a6b7d0326e5594604cdc144b967c2a9cdb4 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 86016a677b..16b73040a5 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 @@ -15,9 +15,8 @@ import akka.actor.Props; import akka.testkit.TestActorRef; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; -import org.junit.Assert; import org.junit.Test; -import org.opendaylight.controller.cluster.datastore.messages.DeleteData; +import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier; 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; @@ -30,11 +29,11 @@ import scala.concurrent.duration.Duration; import java.util.Collections; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * Covers negative test cases + * * @author Basheeruddin Ahmed */ public class ShardTransactionFailureTest extends AbstractActorTest { @@ -48,45 +47,21 @@ public class ShardTransactionFailureTest extends AbstractActorTest { private static final SchemaContext testSchemaContext = TestModel.createTestContext(); + private static final ShardIdentifier SHARD_IDENTIFIER = + ShardIdentifier.builder().memberName("member-1") + .shardName("inventory").type("operational").build(); + static { store.onGlobalContextUpdated(testSchemaContext); } - @Test - public void testNegativePerformingWriteOperationOnReadTransaction() - throws Exception { - try { - - final ActorRef - shard = getSystem() - .actorOf(Shard.props("config", Collections.EMPTY_MAP)); - final Props props = - ShardTransaction - .props(store.newReadOnlyTransaction(), shard, TestModel - .createTestContext()); - final TestActorRef subject = TestActorRef.apply(props, getSystem()); - - subject - .receive(new DeleteData(TestModel.TEST_PATH).toSerializable(), - ActorRef.noSender()); - Assert.assertFalse(true); - - - } catch (Exception cs) { - assertEquals(cs.getClass().getSimpleName(), - Exception.class.getSimpleName()); - assertTrue(cs.getMessage().startsWith( - "ShardTransaction:handleRecieve received an unknown message")); - } - } - @Test(expected = ReadFailedException.class) public void testNegativeReadWithReadOnlyTransactionClosed() throws Throwable { final ActorRef shard = - getSystem().actorOf(Shard.props("config", Collections.EMPTY_MAP)); + getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, null)); final Props props = ShardTransaction.props(store.newReadOnlyTransaction(), shard, TestModel.createTestContext()); @@ -121,7 +96,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest { throws Throwable { final ActorRef shard = - getSystem().actorOf(Shard.props("config", Collections.EMPTY_MAP)); + getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, TestModel.createTestContext()); @@ -150,13 +125,47 @@ public class ShardTransactionFailureTest extends AbstractActorTest { } + @Test(expected = ReadFailedException.class) + public void testNegativeExistsWithReadWriteOnlyTransactionClosed() + throws Throwable { + + final ActorRef shard = + getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); + final Props props = + ShardTransaction.props(store.newReadWriteTransaction(), shard, + TestModel.createTestContext()); + + final TestActorRef subject = TestActorRef + .create(getSystem(), props, + "testNegativeExistsWithReadWriteOnlyTransactionClosed"); + + ShardTransactionMessages.DataExists dataExists = + ShardTransactionMessages.DataExists.newBuilder() + .setInstanceIdentifierPathArguments( + NormalizedNodeMessages.InstanceIdentifier.newBuilder() + .build() + ).build(); + + Future future = + akka.pattern.Patterns.ask(subject, dataExists, 3000); + assertTrue(future.isCompleted()); + Await.result(future, Duration.Zero()); + + ((ShardReadWriteTransaction) subject.underlyingActor()) + .forUnitTestOnlyExplicitTransactionClose(); + + future = akka.pattern.Patterns.ask(subject, dataExists, 3000); + Await.result(future, Duration.Zero()); + + + } @Test(expected = IllegalStateException.class) public void testNegativeWriteWithTransactionReady() throws Exception { final ActorRef shard = - getSystem().actorOf(Shard.props("config", Collections.EMPTY_MAP)); + getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); final Props props = ShardTransaction.props(store.newWriteOnlyTransaction(), shard, TestModel.createTestContext()); @@ -195,7 +204,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest { final ActorRef shard = - getSystem().actorOf(Shard.props("config", Collections.EMPTY_MAP)); + getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, TestModel.createTestContext()); @@ -233,7 +242,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest { final ActorRef shard = - getSystem().actorOf(Shard.props("config", Collections.EMPTY_MAP)); + getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, TestModel.createTestContext()); @@ -271,7 +280,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest { final ActorRef shard = - getSystem().actorOf(Shard.props("config", Collections.EMPTY_MAP)); + getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, TestModel.createTestContext());