1 package org.opendaylight.controller.cluster.datastore;
3 import akka.actor.ActorRef;
4 import akka.actor.Props;
5 import akka.testkit.JavaTestKit;
6 import com.google.common.util.concurrent.ListeningExecutorService;
7 import com.google.common.util.concurrent.MoreExecutors;
9 import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChain;
10 import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChainReply;
11 import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
12 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply;
13 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
14 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
16 import static org.junit.Assert.assertEquals;
18 public class ShardTransactionChainTest extends AbstractActorTest {
20 private static ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor());
22 private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", storeExecutor);
25 store.onGlobalContextUpdated(TestModel.createTestContext());
28 public void testOnReceiveCreateTransaction() throws Exception {
29 new JavaTestKit(getSystem()) {{
30 final Props props = ShardTransactionChain.props(store.createTransactionChain());
31 final ActorRef subject = getSystem().actorOf(props, "testCreateTransaction");
33 new Within(duration("1 seconds")) {
34 protected void run() {
36 subject.tell(new CreateTransaction("txn-1"), getRef());
38 final String out = new ExpectMsg<String>("match hint") {
39 // do not put code outside this method, will run afterwards
40 protected String match(Object in) {
41 if (in instanceof CreateTransactionReply) {
42 return ((CreateTransactionReply) in).getTransactionPath().toString();
47 }.get(); // this extracts the received message
49 assertEquals("Unexpected transaction path " + out,
50 "akka://test/user/testCreateTransaction/shard-txn-1",
53 // Will wait for the rest of the 3 seconds
63 public void testOnReceiveCloseTransactionChain() throws Exception {
64 new JavaTestKit(getSystem()) {{
65 final Props props = ShardTransactionChain.props(store.createTransactionChain());
66 final ActorRef subject = getSystem().actorOf(props, "testCloseTransactionChain");
68 new Within(duration("1 seconds")) {
69 protected void run() {
71 subject.tell(new CloseTransactionChain(), getRef());
73 final String out = new ExpectMsg<String>("match hint") {
74 // do not put code outside this method, will run afterwards
75 protected String match(Object in) {
76 if (in instanceof CloseTransactionChainReply) {
82 }.get(); // this extracts the received message
84 assertEquals("match", out);
85 // Will wait for the rest of the 3 seconds