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.PrimaryFound;
12 import org.opendaylight.controller.cluster.datastore.messages.PrimaryNotFound;
13 import scala.concurrent.duration.Duration;
15 public class ShardManagerTest {
16 private static ActorSystem system;
19 public static void setUp(){
20 system = ActorSystem.create("test");
24 public static void tearDown(){
25 JavaTestKit.shutdownActorSystem(system);
30 public void testOnReceiveFindPrimaryForNonExistentShard() throws Exception {
32 new JavaTestKit(system) {{
33 final Props props = ShardManager.props("config");
34 final TestActorRef<ShardManager> subject = TestActorRef.create(system, props);
36 new Within(duration("1 seconds")) {
37 protected void run() {
39 subject.tell(new FindPrimary("inventory"), getRef());
41 expectMsgEquals(Duration.Zero(), new PrimaryNotFound("inventory"));
43 // Will wait for the rest of the 3 seconds
51 public void testOnReceiveFindPrimaryForExistentShard() throws Exception {
53 new JavaTestKit(system) {{
54 final Props props = ShardManager.props("config");
55 final TestActorRef<ShardManager> subject = TestActorRef.create(system, props);
57 // the run() method needs to finish within 3 seconds
58 new Within(duration("1 seconds")) {
59 protected void run() {
61 subject.tell(new FindPrimary(Shard.DEFAULT_NAME), getRef());
63 expectMsgClass(PrimaryFound.class);