Search in sources :

Example 1 with Failure

use of org.apache.flink.runtime.registration.RegistrationResponse.Failure in project flink by apache.

the class TaskExecutorTest method testMaximumRegistrationDurationAfterConnectionLoss.

@Test
public void testMaximumRegistrationDurationAfterConnectionLoss() throws Exception {
    configuration.set(TaskManagerOptions.REGISTRATION_TIMEOUT, TimeUtils.parseDuration("100 ms"));
    final TaskSlotTable<Task> taskSlotTable = TaskSlotUtils.createTaskSlotTable(1);
    final TaskManagerServices taskManagerServices = new TaskManagerServicesBuilder().setTaskSlotTable(taskSlotTable).build();
    final TaskExecutor taskExecutor = createTaskExecutor(taskManagerServices, new HeartbeatServices(10L, 10L));
    taskExecutor.start();
    final CompletableFuture<ResourceID> registrationFuture = new CompletableFuture<>();
    final OneShotLatch secondRegistration = new OneShotLatch();
    try {
        final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway();
        testingResourceManagerGateway.setRegisterTaskExecutorFunction(taskExecutorRegistration -> {
            if (registrationFuture.complete(taskExecutorRegistration.getResourceId())) {
                return createRegistrationResponse(testingResourceManagerGateway);
            } else {
                secondRegistration.trigger();
                return CompletableFuture.completedFuture(new Failure(new FlinkException("Only the first registration should succeed.")));
            }
        });
        rpc.registerGateway(testingResourceManagerGateway.getAddress(), testingResourceManagerGateway);
        resourceManagerLeaderRetriever.notifyListener(testingResourceManagerGateway.getAddress(), UUID.randomUUID());
        final ResourceID registrationResourceId = registrationFuture.get();
        assertThat(registrationResourceId, equalTo(taskManagerServices.getUnresolvedTaskManagerLocation().getResourceID()));
        secondRegistration.await();
        final Throwable error = testingFatalErrorHandler.getErrorFuture().get();
        assertThat(error, is(notNullValue()));
        assertThat(ExceptionUtils.stripExecutionException(error), instanceOf(RegistrationTimeoutException.class));
        testingFatalErrorHandler.clearError();
    } finally {
        RpcUtils.terminateRpcEndpoint(taskExecutor, timeout);
    }
}
Also used : HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) TestingHeartbeatServices(org.apache.flink.runtime.heartbeat.TestingHeartbeatServices) Task(org.apache.flink.runtime.taskmanager.Task) RegistrationTimeoutException(org.apache.flink.runtime.taskexecutor.exceptions.RegistrationTimeoutException) FlinkException(org.apache.flink.util.FlinkException) CompletableFuture(java.util.concurrent.CompletableFuture) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TestingResourceManagerGateway(org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) Failure(org.apache.flink.runtime.registration.RegistrationResponse.Failure) Test(org.junit.Test)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)1 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)1 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)1 HeartbeatServices (org.apache.flink.runtime.heartbeat.HeartbeatServices)1 TestingHeartbeatServices (org.apache.flink.runtime.heartbeat.TestingHeartbeatServices)1 Failure (org.apache.flink.runtime.registration.RegistrationResponse.Failure)1 TestingResourceManagerGateway (org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway)1 RegistrationTimeoutException (org.apache.flink.runtime.taskexecutor.exceptions.RegistrationTimeoutException)1 Task (org.apache.flink.runtime.taskmanager.Task)1 FlinkException (org.apache.flink.util.FlinkException)1 Test (org.junit.Test)1