org.apache.flink.runtime.concurrent.ScheduledExecutorServiceAdapter Java Examples
The following examples show how to use
org.apache.flink.runtime.concurrent.ScheduledExecutorServiceAdapter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: YarnResourceManagerTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
MockResourceManagerRuntimeServices() throws Exception { highAvailabilityServices = new TestingHighAvailabilityServices(); rmLeaderElectionService = new TestingLeaderElectionService(); highAvailabilityServices.setResourceManagerLeaderElectionService(rmLeaderElectionService); heartbeatServices = new TestingHeartbeatServices(); metricRegistry = NoOpMetricRegistry.INSTANCE; slotManager = SlotManagerBuilder.newBuilder() .setScheduledExecutor(new ScheduledExecutorServiceAdapter(new DirectScheduledExecutorService())) .setTaskManagerRequestTimeout(Time.seconds(10)) .setSlotRequestTimeout(Time.seconds(10)) .setTaskManagerTimeout(Time.minutes(1)) .build(); jobLeaderIdService = new JobLeaderIdService( highAvailabilityServices, rpcService.getScheduledExecutor(), Time.minutes(5L)); }
Example #2
Source File: JobStatusPollingUtilsTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testFailedJobResult() throws ExecutionException, InterruptedException { final int maxAttemptCounter = 1; final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); try { final ScheduledExecutor scheduledExecutor = new ScheduledExecutorServiceAdapter(executor); final CallCountingJobStatusSupplier jobStatusSupplier = new CallCountingJobStatusSupplier(maxAttemptCounter); final CompletableFuture<JobResult> result = JobStatusPollingUtils.pollJobResultAsync( jobStatusSupplier, () -> CompletableFuture.completedFuture(createFailedJobResult(new JobID(0, 0))), scheduledExecutor, 10 ); result.join(); assertThat(jobStatusSupplier.getAttemptCounter(), is(equalTo(maxAttemptCounter))); assertTrue(result.isDone() && result.get().getSerializedThrowable().isPresent()); } finally { ExecutorUtils.gracefulShutdown(5, TimeUnit.SECONDS, executor); } }
Example #3
Source File: JobStatusPollingUtilsTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testHappyPath() throws ExecutionException, InterruptedException { final int maxAttemptCounter = 1; final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); try { final ScheduledExecutor scheduledExecutor = new ScheduledExecutorServiceAdapter(executor); final CallCountingJobStatusSupplier jobStatusSupplier = new CallCountingJobStatusSupplier(maxAttemptCounter); final CompletableFuture<JobResult> result = JobStatusPollingUtils.pollJobResultAsync( jobStatusSupplier, () -> CompletableFuture.completedFuture(createSuccessfulJobResult(new JobID(0, 0))), scheduledExecutor, 10 ); result.join(); assertThat(jobStatusSupplier.getAttemptCounter(), is(equalTo(maxAttemptCounter))); assertTrue(result.isDone() && result.get().isSuccess()); } finally { ExecutorUtils.gracefulShutdown(5, TimeUnit.SECONDS, executor); } }
Example #4
Source File: JobStatusPollingUtilsTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testPolling() { final int maxAttemptCounter = 3; final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); try { final ScheduledExecutor scheduledExecutor = new ScheduledExecutorServiceAdapter(executor); final CallCountingJobStatusSupplier jobStatusSupplier = new CallCountingJobStatusSupplier(maxAttemptCounter); final CompletableFuture<JobResult> result = JobStatusPollingUtils.pollJobResultAsync( jobStatusSupplier, () -> CompletableFuture.completedFuture(createSuccessfulJobResult(new JobID(0, 0))), scheduledExecutor, 10 ); result.join(); assertThat(jobStatusSupplier.getAttemptCounter(), is(equalTo(maxAttemptCounter))); } finally { ExecutorUtils.gracefulShutdown(5, TimeUnit.SECONDS, executor); } }
Example #5
Source File: MetricsAvailabilityITCase.java From flink with Apache License 2.0 | 5 votes |
private static <X> X fetchMetric(final SupplierWithException<CompletableFuture<X>, IOException> clientOperation, final Predicate<X> predicate) throws InterruptedException, ExecutionException, TimeoutException { final CompletableFuture<X> responseFuture = FutureUtils.retrySuccessfulWithDelay(() -> { try { return clientOperation.get(); } catch (IOException e) { throw new RuntimeException(e); } }, Time.seconds(1), Deadline.fromNow(Duration.ofSeconds(5)), predicate, new ScheduledExecutorServiceAdapter(scheduledExecutorService)); return responseFuture.get(30, TimeUnit.SECONDS); }
Example #6
Source File: JobManagerHAProcessFailureRecoveryITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void waitForTaskManagers(int numberOfTaskManagers, DispatcherGateway dispatcherGateway, FiniteDuration timeLeft) throws ExecutionException, InterruptedException { FutureUtils.retrySuccessfulWithDelay( () -> dispatcherGateway.requestClusterOverview(Time.milliseconds(timeLeft.toMillis())), Time.milliseconds(50L), org.apache.flink.api.common.time.Deadline.fromNow(Duration.ofMillis(timeLeft.toMillis())), clusterOverview -> clusterOverview.getNumTaskManagersConnected() >= numberOfTaskManagers, new ScheduledExecutorServiceAdapter(Executors.newSingleThreadScheduledExecutor())) .get(); }
Example #7
Source File: RestClusterClient.java From flink with Apache License 2.0 | 5 votes |
private <C> CompletableFuture<C> retry( CheckedSupplier<CompletableFuture<C>> operation, Predicate<Throwable> retryPredicate) { return FutureUtils.retryWithDelay( CheckedSupplier.unchecked(operation), restClusterClientConfiguration.getRetryMaxAttempts(), Time.milliseconds(restClusterClientConfiguration.getRetryDelay()), retryPredicate, new ScheduledExecutorServiceAdapter(retryExecutorService)); }
Example #8
Source File: MockResourceManagerRuntimeServices.java From flink with Apache License 2.0 | 5 votes |
public MockResourceManagerRuntimeServices(RpcService rpcService, Time timeout) { this(rpcService, timeout, SlotManagerBuilder.newBuilder() .setScheduledExecutor(new ScheduledExecutorServiceAdapter(new DirectScheduledExecutorService())) .setTaskManagerRequestTimeout(Time.seconds(10)) .setSlotRequestTimeout(Time.seconds(10)) .setTaskManagerTimeout(Time.minutes(1)) .build()); }
Example #9
Source File: BackPressureSampleServiceTest.java From flink with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws Exception { scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); final ScheduledExecutor scheduledExecutor = new ScheduledExecutorServiceAdapter(scheduledExecutorService); backPressureSampleService = new BackPressureSampleService(10, Time.milliseconds(10), scheduledExecutor); }
Example #10
Source File: CheckpointCoordinatorTriggeringTest.java From flink with Apache License 2.0 | 5 votes |
/** * This test only fails eventually. */ @Test public void discardingTriggeringCheckpointWillExecuteNextCheckpointRequest() throws Exception { final ExecutionVertex executionVertex = mockExecutionVertex(new ExecutionAttemptID()); final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); final CheckpointCoordinator checkpointCoordinator = new CheckpointCoordinatorTestingUtils.CheckpointCoordinatorBuilder() .setTasks(new ExecutionVertex[]{executionVertex}) .setTimer(new ScheduledExecutorServiceAdapter(scheduledExecutorService)) .setCheckpointCoordinatorConfiguration(CheckpointCoordinatorConfiguration.builder() .build()) .build(); final CompletableFuture<String> masterHookCheckpointFuture = new CompletableFuture<>(); final OneShotLatch triggerCheckpointLatch = new OneShotLatch(); checkpointCoordinator.addMasterHook(new TestingMasterHook(masterHookCheckpointFuture, triggerCheckpointLatch)); try { checkpointCoordinator.triggerCheckpoint(false); final CompletableFuture<CompletedCheckpoint> secondCheckpoint = checkpointCoordinator.triggerCheckpoint(false); triggerCheckpointLatch.await(); masterHookCheckpointFuture.complete("Completed"); // discard triggering checkpoint checkpointCoordinator.abortPendingCheckpoints(new CheckpointException(CheckpointFailureReason.CHECKPOINT_DECLINED)); try { // verify that the second checkpoint request will be executed and eventually times out secondCheckpoint.get(); fail("Expected the second checkpoint to fail."); } catch (ExecutionException ee) { assertThat(ExceptionUtils.stripExecutionException(ee), instanceOf(CheckpointException.class)); } } finally { checkpointCoordinator.shutdown(JobStatus.FINISHED); ExecutorUtils.gracefulShutdown(10L, TimeUnit.SECONDS, scheduledExecutorService); } }
Example #11
Source File: JobManagerHAProcessFailureRecoveryITCase.java From flink with Apache License 2.0 | 5 votes |
private void waitForTaskManagers(int numberOfTaskManagers, DispatcherGateway dispatcherGateway, Duration timeLeft) throws ExecutionException, InterruptedException { FutureUtils.retrySuccessfulWithDelay( () -> dispatcherGateway.requestClusterOverview(Time.milliseconds(timeLeft.toMillis())), Time.milliseconds(50L), org.apache.flink.api.common.time.Deadline.fromNow(Duration.ofMillis(timeLeft.toMillis())), clusterOverview -> clusterOverview.getNumTaskManagersConnected() >= numberOfTaskManagers, new ScheduledExecutorServiceAdapter(Executors.newSingleThreadScheduledExecutor())) .get(); }
Example #12
Source File: MetricsAvailabilityITCase.java From flink with Apache License 2.0 | 5 votes |
private static <X> X fetchMetric(final SupplierWithException<CompletableFuture<X>, IOException> clientOperation, final Predicate<X> predicate) throws InterruptedException, ExecutionException, TimeoutException { final CompletableFuture<X> responseFuture = FutureUtils.retrySuccessfulWithDelay(() -> { try { return clientOperation.get(); } catch (IOException e) { throw new RuntimeException(e); } }, Time.seconds(1), Deadline.fromNow(Duration.ofSeconds(5)), predicate, new ScheduledExecutorServiceAdapter(scheduledExecutorService)); return responseFuture.get(30, TimeUnit.SECONDS); }
Example #13
Source File: RestClusterClient.java From flink with Apache License 2.0 | 5 votes |
private <C> CompletableFuture<C> retry( CheckedSupplier<CompletableFuture<C>> operation, Predicate<Throwable> retryPredicate) { return FutureUtils.retryWithDelay( CheckedSupplier.unchecked(operation), restClusterClientConfiguration.getRetryMaxAttempts(), Time.milliseconds(restClusterClientConfiguration.getRetryDelay()), retryPredicate, new ScheduledExecutorServiceAdapter(retryExecutorService)); }
Example #14
Source File: MockResourceManagerRuntimeServices.java From flink with Apache License 2.0 | 5 votes |
public MockResourceManagerRuntimeServices(RpcService rpcService, Time timeout) { this(rpcService, timeout, SlotManagerBuilder.newBuilder() .setScheduledExecutor(new ScheduledExecutorServiceAdapter(new DirectScheduledExecutorService())) .setTaskManagerRequestTimeout(Time.seconds(10)) .setSlotRequestTimeout(Time.seconds(10)) .setTaskManagerTimeout(Time.minutes(1)) .build()); }
Example #15
Source File: StackTraceSampleServiceTest.java From flink with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); final ScheduledExecutor scheduledExecutor = new ScheduledExecutorServiceAdapter(scheduledExecutorService); stackTraceSampleService = new StackTraceSampleService(scheduledExecutor); }
Example #16
Source File: JobManagerHAProcessFailureRecoveryITCase.java From flink with Apache License 2.0 | 5 votes |
private void waitForTaskManagers(int numberOfTaskManagers, DispatcherGateway dispatcherGateway, FiniteDuration timeLeft) throws ExecutionException, InterruptedException { FutureUtils.retrySuccessfulWithDelay( () -> dispatcherGateway.requestClusterOverview(Time.milliseconds(timeLeft.toMillis())), Time.milliseconds(50L), org.apache.flink.api.common.time.Deadline.fromNow(Duration.ofMillis(timeLeft.toMillis())), clusterOverview -> clusterOverview.getNumTaskManagersConnected() >= numberOfTaskManagers, new ScheduledExecutorServiceAdapter(Executors.newSingleThreadScheduledExecutor())) .get(); }
Example #17
Source File: MetricsAvailabilityITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private static <X> X fetchMetric(final SupplierWithException<CompletableFuture<X>, IOException> clientOperation, final Predicate<X> predicate) throws InterruptedException, ExecutionException, TimeoutException { final CompletableFuture<X> responseFuture = FutureUtils.retrySuccessfulWithDelay(() -> { try { return clientOperation.get(); } catch (IOException e) { throw new RuntimeException(e); } }, Time.seconds(1), Deadline.fromNow(Duration.ofSeconds(5)), predicate, new ScheduledExecutorServiceAdapter(scheduledExecutorService)); return responseFuture.get(30, TimeUnit.SECONDS); }
Example #18
Source File: RestClusterClient.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private <C> CompletableFuture<C> retry( CheckedSupplier<CompletableFuture<C>> operation, Predicate<Throwable> retryPredicate) { return FutureUtils.retryWithDelay( CheckedSupplier.unchecked(operation), restClusterClientConfiguration.getRetryMaxAttempts(), Time.milliseconds(restClusterClientConfiguration.getRetryDelay()), retryPredicate, new ScheduledExecutorServiceAdapter(retryExecutorService)); }
Example #19
Source File: StackTraceSampleServiceTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); final ScheduledExecutor scheduledExecutor = new ScheduledExecutorServiceAdapter(scheduledExecutorService); stackTraceSampleService = new StackTraceSampleService(scheduledExecutor); }
Example #20
Source File: DefaultSchedulerFactory.java From flink with Apache License 2.0 | 4 votes |
@Override public SchedulerNG createInstance( final Logger log, final JobGraph jobGraph, final BackPressureStatsTracker backPressureStatsTracker, final Executor ioExecutor, final Configuration jobMasterConfiguration, final SlotProvider slotProvider, 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) throws Exception { final SchedulingStrategyFactory schedulingStrategyFactory = createSchedulingStrategyFactory(jobGraph.getScheduleMode()); 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 ExecutionSlotAllocatorFactory slotAllocatorFactory = createExecutionSlotAllocatorFactory( jobGraph.getScheduleMode(), slotProvider, slotRequestTimeout, schedulingStrategyFactory); return new DefaultScheduler( log, jobGraph, backPressureStatsTracker, ioExecutor, jobMasterConfiguration, futureExecutor, new ScheduledExecutorServiceAdapter(futureExecutor), userCodeLoader, checkpointRecoveryFactory, rpcTimeout, blobWriter, jobManagerJobMetricGroup, shuffleMaster, partitionTracker, schedulingStrategyFactory, FailoverStrategyFactoryLoader.loadFailoverStrategyFactory(jobMasterConfiguration), restartBackoffTimeStrategy, new DefaultExecutionVertexOperations(), new ExecutionVertexVersioner(), slotAllocatorFactory); }
Example #21
Source File: HeartbeatManagerTest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests that the heartbeat target {@link ResourceID} is properly passed to the {@link HeartbeatListener} by the * {@link HeartbeatManagerSenderImpl}. */ @Test public void testHeartbeatManagerSenderTargetPayload() throws Exception { final long heartbeatTimeout = 100L; final long heartbeatPeriod = 2000L; final ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); final ResourceID someTargetId = ResourceID.generate(); final ResourceID specialTargetId = ResourceID.generate(); final OneShotLatch someTargetReceivedLatch = new OneShotLatch(); final OneShotLatch specialTargetReceivedLatch = new OneShotLatch(); final TargetDependentHeartbeatReceiver someHeartbeatTarget = new TargetDependentHeartbeatReceiver(someTargetReceivedLatch); final TargetDependentHeartbeatReceiver specialHeartbeatTarget = new TargetDependentHeartbeatReceiver(specialTargetReceivedLatch); final int defaultResponse = 0; final int specialResponse = 1; HeartbeatManager<?, Integer> heartbeatManager = new HeartbeatManagerSenderImpl<>( heartbeatPeriod, heartbeatTimeout, ResourceID.generate(), new TargetDependentHeartbeatSender(specialTargetId, specialResponse, defaultResponse), new ScheduledExecutorServiceAdapter(scheduledThreadPoolExecutor), LOG); try { heartbeatManager.monitorTarget(someTargetId, someHeartbeatTarget); heartbeatManager.monitorTarget(specialTargetId, specialHeartbeatTarget); someTargetReceivedLatch.await(5, TimeUnit.SECONDS); specialTargetReceivedLatch.await(5, TimeUnit.SECONDS); assertEquals(defaultResponse, someHeartbeatTarget.getLastRequestedHeartbeatPayload()); assertEquals(specialResponse, specialHeartbeatTarget.getLastRequestedHeartbeatPayload()); } finally { heartbeatManager.stop(); scheduledThreadPoolExecutor.shutdown(); } }
Example #22
Source File: HeartbeatManagerTest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests that the heartbeat target {@link ResourceID} is properly passed to the {@link HeartbeatListener} by the * {@link HeartbeatManagerSenderImpl}. */ @Test public void testHeartbeatManagerSenderTargetPayload() throws Exception { final long heartbeatTimeout = 100L; final long heartbeatPeriod = 2000L; final ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); final ResourceID someTargetId = ResourceID.generate(); final ResourceID specialTargetId = ResourceID.generate(); final OneShotLatch someTargetReceivedLatch = new OneShotLatch(); final OneShotLatch specialTargetReceivedLatch = new OneShotLatch(); final TargetDependentHeartbeatReceiver someHeartbeatTarget = new TargetDependentHeartbeatReceiver(someTargetReceivedLatch); final TargetDependentHeartbeatReceiver specialHeartbeatTarget = new TargetDependentHeartbeatReceiver(specialTargetReceivedLatch); final int defaultResponse = 0; final int specialResponse = 1; HeartbeatManager<?, Integer> heartbeatManager = new HeartbeatManagerSenderImpl<>( heartbeatPeriod, heartbeatTimeout, ResourceID.generate(), new TargetDependentHeartbeatSender(specialTargetId, specialResponse, defaultResponse), new ScheduledExecutorServiceAdapter(scheduledThreadPoolExecutor), LOG); try { heartbeatManager.monitorTarget(someTargetId, someHeartbeatTarget); heartbeatManager.monitorTarget(specialTargetId, specialHeartbeatTarget); someTargetReceivedLatch.await(5, TimeUnit.SECONDS); specialTargetReceivedLatch.await(5, TimeUnit.SECONDS); assertEquals(defaultResponse, someHeartbeatTarget.getLastRequestedHeartbeatPayload()); assertEquals(specialResponse, specialHeartbeatTarget.getLastRequestedHeartbeatPayload()); } finally { heartbeatManager.stop(); scheduledThreadPoolExecutor.shutdown(); } }
Example #23
Source File: HeartbeatManagerTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * Tests that the heartbeat target {@link ResourceID} is properly passed to the {@link HeartbeatListener} by the * {@link HeartbeatManagerSenderImpl}. */ @Test public void testHeartbeatManagerSenderTargetPayload() throws Exception { final long heartbeatTimeout = 100L; final long heartbeatPeriod = 2000L; final ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); final ResourceID someTargetId = ResourceID.generate(); final ResourceID specialTargetId = ResourceID.generate(); final OneShotLatch someTargetReceivedLatch = new OneShotLatch(); final OneShotLatch specialTargetReceivedLatch = new OneShotLatch(); final TargetDependentHeartbeatReceiver someHeartbeatTarget = new TargetDependentHeartbeatReceiver(someTargetReceivedLatch); final TargetDependentHeartbeatReceiver specialHeartbeatTarget = new TargetDependentHeartbeatReceiver(specialTargetReceivedLatch); final int defaultResponse = 0; final int specialResponse = 1; HeartbeatManager<?, Integer> heartbeatManager = new HeartbeatManagerSenderImpl<>( heartbeatPeriod, heartbeatTimeout, ResourceID.generate(), new TargetDependentHeartbeatSender(specialTargetId, specialResponse, defaultResponse), new ScheduledExecutorServiceAdapter(scheduledThreadPoolExecutor), LOG); try { heartbeatManager.monitorTarget(someTargetId, someHeartbeatTarget); heartbeatManager.monitorTarget(specialTargetId, specialHeartbeatTarget); someTargetReceivedLatch.await(5, TimeUnit.SECONDS); specialTargetReceivedLatch.await(5, TimeUnit.SECONDS); assertEquals(defaultResponse, someHeartbeatTarget.getLastRequestedHeartbeatPayload()); assertEquals(specialResponse, specialHeartbeatTarget.getLastRequestedHeartbeatPayload()); } finally { heartbeatManager.stop(); scheduledThreadPoolExecutor.shutdown(); } }