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();
}
}
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));
}
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());
}
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);
}
}
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();
}
}
Aggregations