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=8c3ec82a54eb7c50d195675cffc122b6ed13d546;hp=0000000000000000000000000000000000000000;hb=da6ca13e3f8ecb73a62f7e8f9ae3bdcae9d851f8;hpb=324c96119dec46d0fee5e641f0a26caac478c23b 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 new file mode 100644 index 0000000000..8c3ec82a54 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/BasicIntegrationTest.java @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.cluster.datastore; + +import akka.actor.ActorPath; +import akka.actor.ActorRef; +import akka.actor.ActorSelection; +import akka.actor.Props; +import akka.testkit.JavaTestKit; +import junit.framework.Assert; +import org.junit.Test; +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; +import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction; +import org.opendaylight.controller.cluster.datastore.messages.ReadyTransactionReply; +import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext; +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; + +public class BasicIntegrationTest extends AbstractActorTest { + + @Test + public void integrationTest() { + // This test will + // - create a Shard + // - initiate a transaction + // - write something + // - read the transaction for commit + // - commit the transaction + + + new JavaTestKit(getSystem()) {{ + final Props props = Shard.props("config"); + final ActorRef shard = getSystem().actorOf(props); + + new Within(duration("5 seconds")) { + protected void run() { + + shard.tell( + new UpdateSchemaContext(TestModel.createTestContext()), + getRef()); + + shard.tell(new CreateTransactionChain(), getRef()); + + final ActorSelection transactionChain = + new ExpectMsg("match hint") { + protected ActorSelection match(Object in) { + if (in instanceof CreateTransactionChainReply) { + ActorPath transactionChainPath = + ((CreateTransactionChainReply) in) + .getTransactionChainPath(); + return getSystem() + .actorSelection(transactionChainPath); + } else { + throw noMatch(); + } + } + }.get(); // this extracts the received message + + Assert.assertNotNull(transactionChain); + + transactionChain.tell(new CreateTransaction(), getRef()); + + final ActorSelection transaction = + new ExpectMsg("match hint") { + protected ActorSelection match(Object in) { + if (in instanceof CreateTransactionReply) { + ActorPath transactionPath = + ((CreateTransactionReply) in) + .getTransactionPath(); + return getSystem() + .actorSelection(transactionPath); + } else { + throw noMatch(); + } + } + }.get(); // this extracts the received message + + Assert.assertNotNull(transaction); + + transaction.tell(new WriteData(TestModel.TEST_PATH, + ImmutableNodes.containerNode(TestModel.TEST_QNAME)), + getRef()); + + Boolean writeDone = new ExpectMsg("match hint") { + protected Boolean match(Object in) { + if (in instanceof WriteDataReply) { + return true; + } else { + throw noMatch(); + } + } + }.get(); // this extracts the received message + + Assert.assertTrue(writeDone); + + transaction.tell(new ReadyTransaction(), getRef()); + + final ActorSelection cohort = + new ExpectMsg("match hint") { + protected ActorSelection match(Object in) { + if (in instanceof ReadyTransactionReply) { + ActorPath cohortPath = + ((ReadyTransactionReply) in) + .getCohortPath(); + return getSystem() + .actorSelection(cohortPath); + } else { + throw noMatch(); + } + } + }.get(); // this extracts the received message + + Assert.assertNotNull(cohort); + + cohort.tell(new PreCommitTransaction(), getRef()); + + Boolean preCommitDone = + new ExpectMsg("match hint") { + protected Boolean match(Object in) { + if (in instanceof PreCommitTransactionReply) { + return true; + } else { + throw noMatch(); + } + } + }.get(); // this extracts the received message + + Assert.assertTrue(preCommitDone); + + cohort.tell(new CommitTransaction(), getRef()); + + final Boolean commitDone = + new ExpectMsg("match hint") { + protected Boolean match(Object in) { + if (in instanceof CommitTransactionReply) { + return true; + } else { + throw noMatch(); + } + } + }.get(); // this extracts the received message + + Assert.assertTrue(commitDone); + + } + + + }; + }}; + + + } +}