use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes in project controller by opendaylight.
the class RpcRegistryTest method testRpcAddedOnMultiNodes.
/**
* Three node cluster. Register rpc on 2 nodes. Ensure 3rd gets updated.
*/
@Test
public void testRpcAddedOnMultiNodes() throws Exception {
final TestKit testKit = new TestKit(node3);
// Add rpc on node 1
List<DOMRpcIdentifier> addedRouteIds1 = createRouteIds();
registry1.tell(new AddOrUpdateRoutes(addedRouteIds1), ActorRef.noSender());
final UpdateRemoteEndpoints req1 = registrar3.expectMsgClass(Duration.create(3, TimeUnit.SECONDS), UpdateRemoteEndpoints.class);
// Add rpc on node 2
List<DOMRpcIdentifier> addedRouteIds2 = createRouteIds();
registry2.tell(new AddOrUpdateRoutes(addedRouteIds2), ActorRef.noSender());
final UpdateRemoteEndpoints req2 = registrar3.expectMsgClass(Duration.create(3, TimeUnit.SECONDS), UpdateRemoteEndpoints.class);
Address node2Address = node2.provider().getDefaultAddress();
Address node1Address = node1.provider().getDefaultAddress();
Map<Address, Bucket<RoutingTable>> buckets = retrieveBuckets(registry3, testKit, node1Address, node2Address);
verifyBucket(buckets.get(node1Address), addedRouteIds1);
verifyBucket(buckets.get(node2Address), addedRouteIds2);
Map<Address, Long> versions = retrieveVersions(registry3, testKit);
Assert.assertEquals("Version for bucket " + node1Address, (Long) buckets.get(node1Address).getVersion(), versions.get(node1Address));
Assert.assertEquals("Version for bucket " + node2Address, (Long) buckets.get(node2Address).getVersion(), versions.get(node2Address));
assertEndpoints(req1, node1Address, invoker1);
assertEndpoints(req2, node2Address, invoker2);
}
use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes in project controller by opendaylight.
the class RpcRegistryTest method testRpcAddRemoveInCluster.
/**
* Three node cluster. 1. Register rpc on 1 node, ensure 2nd node gets updated 2. Remove rpc on
* 1 node, ensure 2nd node gets updated
*/
@Test
public void testRpcAddRemoveInCluster() throws Exception {
LOG.info("testRpcAddRemoveInCluster starting");
List<DOMRpcIdentifier> addedRouteIds = createRouteIds();
Address node1Address = node1.provider().getDefaultAddress();
// Add rpc on node 1
registry1.tell(new AddOrUpdateRoutes(addedRouteIds), ActorRef.noSender());
// Bucket store on node2 should get a message to update its local copy of remote buckets
final TestKit testKit = new TestKit(node2);
Map<Address, Bucket<RoutingTable>> buckets = retrieveBuckets(registry2, testKit, node1Address);
verifyBucket(buckets.get(node1Address), addedRouteIds);
// Now remove
registry1.tell(new RemoveRoutes(addedRouteIds), ActorRef.noSender());
// Bucket store on node2 should get a message to update its local copy of remote buckets.
// Wait for the bucket for node1 to be empty.
verifyEmptyBucket(testKit, registry2, node1Address);
LOG.info("testRpcAddRemoveInCluster ending");
}
use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes in project controller by opendaylight.
the class RpcRegistryTest method testAddRoutesConcurrency.
@Test
public void testAddRoutesConcurrency() {
final TestKit testKit = new TestKit(node1);
final int nRoutes = 500;
final Collection<DOMRpcIdentifier> added = new ArrayList<>(nRoutes);
for (int i = 0; i < nRoutes; i++) {
final DOMRpcIdentifier routeId = DOMRpcIdentifier.create(SchemaPath.create(true, QName.create(URI.create("/mockrpc"), "type" + i)));
added.add(routeId);
// Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
registry1.tell(new AddOrUpdateRoutes(Arrays.asList(routeId)), ActorRef.noSender());
}
FiniteDuration duration = Duration.create(3, TimeUnit.SECONDS);
int numTries = 0;
while (true) {
registry1.tell(GET_ALL_BUCKETS, testKit.getRef());
@SuppressWarnings("unchecked") Map<Address, Bucket<RoutingTable>> buckets = testKit.expectMsgClass(duration, Map.class);
Bucket<RoutingTable> localBucket = buckets.values().iterator().next();
RoutingTable table = localBucket.getData();
if (table != null && table.size() == nRoutes) {
for (DOMRpcIdentifier r : added) {
Assert.assertTrue("RoutingTable contains " + r, table.contains(r));
}
break;
}
if (++numTries >= 50) {
Assert.fail("Expected # routes: " + nRoutes + ", Actual: " + table.size());
}
Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
}
}
use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes in project controller by opendaylight.
the class RpcRegistryTest method testAddRemoveRpcOnSameNode.
/**
* One node cluster. 1. Register rpc, ensure router can be found 2. Then remove rpc, ensure its
* deleted
*/
@Test
public void testAddRemoveRpcOnSameNode() throws Exception {
LOG.info("testAddRemoveRpcOnSameNode starting");
Address nodeAddress = node1.provider().getDefaultAddress();
// Add rpc on node 1
List<DOMRpcIdentifier> addedRouteIds = createRouteIds();
registry1.tell(new AddOrUpdateRoutes(addedRouteIds), ActorRef.noSender());
// Bucket store should get an update bucket message. Updated bucket contains added rpc.
final TestKit testKit = new TestKit(node1);
Map<Address, Bucket<RoutingTable>> buckets = retrieveBuckets(registry1, testKit, nodeAddress);
verifyBucket(buckets.get(nodeAddress), addedRouteIds);
Map<Address, Long> versions = retrieveVersions(registry1, testKit);
Assert.assertEquals("Version for bucket " + nodeAddress, (Long) buckets.get(nodeAddress).getVersion(), versions.get(nodeAddress));
// Now remove rpc
registry1.tell(new RemoveRoutes(addedRouteIds), ActorRef.noSender());
// Bucket store should get an update bucket message. Rpc is removed in the updated bucket
verifyEmptyBucket(testKit, registry1, nodeAddress);
LOG.info("testAddRemoveRpcOnSameNode ending");
}
use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes in project controller by opendaylight.
the class RpcListener method onRpcAvailable.
@Override
public void onRpcAvailable(@Nonnull final Collection<DOMRpcIdentifier> rpcs) {
Preconditions.checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null.");
LOG.debug("Adding registration for [{}]", rpcs);
rpcRegistry.tell(new AddOrUpdateRoutes(rpcs), ActorRef.noSender());
}
Aggregations