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;
17 import static org.junit.Assert.assertTrue;
19 public class ShardTransactionChainTest extends AbstractActorTest {
21 private static ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor());
23 private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", storeExecutor);
26 store.onGlobalContextUpdated(TestModel.createTestContext());
29 public void testOnReceiveCreateTransaction() throws Exception {
30 new JavaTestKit(getSystem()) {{
31 final Props props = ShardTransactionChain.props(store.createTransactionChain());
32 final ActorRef subject = getSystem().actorOf(props, "testCreateTransaction");
34 new Within(duration("1 seconds")) {
35 protected void run() {
37 subject.tell(new CreateTransaction(), getRef());
39 final String out = new ExpectMsg<String>("match hint") {
40 // do not put code outside this method, will run afterwards
41 protected String match(Object in) {
42 if (in instanceof CreateTransactionReply) {
43 return ((CreateTransactionReply) in).getTransactionPath().toString();
48 }.get(); // this extracts the received message
50 assertTrue(out.matches("akka:\\/\\/test\\/user\\/testCreateTransaction\\/\\$.*"));
51 // Will wait for the rest of the 3 seconds
61 public void testOnReceiveCloseTransactionChain() throws Exception {
62 new JavaTestKit(getSystem()) {{
63 final Props props = ShardTransactionChain.props(store.createTransactionChain());
64 final ActorRef subject = getSystem().actorOf(props, "testCloseTransactionChain");
66 new Within(duration("1 seconds")) {
67 protected void run() {
69 subject.tell(new CloseTransactionChain(), getRef());
71 final String out = new ExpectMsg<String>("match hint") {
72 // do not put code outside this method, will run afterwards
73 protected String match(Object in) {
74 if (in instanceof CloseTransactionChainReply) {
80 }.get(); // this extracts the received message
82 assertEquals("match", out);
83 // Will wait for the rest of the 3 seconds