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=7b826302f588ad76be85f54c9e17bcc1c8dff56a;hp=dfefc5ed579b36163f882485f38f577b53832b8e;hb=4c22825994c2519fb1c9d63f0050ebf35c4f8439;hpb=55e562009629fcc7163f1f05261de4b2ce4b1e77 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 dfefc5ed57..7b826302f5 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,15 +12,12 @@ import akka.actor.ActorPath; import akka.actor.ActorRef; import akka.actor.ActorSelection; import akka.actor.Props; -import akka.actor.Terminated; +import akka.event.Logging; import akka.testkit.JavaTestKit; -import junit.framework.Assert; import org.junit.Test; +import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier; import org.opendaylight.controller.cluster.datastore.messages.CommitTransaction; -import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply; import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction; -import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChain; -import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChainReply; import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply; import org.opendaylight.controller.cluster.datastore.messages.PreCommitTransaction; import org.opendaylight.controller.cluster.datastore.messages.PreCommitTransactionReply; @@ -31,14 +28,22 @@ 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 org.opendaylight.yangtools.yang.model.api.SchemaContext; import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.FiniteDuration; +import java.util.Collections; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; + public class BasicIntegrationTest extends AbstractActorTest { @Test public void integrationTest() throws Exception{ + // System.setProperty("shard.persistent", "true"); // This test will // - create a Shard // - initiate a transaction @@ -48,64 +53,67 @@ public class BasicIntegrationTest extends AbstractActorTest { new JavaTestKit(getSystem()) {{ - final Props props = Shard.props("config"); + final ShardIdentifier identifier = + ShardIdentifier.builder().memberName("member-1") + .shardName("inventory").type("config").build(); + + final SchemaContext schemaContext = TestModel.createTestContext(); + DatastoreContext datastoreContext = new DatastoreContext(); + + final Props props = Shard.props(identifier, Collections.EMPTY_MAP, datastoreContext, TestModel.createTestContext()); final ActorRef shard = getSystem().actorOf(props); - new Within(duration("5 seconds")) { + new Within(duration("10 seconds")) { + @Override protected void run() { + shard.tell(new UpdateSchemaContext(schemaContext), getRef()); - shard.tell( - new UpdateSchemaContext(TestModel.createTestContext()), - getRef()); - - shard.tell(new CreateTransactionChain(), getRef()); - final ActorSelection transactionChain = - new ExpectMsg("CreateTransactionChainReply") { - protected ActorSelection match(Object in) { - if (in instanceof CreateTransactionChainReply) { - ActorPath transactionChainPath = - ((CreateTransactionChainReply) in) - .getTransactionChainPath(); - return getSystem() - .actorSelection(transactionChainPath); - } else { - throw noMatch(); - } + // Wait for a specific log message to show up + final boolean result = + new JavaTestKit.EventFilter(Logging.Info.class + ) { + @Override + protected Boolean run() { + return true; } - }.get(); // this extracts the received message + }.from(shard.path().toString()) + .message("Switching from state Candidate to Leader") + .occurrences(1).exec(); - Assert.assertNotNull(transactionChain); + assertEquals(true, result); - transactionChain.tell(new CreateTransaction("txn-1"), getRef()); + // Create a transaction on the shard + shard.tell(new CreateTransaction("txn-1", TransactionProxy.TransactionType.WRITE_ONLY.ordinal() ).toSerializable(), getRef()); final ActorSelection transaction = - new ExpectMsg("CreateTransactionReply") { + new ExpectMsg(duration("3 seconds"), "CreateTransactionReply") { + @Override 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(); } } }.get(); // this extracts the received message - Assert.assertNotNull(transaction); + 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)), + ImmutableNodes.containerNode(TestModel.TEST_QNAME), schemaContext).toSerializable(), getRef()); - Boolean writeDone = new ExpectMsg("WriteDataReply") { + Boolean writeDone = new ExpectMsg(duration("3 seconds"), "WriteDataReply") { + @Override protected Boolean match(Object in) { - if (in instanceof WriteDataReply) { + if (in.getClass().equals(WriteDataReply.SERIALIZABLE_CLASS)) { return true; } else { throw noMatch(); @@ -113,16 +121,21 @@ public class BasicIntegrationTest extends AbstractActorTest { } }.get(); // this extracts the received message - Assert.assertTrue(writeDone); + assertTrue(writeDone); + + System.out.println("Successfully wrote data"); + + // 4. Ready the transaction for commit - transaction.tell(new ReadyTransaction(), getRef()); + transaction.tell(new ReadyTransaction().toSerializable(), getRef()); final ActorSelection cohort = - new ExpectMsg("ReadyTransactionReply") { + new ExpectMsg(duration("3 seconds"), "ReadyTransactionReply") { + @Override protected ActorSelection match(Object in) { - if (in instanceof ReadyTransactionReply) { + if (in.getClass().equals(ReadyTransactionReply.SERIALIZABLE_CLASS)) { ActorPath cohortPath = - ((ReadyTransactionReply) in) + ReadyTransactionReply.fromSerializable(getSystem(),in) .getCohortPath(); return getSystem() .actorSelection(cohortPath); @@ -132,17 +145,19 @@ public class BasicIntegrationTest extends AbstractActorTest { } }.get(); // this extracts the received message - Assert.assertNotNull(cohort); + 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"); - cohort.tell(new PreCommitTransaction(), getRef()); + // 5. PreCommit the transaction + + cohort.tell(new PreCommitTransaction().toSerializable(), getRef()); Boolean preCommitDone = - new ExpectMsg("PreCommitTransactionReply") { + new ExpectMsg(duration("3 seconds"), "PreCommitTransactionReply") { + @Override protected Boolean match(Object in) { - if (in instanceof PreCommitTransactionReply) { + if (in.getClass().equals(PreCommitTransactionReply.SERIALIZABLE_CLASS)) { return true; } else { throw noMatch(); @@ -150,54 +165,16 @@ public class BasicIntegrationTest extends AbstractActorTest { } }.get(); // this extracts the received message - 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 + assertTrue(preCommitDone); - Assert.assertTrue(terminatedTransaction); + System.out.println("Successfully pre-committed the transaction"); - final Boolean commitDone = - new ExpectMsg("CommitTransactionReply") { - protected Boolean match(Object in) { - if (in instanceof CommitTransactionReply) { - return true; - } else { - throw noMatch(); - } - } - }.get(); // this extracts the received message + // 6. Commit the transaction + cohort.tell(new CommitTransaction().toSerializable(), getRef()); - Assert.assertTrue(commitDone); + // 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"); }