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 org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper;
14 import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration;
15 import scala.concurrent.duration.Duration;
17 public class ShardManagerTest {
18 private static ActorSystem system;
21 public static void setUp(){
22 system = ActorSystem.create("test");
26 public static void tearDown(){
27 JavaTestKit.shutdownActorSystem(system);
32 public void testOnReceiveFindPrimaryForNonExistentShard() throws Exception {
34 new JavaTestKit(system) {{
35 final Props props = ShardManager.props("config", new MockClusterWrapper(), new MockConfiguration());
36 final TestActorRef<ShardManager> subject = TestActorRef.create(system, props);
38 new Within(duration("1 seconds")) {
39 protected void run() {
41 subject.tell(new FindPrimary("inventory"), getRef());
43 expectMsgEquals(Duration.Zero(), new PrimaryNotFound("inventory"));
45 // Will wait for the rest of the 3 seconds
53 public void testOnReceiveFindPrimaryForExistentShard() throws Exception {
55 new JavaTestKit(system) {{
56 final Props props = ShardManager.props("config", new MockClusterWrapper(), new MockConfiguration());
57 final TestActorRef<ShardManager> subject = TestActorRef.create(system, props);
59 // the run() method needs to finish within 3 seconds
60 new Within(duration("1 seconds")) {
61 protected void run() {
63 subject.tell(new FindPrimary(Shard.DEFAULT_NAME), getRef());
65 expectMsgClass(PrimaryFound.class);