use of akka.actor.Address in project controller by opendaylight.
the class RpcRegistryTest method retrieveBuckets.
private static Map<Address, Bucket<RoutingTable>> retrieveBuckets(final ActorRef bucketStore, final TestKit testKit, final Address... addresses) {
int numTries = 0;
while (true) {
bucketStore.tell(GET_ALL_BUCKETS, testKit.getRef());
@SuppressWarnings("unchecked") Map<Address, Bucket<RoutingTable>> buckets = testKit.expectMsgClass(Duration.create(3, TimeUnit.SECONDS), Map.class);
boolean foundAll = true;
for (Address addr : addresses) {
Bucket<RoutingTable> bucket = buckets.get(addr);
if (bucket == null) {
foundAll = false;
break;
}
}
if (foundAll) {
return buckets;
}
if (++numTries >= 50) {
Assert.fail("Missing expected buckets for addresses: " + Arrays.toString(addresses) + ", Actual: " + buckets);
}
Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
}
}
use of akka.actor.Address 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 akka.actor.Address in project controller by opendaylight.
the class BucketStoreTest method testReceiveUpdateRemoteBuckets.
/**
* Given remote buckets, should merge with local copy of remote buckets.
*/
@Test
public void testReceiveUpdateRemoteBuckets() {
final BucketStoreActor<T> store = createStore();
Address localAddress = system.provider().getDefaultAddress();
Bucket<T> localBucket = new BucketImpl<>(0L, new T());
final Address a1 = new Address("tcp", "system1");
final Address a2 = new Address("tcp", "system2");
final Address a3 = new Address("tcp", "system3");
final Bucket<T> b1 = new BucketImpl<>(0L, new T());
final Bucket<T> b2 = new BucketImpl<>(0L, new T());
final Bucket<T> b3 = new BucketImpl<>(0L, new T());
// Given remote buckets
store.updateRemoteBuckets(ImmutableMap.of(a1, b1, a2, b2, localAddress, localBucket));
// Should NOT contain local bucket
// Should contain ONLY 3 entries i.e a1, a2
Map<Address, Bucket<T>> remoteBucketsInStore = store.getRemoteBuckets();
Assert.assertFalse("remote buckets contains local bucket", remoteBucketsInStore.containsKey(localAddress));
Assert.assertTrue(remoteBucketsInStore.size() == 2);
// Add a new remote bucket
Address a4 = new Address("tcp", "system4");
Bucket<T> b4 = new BucketImpl<>(0L, new T());
store.updateRemoteBuckets(ImmutableMap.of(a4, b4));
// Should contain a4
// Should contain 4 entries now i.e a1, a2, a4
remoteBucketsInStore = store.getRemoteBuckets();
Assert.assertTrue("Does not contain a4", remoteBucketsInStore.containsKey(a4));
Assert.assertTrue(remoteBucketsInStore.size() == 3);
// Update a bucket
Bucket<T> b3New = new BucketImpl<>(0L, new T());
Map<Address, Bucket<?>> remoteBuckets = new HashMap<>(3);
remoteBuckets.put(a3, b3New);
remoteBuckets.put(a1, null);
remoteBuckets.put(a2, null);
store.updateRemoteBuckets(remoteBuckets);
// Should only update a3
remoteBucketsInStore = store.getRemoteBuckets();
Bucket<T> b3InStore = remoteBucketsInStore.get(a3);
Assert.assertEquals(b3New.getVersion(), b3InStore.getVersion());
// Should NOT update a1 and a2
Bucket<T> b1InStore = remoteBucketsInStore.get(a1);
Bucket<T> b2InStore = remoteBucketsInStore.get(a2);
Assert.assertEquals(b1.getVersion(), b1InStore.getVersion());
Assert.assertEquals(b2.getVersion(), b2InStore.getVersion());
Assert.assertTrue(remoteBucketsInStore.size() == 4);
// Should update versions map
// versions map contains versions for all remote buckets (4).
Map<Address, Long> versionsInStore = store.getVersions();
Assert.assertEquals(4, versionsInStore.size());
Assert.assertEquals((Long) b1.getVersion(), versionsInStore.get(a1));
Assert.assertEquals((Long) b2.getVersion(), versionsInStore.get(a2));
Assert.assertEquals((Long) b3New.getVersion(), versionsInStore.get(a3));
Assert.assertEquals((Long) b4.getVersion(), versionsInStore.get(a4));
// Send older version of bucket
remoteBuckets.clear();
remoteBuckets.put(a3, b3);
store.updateRemoteBuckets(remoteBuckets);
// Should NOT update a3
remoteBucketsInStore = store.getRemoteBuckets();
b3InStore = remoteBucketsInStore.get(a3);
Assert.assertEquals(b3InStore.getVersion(), b3New.getVersion());
}
use of akka.actor.Address in project controller by opendaylight.
the class RemoteRpcRegistryMXBeanImpl method findRpcByRoute.
@Override
public Map<String, String> findRpcByRoute(final String routeId) {
RoutingTable localTable = getLocalData();
Map<String, String> rpcMap = new HashMap<>(getRpcMemberMapByRoute(localTable, routeId, LOCAL_CONSTANT));
Map<Address, Bucket<RoutingTable>> buckets = getRemoteBuckets();
for (Entry<Address, Bucket<RoutingTable>> entry : buckets.entrySet()) {
RoutingTable table = entry.getValue().getData();
rpcMap.putAll(getRpcMemberMapByRoute(table, routeId, entry.getKey().toString()));
}
log.debug("list of RPCs {} searched by route {}", rpcMap, routeId);
return rpcMap;
}
use of akka.actor.Address in project controller by opendaylight.
the class RpcRegistry method onBucketsUpdated.
@Override
protected void onBucketsUpdated(final Map<Address, Bucket<RoutingTable>> buckets) {
final Map<Address, Optional<RemoteRpcEndpoint>> endpoints = new HashMap<>(buckets.size());
for (Entry<Address, Bucket<RoutingTable>> e : buckets.entrySet()) {
final RoutingTable table = e.getValue().getData();
final Collection<DOMRpcIdentifier> rpcs = table.getRoutes();
endpoints.put(e.getKey(), rpcs.isEmpty() ? Optional.empty() : Optional.of(new RemoteRpcEndpoint(table.getRpcInvoker(), rpcs)));
}
if (!endpoints.isEmpty()) {
rpcRegistrar.tell(new UpdateRemoteEndpoints(endpoints), ActorRef.noSender());
}
}
Aggregations