From 58d9dc1c6df02ee0c5f1d72e9f0a2f6361b7d23f Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 8 Aug 2014 14:42:06 -0700 Subject: [PATCH] Fixed remove rpc api in rpc registry Added tests Change-Id: Ib5204f5226d11a1d8cdec7cf99809333bd1f1457 Signed-off-by: Abhishek Kumar --- .../remote/rpc/registry/RoutingTable.java | 3 +- .../remote/rpc/registry/RpcRegistryTest.java | 54 ++++++++++++++----- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RoutingTable.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RoutingTable.java index d99faabfe4..d21d05d7fe 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RoutingTable.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RoutingTable.java @@ -14,7 +14,6 @@ import org.opendaylight.controller.remote.rpc.registry.gossip.Copier; import org.opendaylight.controller.sal.connector.api.RpcRouter; import java.io.Serializable; -import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -26,7 +25,7 @@ public class RoutingTable implements Copier, Serializable { @Override public RoutingTable copy() { RoutingTable copy = new RoutingTable(); - copy.setTable(Collections.unmodifiableMap(table)); + copy.setTable(new HashMap<>(table)); copy.setRouter(this.getRouter()); return copy; 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 284789cc57..da3942a828 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 @@ -29,6 +29,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; 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.FindRouters; import static org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.FindRoutersReply; import static org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.SetLocalRouter; @@ -84,13 +85,14 @@ public class RpcRegistryTest { /** * One node cluster. - * Register rpc. Ensure router can be found + * 1. Register rpc, ensure router can be found + * 2. Then remove rpc, ensure its deleted * * @throws URISyntaxException * @throws InterruptedException */ @Test - public void testWhenRpcAddedOneNodeShouldAppearOnSameNode() throws URISyntaxException, InterruptedException { + public void testAddRemoveRpcOnSameNode() throws URISyntaxException, InterruptedException { final JavaTestKit mockBroker = new JavaTestKit(node1); @@ -106,17 +108,28 @@ public class RpcRegistryTest { List> pairs = message.getRouterWithUpdateTime(); validateRouterReceived(pairs, mockBroker.getRef()); + + //Now remove rpc + registry1.tell(getRemoveRouteMessage(), mockBroker.getRef()); + Thread.sleep(1000); + //find the route on node 1's registry + registry1.tell(new FindRouters(createRouteId()), mockBroker.getRef()); + message = mockBroker.expectMsgClass(JavaTestKit.duration("10 second"), FindRoutersReply.class); + pairs = message.getRouterWithUpdateTime(); + + Assert.assertTrue(pairs.isEmpty()); } /** * Three node cluster. - * Register rpc on 1 node. Ensure its router can be found on other 2. + * 1. Register rpc on 1 node, ensure its router can be found on other 2. + * 2. Remove rpc on 1 node, ensure its removed on other 2. * * @throws URISyntaxException * @throws InterruptedException */ @Test - public void testWhenRpcAddedOneNodeShouldAppearOnAnother() throws URISyntaxException, InterruptedException { + public void testRpcAddRemoveInCluster() throws URISyntaxException, InterruptedException { validateSystemStartup(); @@ -128,22 +141,25 @@ public class RpcRegistryTest { registry1.tell(new SetLocalRouter(mockBroker1.getRef()), mockBroker1.getRef()); registry1.tell(getAddRouteMessage(), mockBroker1.getRef()); - Thread.sleep(5000);// give some time for bucket store data sync + Thread.sleep(1000);// give some time for bucket store data sync //find the route in node 2's registry - registry2.tell(new FindRouters(createRouteId()), mockBroker2.getRef()); - FindRoutersReply message = mockBroker2.expectMsgClass(JavaTestKit.duration("10 second"), FindRoutersReply.class); - List> pairs = message.getRouterWithUpdateTime(); - + List> pairs = findRouters(registry2, mockBroker2); validateRouterReceived(pairs, mockBroker1.getRef()); //find the route in node 3's registry - registry3.tell(new FindRouters(createRouteId()), mockBroker3.getRef()); - message = mockBroker3.expectMsgClass(JavaTestKit.duration("10 second"), FindRoutersReply.class); - pairs = message.getRouterWithUpdateTime(); - + pairs = findRouters(registry3, mockBroker3); validateRouterReceived(pairs, mockBroker1.getRef()); + //Now remove + registry1.tell(getRemoveRouteMessage(), mockBroker1.getRef()); + Thread.sleep(1000);// give some time for bucket store data sync + + pairs = findRouters(registry2, mockBroker2); + Assert.assertTrue(pairs.isEmpty()); + + pairs = findRouters(registry3, mockBroker3); + Assert.assertTrue(pairs.isEmpty()); } /** @@ -172,7 +188,7 @@ public class RpcRegistryTest { registry2.tell(getAddRouteMessage(), mockBroker2.getRef()); registry3.tell(new SetLocalRouter(mockBroker3.getRef()), mockBroker3.getRef()); - Thread.sleep(5000);// give some time for bucket store data sync + Thread.sleep(1000);// give some time for bucket store data sync //find the route in node 3's registry registry3.tell(new FindRouters(createRouteId()), mockBroker3.getRef()); @@ -183,6 +199,12 @@ public class RpcRegistryTest { } + private List> findRouters(ActorRef registry, JavaTestKit receivingActor) throws URISyntaxException { + registry.tell(new FindRouters(createRouteId()), receivingActor.getRef()); + FindRoutersReply message = receivingActor.expectMsgClass(JavaTestKit.duration("10 second"), FindRoutersReply.class); + return message.getRouterWithUpdateTime(); + } + private void validateMultiRouterReceived(List> actual, ActorRef... expected) { Assert.assertTrue(actual != null); Assert.assertTrue(actual.size() == expected.length); @@ -242,6 +264,10 @@ public class RpcRegistryTest { return new AddOrUpdateRoutes(createRouteIds()); } + private RemoveRoutes getRemoveRouteMessage() throws URISyntaxException { + return new RemoveRoutes(createRouteIds()); + } + private List> createRouteIds() throws URISyntaxException { QName type = new QName(new URI("/mockrpc"), "mockrpc"); List> routeIds = new ArrayList<>(); -- 2.36.6