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%2FShardTransactionChainTest.java;h=c5968c358f87824f3819edf739c5f9cdafcbb664;hp=d468af6664981d08ad603b1a841fefbdaccc8d47;hb=76cc965bd2d9978fedcbe19603c98e7752abf5a8;hpb=d7ce7c5acee7e6f7cd7895ceff5af63ac53789ad diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChainTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChainTest.java index d468af6664..c5968c358f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChainTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChainTest.java @@ -3,96 +3,113 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorRef; import akka.actor.Props; import akka.testkit.JavaTestKit; + import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; + +import org.junit.BeforeClass; import org.junit.Test; +import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats; import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChain; import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChainReply; import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction; import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import static org.junit.Assert.assertEquals; public class ShardTransactionChainTest extends AbstractActorTest { - private static ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor()); - - private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", storeExecutor, - MoreExecutors.sameThreadExecutor()); - - static { - store.onGlobalContextUpdated(TestModel.createTestContext()); - } - @Test - public void testOnReceiveCreateTransaction() throws Exception { - new JavaTestKit(getSystem()) {{ - final Props props = ShardTransactionChain.props(store.createTransactionChain(), TestModel.createTestContext()); - final ActorRef subject = getSystem().actorOf(props, "testCreateTransaction"); - - new Within(duration("1 seconds")) { - @Override - protected void run() { - - subject.tell(new CreateTransaction("txn-1", TransactionProxy.TransactionType.READ_ONLY.ordinal() ).toSerializable(), getRef()); - - final String out = new ExpectMsg(duration("1 seconds"), "match hint") { - // do not put code outside this method, will run afterwards - @Override - protected String match(Object in) { - if (in.getClass().equals(CreateTransactionReply.SERIALIZABLE_CLASS)) { - return CreateTransactionReply.fromSerializable(in).getTransactionPath(); - }else{ - throw noMatch(); - } - } - }.get(); // this extracts the received message - - assertEquals("Unexpected transaction path " + out, - "akka://test/user/testCreateTransaction/shard-txn-1", - out); - - // Will wait for the rest of the 3 seconds - expectNoMsg(); - } - - - }; - }}; - } - - @Test - public void testOnReceiveCloseTransactionChain() throws Exception { - new JavaTestKit(getSystem()) {{ - final Props props = ShardTransactionChain.props(store.createTransactionChain(), TestModel.createTestContext()); - final ActorRef subject = getSystem().actorOf(props, "testCloseTransactionChain"); - - new Within(duration("1 seconds")) { - @Override - protected void run() { - - subject.tell(new CloseTransactionChain().toSerializable(), getRef()); - - final String out = new ExpectMsg(duration("1 seconds"), "match hint") { - // do not put code outside this method, will run afterwards - @Override - protected String match(Object in) { - if (in.getClass().equals(CloseTransactionChainReply.SERIALIZABLE_CLASS)) { - return "match"; - } else { - throw noMatch(); - } - } - }.get(); // this extracts the received message - - assertEquals("match", out); - // Will wait for the rest of the 3 seconds - expectNoMsg(); - } - - - }; - }}; - } + private static ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor()); + + private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", storeExecutor, + MoreExecutors.sameThreadExecutor()); + + private static final SchemaContext testSchemaContext = TestModel.createTestContext(); + + private static final DatastoreContext DATA_STORE_CONTEXT = new DatastoreContext(); + + private static final String mockShardName = "mockShardName"; + + private final ShardStats shardStats = new ShardStats(mockShardName, "DataStore"); + + @BeforeClass + public static void staticSetup() { + store.onGlobalContextUpdated(testSchemaContext); + } + + @Test + public void testOnReceiveCreateTransaction() throws Exception { + new JavaTestKit(getSystem()) {{ + final Props props = ShardTransactionChain.props(store.createTransactionChain(), + testSchemaContext, DATA_STORE_CONTEXT, shardStats); + final ActorRef subject = getSystem().actorOf(props, "testCreateTransaction"); + + new Within(duration("1 seconds")) { + @Override + protected void run() { + + subject.tell(new CreateTransaction("txn-1", TransactionProxy.TransactionType.READ_ONLY.ordinal() ).toSerializable(), getRef()); + + final String out = new ExpectMsg(duration("1 seconds"), "match hint") { + // do not put code outside this method, will run afterwards + @Override + protected String match(Object in) { + if (in.getClass().equals(CreateTransactionReply.SERIALIZABLE_CLASS)) { + return CreateTransactionReply.fromSerializable(in).getTransactionPath(); + }else{ + throw noMatch(); + } + } + }.get(); // this extracts the received message + + assertEquals("Unexpected transaction path " + out, + "akka://test/user/testCreateTransaction/shard-txn-1", + out); + + // Will wait for the rest of the 3 seconds + expectNoMsg(); + } + + + }; + }}; + } + + @Test + public void testOnReceiveCloseTransactionChain() throws Exception { + new JavaTestKit(getSystem()) {{ + final Props props = ShardTransactionChain.props(store.createTransactionChain(), + testSchemaContext, DATA_STORE_CONTEXT, shardStats ); + final ActorRef subject = getSystem().actorOf(props, "testCloseTransactionChain"); + + new Within(duration("1 seconds")) { + @Override + protected void run() { + + subject.tell(new CloseTransactionChain().toSerializable(), getRef()); + + final String out = new ExpectMsg(duration("1 seconds"), "match hint") { + // do not put code outside this method, will run afterwards + @Override + protected String match(Object in) { + if (in.getClass().equals(CloseTransactionChainReply.SERIALIZABLE_CLASS)) { + return "match"; + } else { + throw noMatch(); + } + } + }.get(); // this extracts the received message + + assertEquals("match", out); + // Will wait for the rest of the 3 seconds + expectNoMsg(); + } + + + }; + }}; + } }