use of org.apache.flink.util.concurrent.ScheduledExecutor in project flink by apache.
the class ApplicationDispatcherBootstrapTest method testErrorHandlerIsCalledWhenSubmissionThrowsAnException.
@Test
public void testErrorHandlerIsCalledWhenSubmissionThrowsAnException() throws Exception {
final AtomicBoolean shutdownCalled = new AtomicBoolean(false);
final TestingDispatcherGateway.Builder dispatcherBuilder = runningJobGatewayBuilder().setSubmitFunction(jobGraph -> {
throw new FlinkRuntimeException("Nope!");
}).setClusterShutdownFunction(status -> {
shutdownCalled.set(true);
return CompletableFuture.completedFuture(Acknowledge.get());
});
// we're "listening" on this to be completed to verify that the error handler is called.
// In production, this will shut down the cluster with an exception.
final CompletableFuture<Void> errorHandlerFuture = new CompletableFuture<>();
final ApplicationDispatcherBootstrap bootstrap = createApplicationDispatcherBootstrap(2, dispatcherBuilder.build(), scheduledExecutor, errorHandlerFuture::completeExceptionally);
final CompletableFuture<Acknowledge> completionFuture = bootstrap.getBootstrapCompletionFuture();
// we call the error handler
assertException(errorHandlerFuture, FlinkRuntimeException.class);
// we return a future that is completed exceptionally
assertException(completionFuture, FlinkRuntimeException.class);
// and cluster shutdown didn't get called
assertFalse(shutdownCalled.get());
}
use of org.apache.flink.util.concurrent.ScheduledExecutor in project flink by apache.
the class JobStatusPollingUtilsTest method testPolling.
@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);
}
}
use of org.apache.flink.util.concurrent.ScheduledExecutor in project flink by apache.
the class JobStatusPollingUtilsTest method testFailedJobResult.
@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);
}
}
use of org.apache.flink.util.concurrent.ScheduledExecutor in project flink by apache.
the class DeclarativeSlotManagerTest method testSlotReportWithConflictingJobIdDuringSlotAllocation.
/**
* Tests that a pending slot allocation is cancelled if a slot report indicates that the slot is
* already allocated by another job.
*/
@Test
public void testSlotReportWithConflictingJobIdDuringSlotAllocation() throws Exception {
final ResourceRequirements resourceRequirements = createResourceRequirementsForSingleSlot();
final ArrayBlockingQueue<SlotID> requestedSlotIds = new ArrayBlockingQueue<>(2);
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(FunctionUtils.uncheckedFunction(requestSlotParameters -> {
requestedSlotIds.put(requestSlotParameters.f0);
return new CompletableFuture<>();
})).createTestingTaskExecutorGateway();
final TaskExecutorConnection taskExecutorConnection = createTaskExecutorConnection(taskExecutorGateway);
final ResourceID resourceId = taskExecutorConnection.getResourceID();
final SlotID slotId1 = new SlotID(resourceId, 0);
final SlotID slotId2 = new SlotID(resourceId, 1);
final SlotReport slotReport = new SlotReport(Arrays.asList(createFreeSlotStatus(slotId1), createFreeSlotStatus(slotId2)));
final ScheduledExecutor mainThreadExecutor = new ManuallyTriggeredScheduledExecutor();
try (final DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().setScheduledExecutor(mainThreadExecutor).build()) {
slotManager.start(ResourceManagerId.generate(), mainThreadExecutor, new TestingResourceActionsBuilder().build());
slotManager.registerTaskManager(taskExecutorConnection, slotReport, ResourceProfile.ANY, ResourceProfile.ANY);
slotManager.processResourceRequirements(resourceRequirements);
final SlotID firstRequestedSlotId = requestedSlotIds.take();
final SlotID freeSlotId = firstRequestedSlotId.equals(slotId1) ? slotId2 : slotId1;
final SlotReport newSlotReport = new SlotReport(Arrays.asList(createAllocatedSlotStatus(firstRequestedSlotId), createFreeSlotStatus(freeSlotId)));
slotManager.reportSlotStatus(taskExecutorConnection.getInstanceID(), newSlotReport);
final SlotID secondRequestedSlotId = requestedSlotIds.take();
assertEquals(freeSlotId, secondRequestedSlotId);
}
}
use of org.apache.flink.util.concurrent.ScheduledExecutor in project flink by apache.
the class DefaultJobLeaderIdServiceTest method testIsStarted.
/**
* Tests that whether the service has been started.
*/
@Test
public void testIsStarted() throws Exception {
final JobID jobId = new JobID();
TestingHighAvailabilityServices highAvailabilityServices = new TestingHighAvailabilityServices();
SettableLeaderRetrievalService leaderRetrievalService = new SettableLeaderRetrievalService(null, null);
highAvailabilityServices.setJobMasterLeaderRetriever(jobId, leaderRetrievalService);
ScheduledExecutor scheduledExecutor = mock(ScheduledExecutor.class);
Time timeout = Time.milliseconds(5000L);
JobLeaderIdActions jobLeaderIdActions = mock(JobLeaderIdActions.class);
DefaultJobLeaderIdService jobLeaderIdService = new DefaultJobLeaderIdService(highAvailabilityServices, scheduledExecutor, timeout);
assertFalse(jobLeaderIdService.isStarted());
jobLeaderIdService.start(jobLeaderIdActions);
assertTrue(jobLeaderIdService.isStarted());
jobLeaderIdService.stop();
assertFalse(jobLeaderIdService.isStarted());
}
Aggregations