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;h=e275bc5f12e9507d923b1757930b4f0d42333085;hp=8c3ec82a54eb7c50d195675cffc122b6ed13d546;hb=12a178609f39e8c73856fc640813cfda9f058167;hpb=da6ca13e3f8ecb73a62f7e8f9ae3bdcae9d851f8 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..e275bc5f12 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 = @@ -73,17 +77,16 @@ public class BasicIntegrationTest extends AbstractActorTest { Assert.assertNotNull(transactionChain); - transactionChain.tell(new CreateTransaction(), getRef()); + transactionChain.tell(new CreateTransaction("txn-1"), getRef()); final ActorSelection transaction = - new ExpectMsg("match hint") { + new ExpectMsg("CreateTransactionReply") { protected ActorSelection match(Object in) { - if (in instanceof CreateTransactionReply) { - ActorPath transactionPath = - ((CreateTransactionReply) in) - .getTransactionPath(); + if (CreateTransactionReply.SERIALIZABLE_CLASS.equals(in.getClass())) { + CreateTransactionReply reply = CreateTransactionReply.fromSerializable(in); return getSystem() - .actorSelection(transactionPath); + .actorSelection(reply + .getTransactionPath()); } else { throw noMatch(); } @@ -92,11 +95,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)), + ImmutableNodes.containerNode(TestModel.TEST_QNAME), TestModel.createTestContext()).toSerializable(), 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 +117,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 +133,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; @@ -142,10 +151,41 @@ public class BasicIntegrationTest extends AbstractActorTest { Assert.assertTrue(preCommitDone); + // FIXME : When we commit on the cohort it "kills" the Transaction. + // This in turn kills the child of Transaction as well. + // The order in which we receive the terminated event for both + // these actors is not fixed which may cause this test to fail 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 +201,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); + } + + } + }; }