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