Search in sources :

Example 6 with Address

use of akka.actor.Address in project controller by opendaylight.

the class RpcRegistrarTest method testHandleReceiveRemoveEndpoint.

@Test
public void testHandleReceiveRemoveEndpoint() throws Exception {
    final Map<Address, Optional<RemoteRpcEndpoint>> endpoints = ImmutableMap.of(endpointAddress, Optional.empty());
    testActorRef.tell(new UpdateRemoteEndpoints(endpoints), ActorRef.noSender());
    Mockito.verifyNoMoreInteractions(service, oldReg, newReg);
}
Also used : Address(akka.actor.Address) Optional(java.util.Optional) UpdateRemoteEndpoints(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.UpdateRemoteEndpoints) Test(org.junit.Test)

Example 7 with Address

use of akka.actor.Address in project controller by opendaylight.

the class RpcRegistrarTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    system = ActorSystem.create("test");
    final TestKit testKit = new TestKit(system);
    final RemoteRpcProviderConfig config = new RemoteRpcProviderConfig.Builder("system").build();
    final Props props = RpcRegistrar.props(config, service);
    testActorRef = new TestActorRef<>(system, props, testKit.getRef(), "actorRef");
    endpointAddress = new Address("http", "local");
    final DOMRpcIdentifier firstEndpointId = DOMRpcIdentifier.create(SchemaPath.create(true, QName.create("first:identifier", "foo")));
    final DOMRpcIdentifier secondEndpointId = DOMRpcIdentifier.create(SchemaPath.create(true, QName.create("second:identifier", "bar")));
    final TestKit senderKit = new TestKit(system);
    firstEndpoint = new RemoteRpcEndpoint(senderKit.getRef(), Collections.singletonList(firstEndpointId));
    secondEndpoint = new RemoteRpcEndpoint(senderKit.getRef(), Collections.singletonList(secondEndpointId));
    Mockito.doReturn(oldReg).when(service).registerRpcImplementation(Mockito.any(RemoteRpcImplementation.class), Mockito.eq(firstEndpoint.getRpcs()));
    Mockito.doReturn(newReg).when(service).registerRpcImplementation(Mockito.any(RemoteRpcImplementation.class), Mockito.eq(secondEndpoint.getRpcs()));
    rpcRegistrar = testActorRef.underlyingActor();
}
Also used : Address(akka.actor.Address) RemoteRpcEndpoint(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint) DOMRpcIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier) TestKit(akka.testkit.javadsl.TestKit) Props(akka.actor.Props) Before(org.junit.Before)

Example 8 with Address

use of akka.actor.Address 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);
}
Also used : UniqueAddress(akka.cluster.UniqueAddress) Address(akka.actor.Address) AddOrUpdateRoutes(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes) Bucket(org.opendaylight.controller.remote.rpc.registry.gossip.Bucket) DOMRpcIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier) TestKit(akka.testkit.javadsl.TestKit) UpdateRemoteEndpoints(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.UpdateRemoteEndpoints) Test(org.junit.Test)

Example 9 with Address

use of akka.actor.Address 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");
}
Also used : UniqueAddress(akka.cluster.UniqueAddress) Address(akka.actor.Address) AddOrUpdateRoutes(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes) Bucket(org.opendaylight.controller.remote.rpc.registry.gossip.Bucket) DOMRpcIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier) TestKit(akka.testkit.javadsl.TestKit) RemoveRoutes(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.RemoveRoutes) Test(org.junit.Test)

Example 10 with Address

use of akka.actor.Address in project controller by opendaylight.

the class RpcRegistryTest method verifyEmptyBucket.

private void verifyEmptyBucket(final TestKit testKit, final ActorRef registry, final Address address) throws AssertionError {
    Map<Address, Bucket<RoutingTable>> buckets;
    int numTries = 0;
    while (true) {
        buckets = retrieveBuckets(registry1, testKit, address);
        try {
            verifyBucket(buckets.get(address), Collections.emptyList());
            break;
        } catch (AssertionError e) {
            if (++numTries >= 50) {
                throw e;
            }
        }
        Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
    }
}
Also used : UniqueAddress(akka.cluster.UniqueAddress) Address(akka.actor.Address) Bucket(org.opendaylight.controller.remote.rpc.registry.gossip.Bucket) RemoteRpcEndpoint(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint)

Aggregations

Address (akka.actor.Address)36 Test (org.junit.Test)15 Bucket (org.opendaylight.controller.remote.rpc.registry.gossip.Bucket)9 UniqueAddress (akka.cluster.UniqueAddress)7 HashMap (java.util.HashMap)6 DOMRpcIdentifier (org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier)6 RemoteRpcEndpoint (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint)6 TestKit (akka.testkit.javadsl.TestKit)5 Optional (java.util.Optional)5 AddOrUpdateRoutes (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes)4 UpdateRemoteEndpoints (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.UpdateRemoteEndpoints)4 ActorRef (akka.actor.ActorRef)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ActorSelection (akka.actor.ActorSelection)2 ActorSystem (akka.actor.ActorSystem)2 Props (akka.actor.Props)2 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)2 WebMonitor (org.apache.flink.runtime.webmonitor.WebMonitor)2