Search in sources :

Example 1 with RpcGateway

use of org.apache.flink.runtime.rpc.RpcGateway in project flink by apache.

the class AkkaRpcActorTest method resolvesRunningAkkaRpcActor.

@Test
public void resolvesRunningAkkaRpcActor() throws Exception {
    final String endpointName = "foobar";
    try (RpcEndpoint simpleRpcEndpoint1 = createRpcEndpointWithRandomNameSuffix(endpointName);
        RpcEndpoint simpleRpcEndpoint2 = createRpcEndpointWithRandomNameSuffix(endpointName)) {
        simpleRpcEndpoint1.closeAsync().join();
        final String wildcardName = RpcServiceUtils.createWildcardName(endpointName);
        final String wildcardAddress = AkkaRpcServiceUtils.getLocalRpcUrl(wildcardName);
        final RpcGateway rpcGateway = akkaRpcService.connect(wildcardAddress, RpcGateway.class).join();
        assertThat(rpcGateway.getAddress(), is(equalTo(simpleRpcEndpoint2.getAddress())));
    }
}
Also used : RpcEndpoint(org.apache.flink.runtime.rpc.RpcEndpoint) RpcGateway(org.apache.flink.runtime.rpc.RpcGateway) Test(org.junit.Test)

Example 2 with RpcGateway

use of org.apache.flink.runtime.rpc.RpcGateway in project flink by apache.

the class LeaderGatewayRetrieverTest method testGatewayRetrievalFailures.

/**
 * Tests that the gateway retrieval is retried in case of a failure.
 */
@Test
public void testGatewayRetrievalFailures() throws Exception {
    final String address = "localhost";
    final UUID leaderId = UUID.randomUUID();
    RpcGateway rpcGateway = mock(RpcGateway.class);
    TestingLeaderGatewayRetriever leaderGatewayRetriever = new TestingLeaderGatewayRetriever(rpcGateway);
    SettableLeaderRetrievalService settableLeaderRetrievalService = new SettableLeaderRetrievalService();
    settableLeaderRetrievalService.start(leaderGatewayRetriever);
    CompletableFuture<RpcGateway> gatewayFuture = leaderGatewayRetriever.getFuture();
    // this triggers the first gateway retrieval attempt
    settableLeaderRetrievalService.notifyListener(address, leaderId);
    // check that the first future has been failed
    try {
        gatewayFuture.get();
        fail("The first future should have been failed.");
    } catch (ExecutionException ignored) {
    // that's what we expect
    }
    // the second attempt should fail as well
    assertFalse((leaderGatewayRetriever.getNow().isPresent()));
    // the third attempt should succeed
    assertEquals(rpcGateway, leaderGatewayRetriever.getNow().get());
}
Also used : RpcGateway(org.apache.flink.runtime.rpc.RpcGateway) SettableLeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.SettableLeaderRetrievalService) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

RpcGateway (org.apache.flink.runtime.rpc.RpcGateway)2 Test (org.junit.Test)2 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1 SettableLeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.SettableLeaderRetrievalService)1 RpcEndpoint (org.apache.flink.runtime.rpc.RpcEndpoint)1