Search in sources :

Example 11 with ScheduledExecutorServiceAdapter

use of org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter 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 12 with ScheduledExecutorServiceAdapter

use of org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter in project flink by apache.

the class DefaultSchedulerFactory method createInstance.

@Override
public SchedulerNG createInstance(final Logger log, final JobGraph jobGraph, final Executor ioExecutor, final Configuration jobMasterConfiguration, final SlotPoolService slotPoolService, final ScheduledExecutorService futureExecutor, final ClassLoader userCodeLoader, final CheckpointRecoveryFactory checkpointRecoveryFactory, final Time rpcTimeout, final BlobWriter blobWriter, final JobManagerJobMetricGroup jobManagerJobMetricGroup, final Time slotRequestTimeout, final ShuffleMaster<?> shuffleMaster, final JobMasterPartitionTracker partitionTracker, final ExecutionDeploymentTracker executionDeploymentTracker, long initializationTimestamp, final ComponentMainThreadExecutor mainThreadExecutor, final FatalErrorHandler fatalErrorHandler, final JobStatusListener jobStatusListener) throws Exception {
    final SlotPool slotPool = slotPoolService.castInto(SlotPool.class).orElseThrow(() -> new IllegalStateException("The DefaultScheduler requires a SlotPool."));
    final DefaultSchedulerComponents schedulerComponents = createSchedulerComponents(jobGraph.getJobType(), jobGraph.isApproximateLocalRecoveryEnabled(), jobMasterConfiguration, slotPool, slotRequestTimeout);
    final RestartBackoffTimeStrategy restartBackoffTimeStrategy = RestartBackoffTimeStrategyFactoryLoader.createRestartBackoffTimeStrategyFactory(jobGraph.getSerializedExecutionConfig().deserializeValue(userCodeLoader).getRestartStrategy(), jobMasterConfiguration, jobGraph.isCheckpointingEnabled()).create();
    log.info("Using restart back off time strategy {} for {} ({}).", restartBackoffTimeStrategy, jobGraph.getName(), jobGraph.getJobID());
    final ExecutionGraphFactory executionGraphFactory = new DefaultExecutionGraphFactory(jobMasterConfiguration, userCodeLoader, executionDeploymentTracker, futureExecutor, ioExecutor, rpcTimeout, jobManagerJobMetricGroup, blobWriter, shuffleMaster, partitionTracker);
    return new DefaultScheduler(log, jobGraph, ioExecutor, jobMasterConfiguration, schedulerComponents.getStartUpAction(), new ScheduledExecutorServiceAdapter(futureExecutor), userCodeLoader, new CheckpointsCleaner(), checkpointRecoveryFactory, jobManagerJobMetricGroup, schedulerComponents.getSchedulingStrategyFactory(), FailoverStrategyFactoryLoader.loadFailoverStrategyFactory(jobMasterConfiguration), restartBackoffTimeStrategy, new DefaultExecutionVertexOperations(), new ExecutionVertexVersioner(), schedulerComponents.getAllocatorFactory(), initializationTimestamp, mainThreadExecutor, (jobId, jobStatus, timestamp) -> {
        if (jobStatus == JobStatus.RESTARTING) {
            slotPool.setIsJobRestarting(true);
        } else {
            slotPool.setIsJobRestarting(false);
        }
        jobStatusListener.jobStatusChanges(jobId, jobStatus, timestamp);
    }, executionGraphFactory, shuffleMaster, rpcTimeout);
}
Also used : ScheduledExecutorServiceAdapter(org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter) RestartBackoffTimeStrategy(org.apache.flink.runtime.executiongraph.failover.flip1.RestartBackoffTimeStrategy) CheckpointsCleaner(org.apache.flink.runtime.checkpoint.CheckpointsCleaner) SlotPool(org.apache.flink.runtime.jobmaster.slotpool.SlotPool)

Example 13 with ScheduledExecutorServiceAdapter

use of org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter in project flink by apache.

the class CheckpointCoordinatorTest method testScheduleTriggerRequestDuringShutdown.

@Test
public void testScheduleTriggerRequestDuringShutdown() throws Exception {
    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    CheckpointCoordinator coordinator = getCheckpointCoordinator(new ScheduledExecutorServiceAdapter(executor));
    coordinator.shutdown();
    executor.shutdownNow();
    // shouldn't fail
    coordinator.scheduleTriggerRequest();
}
Also used : DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ScheduledExecutorServiceAdapter(org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter) Test(org.junit.Test)

Aggregations

ScheduledExecutorServiceAdapter (org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter)13 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)8 Test (org.junit.Test)8 JobID (org.apache.flink.api.common.JobID)3 JobResult (org.apache.flink.runtime.jobmaster.JobResult)3 ScheduledExecutor (org.apache.flink.util.concurrent.ScheduledExecutor)3 ExecutionException (java.util.concurrent.ExecutionException)2 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)2 CheckpointCoordinatorBuilder (org.apache.flink.runtime.checkpoint.CheckpointCoordinatorTestingUtils.CheckpointCoordinatorBuilder)2 CheckpointsCleaner (org.apache.flink.runtime.checkpoint.CheckpointsCleaner)2 RestartBackoffTimeStrategy (org.apache.flink.runtime.executiongraph.failover.flip1.RestartBackoffTimeStrategy)2 SlotPool (org.apache.flink.runtime.jobmaster.slotpool.SlotPool)2 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1