Merge "Bug-835:Reserve ports should be logical ports"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / ShardManagerTest.java
1 package org.opendaylight.controller.cluster.datastore;
2
3 import akka.actor.ActorSystem;
4 import akka.actor.Props;
5 import akka.testkit.JavaTestKit;
6 import akka.testkit.TestActorRef;
7 import org.junit.AfterClass;
8 import org.junit.BeforeClass;
9 import org.junit.Test;
10 import org.opendaylight.controller.cluster.datastore.messages.FindPrimary;
11 import org.opendaylight.controller.cluster.datastore.messages.PrimaryNotFound;
12 import scala.concurrent.duration.Duration;
13
14 public class ShardManagerTest {
15     private static ActorSystem system;
16
17     @BeforeClass
18     public static void setUp(){
19         system = ActorSystem.create("test");
20     }
21
22     @AfterClass
23     public static void tearDown(){
24         JavaTestKit.shutdownActorSystem(system);
25         system = null;
26     }
27
28     @Test
29     public void testOnReceiveFindPrimary() throws Exception {
30
31         new JavaTestKit(system) {{
32             final Props props = Props.create(ShardManager.class);
33             final TestActorRef<ShardManager> subject = TestActorRef.create(system, props, "test");
34
35             // can also use JavaTestKit “from the outside”
36             final JavaTestKit probe = new JavaTestKit(system);
37
38             // the run() method needs to finish within 3 seconds
39             new Within(duration("3 seconds")) {
40                 protected void run() {
41
42                     subject.tell(new FindPrimary("inventory"), getRef());
43
44                     expectMsgEquals(Duration.Zero(), new PrimaryNotFound("inventory"));
45
46                     // Will wait for the rest of the 3 seconds
47                     expectNoMsg();
48                 }
49             };
50         }};
51     }
52 }