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.CreateTransaction;
10 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply;
11 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
12 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
14 import static org.junit.Assert.assertTrue;
16 public class ShardTransactionChainTest extends AbstractActorTest {
18 private static ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor());
20 private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", storeExecutor);
23 store.onGlobalContextUpdated(TestModel.createTestContext());
26 public void testOnReceiveCreateTransaction() throws Exception {
27 new JavaTestKit(getSystem()) {{
28 final Props props = ShardTransactionChain.props(store.createTransactionChain());
29 final ActorRef subject = getSystem().actorOf(props, "testCreateTransaction");
31 new Within(duration("1 seconds")) {
32 protected void run() {
34 subject.tell(new CreateTransaction(), getRef());
36 final String out = new ExpectMsg<String>("match hint") {
37 // do not put code outside this method, will run afterwards
38 protected String match(Object in) {
39 if (in instanceof CreateTransactionReply) {
40 return ((CreateTransactionReply) in).getTransactionPath().toString();
45 }.get(); // this extracts the received message
47 assertTrue(out.matches("akka:\\/\\/test\\/user\\/testCreateTransaction\\/\\$.*"));
48 // Will wait for the rest of the 3 seconds