1 package org.opendaylight.controller.cluster.datastore;
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;
10 import org.opendaylight.controller.cluster.datastore.messages.FindPrimary;
11 import org.opendaylight.controller.cluster.datastore.messages.PrimaryNotFound;
12 import scala.concurrent.duration.Duration;
14 public class ShardManagerTest {
15 private static ActorSystem system;
18 public static void setUp(){
19 system = ActorSystem.create("test");
23 public static void tearDown(){
24 JavaTestKit.shutdownActorSystem(system);
29 public void testOnReceiveFindPrimary() throws Exception {
31 new JavaTestKit(system) {{
32 final Props props = Props.create(ShardManager.class);
33 final TestActorRef<ShardManager> subject = TestActorRef.create(system, props, "test");
35 // can also use JavaTestKit “from the outside”
36 final JavaTestKit probe = new JavaTestKit(system);
38 // the run() method needs to finish within 3 seconds
39 new Within(duration("3 seconds")) {
40 protected void run() {
42 subject.tell(new FindPrimary("inventory"), getRef());
44 expectMsgEquals(Duration.Zero(), new PrimaryNotFound("inventory"));
46 // Will wait for the rest of the 3 seconds