Search in sources :

Example 16 with RpcService

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

the class RetryingRegistrationTest method testRetryConnectOnFailure.

@Test
public void testRetryConnectOnFailure() throws Exception {
    final String testId = "laissez les bon temps roulez";
    final UUID leaderId = UUID.randomUUID();
    ScheduledExecutorService executor = TestingUtils.defaultExecutor();
    ManualResponseTestRegistrationGateway testGateway = new ManualResponseTestRegistrationGateway(new TestRegistrationSuccess(testId));
    try {
        // RPC service that fails upon the first connection, but succeeds on the second
        RpcService rpc = mock(RpcService.class);
        when(rpc.connect(anyString(), any(Class.class))).thenReturn(FutureUtils.completedExceptionally(new Exception(// first connection attempt
        "test connect failure")), // fails
        CompletableFuture.completedFuture(// second connection attempt succeeds
        testGateway));
        when(rpc.getScheduledExecutor()).thenReturn(new ScheduledExecutorServiceAdapter(executor));
        when(rpc.scheduleRunnable(any(Runnable.class), anyLong(), any(TimeUnit.class))).thenAnswer((InvocationOnMock invocation) -> {
            final Runnable runnable = invocation.getArgument(0);
            final long delay = invocation.getArgument(1);
            final TimeUnit timeUnit = invocation.getArgument(2);
            return TestingUtils.defaultScheduledExecutor().schedule(runnable, delay, timeUnit);
        });
        TestRetryingRegistration registration = new TestRetryingRegistration(rpc, "foobar address", leaderId);
        long start = System.currentTimeMillis();
        registration.startRegistration();
        RetryingRegistration.RetryingRegistrationResult<TestRegistrationGateway, TestRegistrationSuccess, TestRegistrationRejection> registrationResponse = registration.getFuture().get(10L, TimeUnit.SECONDS);
        // measure the duration of the registration --> should be longer than the error delay
        long duration = System.currentTimeMillis() - start;
        assertTrue("The registration should have failed the first time. Thus the duration should be longer than at least a single error delay.", duration > TestRetryingRegistration.DELAY_ON_ERROR);
        // validate correct invocation and result
        assertEquals(testId, registrationResponse.getSuccess().getCorrelationId());
        assertEquals(leaderId, testGateway.getInvocations().take().leaderId());
    } finally {
        testGateway.stop();
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Mockito.anyString(org.mockito.Mockito.anyString) FlinkException(org.apache.flink.util.FlinkException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) ScheduledExecutorServiceAdapter(org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) RpcService(org.apache.flink.runtime.rpc.RpcService) TimeUnit(java.util.concurrent.TimeUnit) UUID(java.util.UUID) Test(org.junit.Test)

Example 17 with RpcService

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

the class RegisteredRpcConnectionTest method testRpcConnectionRejectionCallsOnRegistrationRejection.

@Test
public void testRpcConnectionRejectionCallsOnRegistrationRejection() {
    TestRegistrationGateway testRegistrationGateway = DefaultTestRegistrationGateway.newBuilder().setRegistrationFunction((uuid, aLong) -> CompletableFuture.completedFuture(new TestRegistrationRejection(TestRegistrationRejection.RejectionReason.REJECTED))).build();
    rpcService.registerGateway(testRegistrationGateway.getAddress(), testRegistrationGateway);
    TestRpcConnection connection = new TestRpcConnection(testRegistrationGateway.getAddress(), UUID.randomUUID(), rpcService.getScheduledExecutor(), rpcService);
    connection.start();
    final Either<TestRegistrationSuccess, TestRegistrationRejection> connectionResult = connection.getConnectionFuture().join();
    assertTrue(connectionResult.isRight());
    final TestRegistrationRejection registrationRejection = connectionResult.right();
    assertThat(registrationRejection.getRejectionReason(), is(TestRegistrationRejection.RejectionReason.REJECTED));
}
Also used : TestRegistrationSuccess(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess) Either(org.apache.flink.types.Either) Executor(java.util.concurrent.Executor) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) LoggerFactory(org.slf4j.LoggerFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) Assert.assertThat(org.junit.Assert.assertThat) RpcService(org.apache.flink.runtime.rpc.RpcService) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) After(org.junit.After) TestLogger(org.apache.flink.util.TestLogger) TestRegistrationRejection(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationRejection) Matchers.is(org.hamcrest.Matchers.is) Assert.fail(org.junit.Assert.fail) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) TestRegistrationRejection(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationRejection) TestRegistrationSuccess(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess) Test(org.junit.Test)

Example 18 with RpcService

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

the class RegisteredRpcConnectionTest method testRpcConnectionFailures.

@Test
public void testRpcConnectionFailures() throws Exception {
    final String connectionFailureMessage = "Test RPC Connection failure";
    final String testRpcConnectionEndpointAddress = "<TestRpcConnectionEndpointAddress>";
    final UUID leaderId = UUID.randomUUID();
    final RuntimeException registrationException = new RuntimeException(connectionFailureMessage);
    // gateway that upon registration calls throws an exception
    TestRegistrationGateway testGateway = DefaultTestRegistrationGateway.newBuilder().setRegistrationFunction((uuid, aLong) -> {
        throw registrationException;
    }).build();
    rpcService.registerGateway(testRpcConnectionEndpointAddress, testGateway);
    TestRpcConnection connection = new TestRpcConnection(testRpcConnectionEndpointAddress, leaderId, rpcService.getScheduledExecutor(), rpcService);
    connection.start();
    // wait for connection failure
    try {
        connection.getConnectionFuture().get();
        fail("expected failure.");
    } catch (ExecutionException ee) {
        assertEquals(registrationException, ee.getCause());
    }
    // validate correct invocation and result
    assertFalse(connection.isConnected());
    assertEquals(testRpcConnectionEndpointAddress, connection.getTargetAddress());
    assertEquals(leaderId, connection.getTargetLeaderId());
    assertNull(connection.getTargetGateway());
}
Also used : TestRegistrationSuccess(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess) Either(org.apache.flink.types.Either) Executor(java.util.concurrent.Executor) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) LoggerFactory(org.slf4j.LoggerFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) Assert.assertThat(org.junit.Assert.assertThat) RpcService(org.apache.flink.runtime.rpc.RpcService) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) After(org.junit.After) TestLogger(org.apache.flink.util.TestLogger) TestRegistrationRejection(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationRejection) Matchers.is(org.hamcrest.Matchers.is) Assert.fail(org.junit.Assert.fail) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 19 with RpcService

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

the class TaskManagerRunnerConfigurationTest method testTaskManagerRpcServiceShouldBindToIpAddressDeterminedByConnectingToResourceManager.

@Test
public void testTaskManagerRpcServiceShouldBindToIpAddressDeterminedByConnectingToResourceManager() throws Exception {
    final ServerSocket testJobManagerSocket = openServerSocket();
    final Configuration config = createFlinkConfigWithJobManagerPort(testJobManagerSocket.getLocalPort());
    final HighAvailabilityServices highAvailabilityServices = createHighAvailabilityServices(config);
    RpcService taskManagerRpcService = null;
    try {
        taskManagerRpcService = TaskManagerRunner.createRpcService(config, highAvailabilityServices, RPC_SYSTEM);
        assertThat(taskManagerRpcService.getAddress(), is(ipAddress()));
    } finally {
        maybeCloseRpcService(taskManagerRpcService);
        highAvailabilityServices.closeAndCleanupAllData();
        IOUtils.closeQuietly(testJobManagerSocket);
    }
}
Also used : UnmodifiableConfiguration(org.apache.flink.configuration.UnmodifiableConfiguration) Configuration(org.apache.flink.configuration.Configuration) GlobalConfiguration(org.apache.flink.configuration.GlobalConfiguration) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) RpcService(org.apache.flink.runtime.rpc.RpcService) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 20 with RpcService

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

the class TaskManagerRunnerConfigurationTest method testTaskManagerRpcServiceShouldBindToConfiguredTaskManagerHostname.

@Test
public void testTaskManagerRpcServiceShouldBindToConfiguredTaskManagerHostname() throws Exception {
    final String taskmanagerHost = "testhostname";
    final Configuration config = createFlinkConfigWithPredefinedTaskManagerHostname(taskmanagerHost);
    final HighAvailabilityServices highAvailabilityServices = createHighAvailabilityServices(config);
    RpcService taskManagerRpcService = null;
    try {
        taskManagerRpcService = TaskManagerRunner.createRpcService(config, highAvailabilityServices, RPC_SYSTEM);
        assertThat(taskManagerRpcService.getPort(), is(greaterThanOrEqualTo(0)));
        assertThat(taskManagerRpcService.getAddress(), is(equalTo(taskmanagerHost)));
    } finally {
        maybeCloseRpcService(taskManagerRpcService);
        highAvailabilityServices.closeAndCleanupAllData();
    }
}
Also used : UnmodifiableConfiguration(org.apache.flink.configuration.UnmodifiableConfiguration) Configuration(org.apache.flink.configuration.Configuration) GlobalConfiguration(org.apache.flink.configuration.GlobalConfiguration) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) RpcService(org.apache.flink.runtime.rpc.RpcService) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

RpcService (org.apache.flink.runtime.rpc.RpcService)25 Test (org.junit.Test)15 Configuration (org.apache.flink.configuration.Configuration)13 HighAvailabilityServices (org.apache.flink.runtime.highavailability.HighAvailabilityServices)9 ExecutionException (java.util.concurrent.ExecutionException)8 TestingRpcService (org.apache.flink.runtime.rpc.TestingRpcService)7 UUID (java.util.UUID)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Before (org.junit.Before)6 FlinkException (org.apache.flink.util.FlinkException)5 TestLogger (org.apache.flink.util.TestLogger)5 After (org.junit.After)5 Assert.assertThat (org.junit.Assert.assertThat)5 Assert.fail (org.junit.Assert.fail)5 LoggerFactory (org.slf4j.LoggerFactory)5 IOException (java.io.IOException)4 TimeUnit (java.util.concurrent.TimeUnit)4 HeartbeatServices (org.apache.flink.runtime.heartbeat.HeartbeatServices)4 Mockito.anyString (org.mockito.Mockito.anyString)4 InetAddress (java.net.InetAddress)3