X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2Fregistry%2FRpcRegistryTest.java;h=f6f720eed0f62dd50393c3275c6e7d9cc8fab23d;hb=00dba4141e5132372e68190638e083cd54e327ba;hp=e6793741a3ec2ef9030a2e469058ab92de93c153;hpb=d5a00419b66920905e68ff857f44d3a0ab417db7;p=controller.git diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java index e6793741a3..f6f720eed0 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java @@ -9,21 +9,17 @@ import akka.actor.ChildActorPath; import akka.actor.Props; import akka.testkit.JavaTestKit; import com.google.common.base.Predicate; -import com.typesafe.config.ConfigFactory; - import org.junit.After; import org.junit.AfterClass; -import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.opendaylight.controller.remote.rpc.RemoteRpcProviderConfig; import org.opendaylight.controller.remote.rpc.RouteIdentifierImpl; import org.opendaylight.controller.remote.rpc.registry.gossip.Messages; import org.opendaylight.controller.sal.connector.api.RpcRouter; import org.opendaylight.controller.utils.ConditionalProbe; import org.opendaylight.yangtools.yang.common.QName; -import scala.concurrent.Await; -import scala.concurrent.Future; import scala.concurrent.duration.FiniteDuration; import javax.annotation.Nullable; @@ -33,9 +29,9 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; -import static org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.SetLocalRouter; import static org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes; import static org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.RemoveRoutes; +import static org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.SetLocalRouter; public class RpcRegistryTest { @@ -49,9 +45,12 @@ public class RpcRegistryTest { @BeforeClass public static void setup() throws InterruptedException { - node1 = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("memberA")); - node2 = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("memberB")); - node3 = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("memberC")); + RemoteRpcProviderConfig config1 = new RemoteRpcProviderConfig.Builder("memberA").build(); + RemoteRpcProviderConfig config2 = new RemoteRpcProviderConfig.Builder("memberB").build(); + RemoteRpcProviderConfig config3 = new RemoteRpcProviderConfig.Builder("memberC").build(); + node1 = ActorSystem.create("opendaylight-rpc", config1.get()); + node2 = ActorSystem.create("opendaylight-rpc", config2.get()); + node3 = ActorSystem.create("opendaylight-rpc", config3.get()); } @AfterClass @@ -95,7 +94,6 @@ public class RpcRegistryTest { */ @Test public void testAddRemoveRpcOnSameNode() throws URISyntaxException, InterruptedException { - validateSystemStartup(); final JavaTestKit mockBroker = new JavaTestKit(node1); @@ -137,8 +135,6 @@ public class RpcRegistryTest { @Test public void testRpcAddRemoveInCluster() throws URISyntaxException, InterruptedException { - validateSystemStartup(); - final JavaTestKit mockBroker1 = new JavaTestKit(node1); //install probe on node2's bucket store @@ -146,7 +142,6 @@ public class RpcRegistryTest { final JavaTestKit probe2 = createProbeForMessage( node2, bucketStorePath, Messages.BucketStoreMessages.UpdateRemoteBuckets.class); - //Add rpc on node 1 registry1.tell(new SetLocalRouter(mockBroker1.getRef()), mockBroker1.getRef()); registry1.tell(getAddRouteMessage(), mockBroker1.getRef()); @@ -175,8 +170,6 @@ public class RpcRegistryTest { @Test public void testRpcAddedOnMultiNodes() throws Exception { - validateSystemStartup(); - final JavaTestKit mockBroker1 = new JavaTestKit(node1); final JavaTestKit mockBroker2 = new JavaTestKit(node2); final JavaTestKit mockBroker3 = new JavaTestKit(node3); @@ -214,7 +207,10 @@ public class RpcRegistryTest { new ConditionalProbe(probe.getRef(), new Predicate() { @Override public boolean apply(@Nullable Object input) { - return clazz.equals(input.getClass()); + if (input != null) + return clazz.equals(input.getClass()); + else + return false; } }); @@ -225,49 +221,6 @@ public class RpcRegistryTest { } - private void validateSystemStartup() throws InterruptedException { - - ActorPath gossiper1Path = new ChildActorPath(new ChildActorPath(registry1.path(), "store"), "gossiper"); - ActorPath gossiper2Path = new ChildActorPath(new ChildActorPath(registry2.path(), "store"), "gossiper"); - ActorPath gossiper3Path = new ChildActorPath(new ChildActorPath(registry3.path(), "store"), "gossiper"); - - ActorSelection gossiper1 = node1.actorSelection(gossiper1Path); - ActorSelection gossiper2 = node2.actorSelection(gossiper2Path); - ActorSelection gossiper3 = node3.actorSelection(gossiper3Path); - - - if (!resolveReference(gossiper1, gossiper2, gossiper3)) - Assert.fail("Could not find gossipers"); - } - - private Boolean resolveReference(ActorSelection... gossipers) { - - Boolean resolved = true; - for (int i = 0; i < 5; i++) { - - resolved = true; - System.out.println(System.currentTimeMillis() + " Resolving gossipers; trial #" + i); - - for (ActorSelection gossiper : gossipers) { - ActorRef ref = null; - - try { - Future future = gossiper.resolveOne(new FiniteDuration(15000, TimeUnit.MILLISECONDS)); - ref = Await.result(future, new FiniteDuration(10000, TimeUnit.MILLISECONDS)); - } catch (Exception e) { - System.out.println("Could not find gossiper in attempt#" + i + ". Got exception " + e.getMessage()); - } - - if (ref == null) - resolved = false; - } - - if (resolved) break; - - } - return resolved; - } - private AddOrUpdateRoutes getAddRouteMessage() throws URISyntaxException { return new AddOrUpdateRoutes(createRouteIds()); }