X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FBasicIntegrationTest.java;h=6599bd8eeb0d0b0b54d9058086d836fb82aa214a;hb=b725fdb758008195a98f7fad0fd3804c363170aa;hp=b62a4b36d5016a00b2b86ae54d1623a3ea76aba5;hpb=ed693440aa741fee9b94447f8404d89b4020f616;p=controller.git 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 b62a4b36d5..6599bd8eeb 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.event.Logging; import akka.testkit.JavaTestKit; import junit.framework.Assert; import org.junit.Test; @@ -33,6 +34,10 @@ import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.FiniteDuration; +import java.util.Collections; + +import static junit.framework.Assert.assertEquals; + public class BasicIntegrationTest extends AbstractActorTest { @Test @@ -47,20 +52,36 @@ public class BasicIntegrationTest extends AbstractActorTest { new JavaTestKit(getSystem()) {{ - final Props props = Shard.props("config"); + final Props props = Shard.props("config", Collections.EMPTY_MAP); final ActorRef shard = getSystem().actorOf(props); new Within(duration("5 seconds")) { protected void run() { + shard.tell( new UpdateSchemaContext(TestModel.createTestContext()), getRef()); + + // Wait for a specific log message to show up + final boolean result = + new JavaTestKit.EventFilter(Logging.Info.class + ) { + protected Boolean run() { + return true; + } + }.from(shard.path().toString()) + .message("Switching from state Candidate to Leader") + .occurrences(1).exec(); + + assertEquals(true, result); + + // 1. Create a TransactionChain shard.tell(new CreateTransactionChain().toSerializable(), getRef()); final ActorSelection transactionChain = - new ExpectMsg("CreateTransactionChainReply") { + new ExpectMsg(duration("1 seconds"), "CreateTransactionChainReply") { protected ActorSelection match(Object in) { if (in.getClass().equals(CreateTransactionChainReply.SERIALIZABLE_CLASS)) { ActorPath transactionChainPath = @@ -76,10 +97,13 @@ public class BasicIntegrationTest extends AbstractActorTest { Assert.assertNotNull(transactionChain); - transactionChain.tell(new CreateTransaction("txn-1").toSerializable(), getRef()); + System.out.println("Successfully created transaction chain"); + + // 2. Create a Transaction on the TransactionChain + transactionChain.tell(new CreateTransaction("txn-1", TransactionProxy.TransactionType.WRITE_ONLY.ordinal() ).toSerializable(), getRef()); final ActorSelection transaction = - new ExpectMsg("CreateTransactionReply") { + new ExpectMsg(duration("1 seconds"), "CreateTransactionReply") { protected ActorSelection match(Object in) { if (CreateTransactionReply.SERIALIZABLE_CLASS.equals(in.getClass())) { CreateTransactionReply reply = CreateTransactionReply.fromSerializable(in); @@ -94,14 +118,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); + System.out.println("Successfully created transaction"); + // 3. Write some data transaction.tell(new WriteData(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), TestModel.createTestContext()).toSerializable(), getRef()); - Boolean writeDone = new ExpectMsg("WriteDataReply") { + Boolean writeDone = new ExpectMsg(duration("1 seconds"), "WriteDataReply") { protected Boolean match(Object in) { if (in.getClass().equals(WriteDataReply.SERIALIZABLE_CLASS)) { return true; @@ -113,10 +137,14 @@ public class BasicIntegrationTest extends AbstractActorTest { Assert.assertTrue(writeDone); + System.out.println("Successfully wrote data"); + + // 4. Ready the transaction for commit + transaction.tell(new ReadyTransaction().toSerializable(), getRef()); final ActorSelection cohort = - new ExpectMsg("ReadyTransactionReply") { + new ExpectMsg(duration("1 seconds"), "ReadyTransactionReply") { protected ActorSelection match(Object in) { if (in.getClass().equals(ReadyTransactionReply.SERIALIZABLE_CLASS)) { ActorPath cohortPath = @@ -132,13 +160,14 @@ 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); + System.out.println("Successfully readied the transaction"); + + // 5. PreCommit the transaction cohort.tell(new PreCommitTransaction().toSerializable(), getRef()); Boolean preCommitDone = - new ExpectMsg("PreCommitTransactionReply") { + new ExpectMsg(duration("1 seconds"), "PreCommitTransactionReply") { protected Boolean match(Object in) { if (in.getClass().equals(PreCommitTransactionReply.SERIALIZABLE_CLASS)) { return true; @@ -150,10 +179,14 @@ public class BasicIntegrationTest extends AbstractActorTest { Assert.assertTrue(preCommitDone); + System.out.println("Successfully pre-committed the transaction"); + + // 6. Commit the transaction cohort.tell(new CommitTransaction().toSerializable(), getRef()); // FIXME : Add assertions that the commit worked and that the cohort and transaction actors were terminated + System.out.println("TODO : Check Successfully committed the transaction"); }