Merge "Fixed for bug 1197"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / ShardTransactionChainTest.java
index d8cb53d0836fbff17d4ece96a1f31a0a9b6a89c9..6330ad8acca33ab6c05f3263aa45ca459f0c283d 100644 (file)
@@ -6,12 +6,14 @@ import akka.testkit.JavaTestKit;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
 import org.junit.Test;
+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 static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
 
 public class ShardTransactionChainTest extends AbstractActorTest {
 
@@ -25,26 +27,61 @@ public class ShardTransactionChainTest extends AbstractActorTest {
   @Test
   public void testOnReceiveCreateTransaction() throws Exception {
     new JavaTestKit(getSystem()) {{
-      final Props props = ShardTransactionChain.props(store.createTransactionChain());
+      final Props props = ShardTransactionChain.props(store.createTransactionChain(), TestModel.createTestContext());
       final ActorRef subject = getSystem().actorOf(props, "testCreateTransaction");
 
+     new Within(duration("1 seconds")) {
+        protected void run() {
+
+          subject.tell(new CreateTransaction("txn-1").toSerializable(), getRef());
+
+          final String out = new ExpectMsg<String>("match hint") {
+            // do not put code outside this method, will run afterwards
+            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")) {
         protected void run() {
 
-          subject.tell(new CreateTransaction(), getRef());
+          subject.tell(new CloseTransactionChain().toSerializable(), getRef());
 
           final String out = new ExpectMsg<String>("match hint") {
             // do not put code outside this method, will run afterwards
             protected String match(Object in) {
-              if (in instanceof CreateTransactionReply) {
-                return ((CreateTransactionReply) in).getTransactionPath().toString();
+              if (in.getClass().equals(CloseTransactionChainReply.SERIALIZABLE_CLASS)) {
+                return "match";
               } else {
                 throw noMatch();
               }
             }
           }.get(); // this extracts the received message
 
-          assertTrue(out.matches("akka:\\/\\/test\\/user\\/testCreateTransaction\\/\\$.*"));
+          assertEquals("match", out);
           // Will wait for the rest of the 3 seconds
           expectNoMsg();
         }
@@ -53,4 +90,4 @@ public class ShardTransactionChainTest extends AbstractActorTest {
       };
     }};
   }
-}
\ No newline at end of file
+}