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%2FBasicIntegrationTest.java;fp=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FBasicIntegrationTest.java;h=74c858e4a6b329ccb6536ddd7f4a1d42bec2885e;hp=8c3ec82a54eb7c50d195675cffc122b6ed13d546;hb=85a32885f57edce51d54021a8060be0e1f9aa45b;hpb=eb095e9201b6279355aac5a1ba3252dbd8564358 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/BasicIntegrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/BasicIntegrationTest.java index 8c3ec82a54..74c858e4a6 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/BasicIntegrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/BasicIntegrationTest.java @@ -12,6 +12,7 @@ import akka.actor.ActorPath; import akka.actor.ActorRef; import akka.actor.ActorSelection; import akka.actor.Props; +import akka.actor.Terminated; import akka.testkit.JavaTestKit; import junit.framework.Assert; import org.junit.Test; @@ -30,11 +31,14 @@ import org.opendaylight.controller.cluster.datastore.messages.WriteData; import org.opendaylight.controller.cluster.datastore.messages.WriteDataReply; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import scala.concurrent.Await; +import scala.concurrent.Future; +import scala.concurrent.duration.FiniteDuration; public class BasicIntegrationTest extends AbstractActorTest { @Test - public void integrationTest() { + public void integrationTest() throws Exception{ // This test will // - create a Shard // - initiate a transaction @@ -57,7 +61,7 @@ public class BasicIntegrationTest extends AbstractActorTest { shard.tell(new CreateTransactionChain(), getRef()); final ActorSelection transactionChain = - new ExpectMsg("match hint") { + new ExpectMsg("CreateTransactionChainReply") { protected ActorSelection match(Object in) { if (in instanceof CreateTransactionChainReply) { ActorPath transactionChainPath = @@ -76,7 +80,7 @@ public class BasicIntegrationTest extends AbstractActorTest { transactionChain.tell(new CreateTransaction(), getRef()); final ActorSelection transaction = - new ExpectMsg("match hint") { + new ExpectMsg("CreateTransactionReply") { protected ActorSelection match(Object in) { if (in instanceof CreateTransactionReply) { ActorPath transactionPath = @@ -92,11 +96,14 @@ public class BasicIntegrationTest extends AbstractActorTest { Assert.assertNotNull(transaction); + // Add a watch on the transaction actor so that we are notified when it dies + final ActorRef transactionActorRef = watchActor(transaction); + transaction.tell(new WriteData(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)), getRef()); - Boolean writeDone = new ExpectMsg("match hint") { + Boolean writeDone = new ExpectMsg("WriteDataReply") { protected Boolean match(Object in) { if (in instanceof WriteDataReply) { return true; @@ -111,7 +118,7 @@ public class BasicIntegrationTest extends AbstractActorTest { transaction.tell(new ReadyTransaction(), getRef()); final ActorSelection cohort = - new ExpectMsg("match hint") { + new ExpectMsg("ReadyTransactionReply") { protected ActorSelection match(Object in) { if (in instanceof ReadyTransactionReply) { ActorPath cohortPath = @@ -127,10 +134,13 @@ public class BasicIntegrationTest extends AbstractActorTest { Assert.assertNotNull(cohort); + // Add a watch on the transaction actor so that we are notified when it dies + final ActorRef cohorActorRef = watchActor(cohort); + cohort.tell(new PreCommitTransaction(), getRef()); Boolean preCommitDone = - new ExpectMsg("match hint") { + new ExpectMsg("PreCommitTransactionReply") { protected Boolean match(Object in) { if (in instanceof PreCommitTransactionReply) { return true; @@ -144,8 +154,35 @@ public class BasicIntegrationTest extends AbstractActorTest { cohort.tell(new CommitTransaction(), getRef()); + final Boolean terminatedCohort = + new ExpectMsg("Terminated Cohort") { + protected Boolean match(Object in) { + if (in instanceof Terminated) { + return cohorActorRef.equals(((Terminated) in).actor()); + } else { + throw noMatch(); + } + } + }.get(); // this extracts the received message + + Assert.assertTrue(terminatedCohort); + + + final Boolean terminatedTransaction = + new ExpectMsg("Terminated Transaction") { + protected Boolean match(Object in) { + if (in instanceof Terminated) { + return transactionActorRef.equals(((Terminated) in).actor()); + } else { + throw noMatch(); + } + } + }.get(); // this extracts the received message + + Assert.assertTrue(terminatedTransaction); + final Boolean commitDone = - new ExpectMsg("match hint") { + new ExpectMsg("CommitTransactionReply") { protected Boolean match(Object in) { if (in instanceof CommitTransactionReply) { return true; @@ -161,7 +198,25 @@ public class BasicIntegrationTest extends AbstractActorTest { }; - }}; + } + + private ActorRef watchActor(ActorSelection actor) { + Future future = actor + .resolveOne(FiniteDuration.apply(100, "milliseconds")); + + try { + ActorRef actorRef = Await.result(future, + FiniteDuration.apply(100, "milliseconds")); + + watch(actorRef); + + return actorRef; + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + }; }