use of org.apache.flink.runtime.dispatcher.cleanup.TestingResourceCleanerFactory in project flink by apache.
the class DispatcherResourceCleanupTest method testJobBeingMarkedAsCleanAfterCleanup.
@Test
public void testJobBeingMarkedAsCleanAfterCleanup() throws Exception {
final CompletableFuture<JobID> markAsCleanFuture = new CompletableFuture<>();
final JobResultStore jobResultStore = TestingJobResultStore.builder().withMarkResultAsCleanConsumer(markAsCleanFuture::complete).build();
final OneShotLatch localCleanupLatch = new OneShotLatch();
final OneShotLatch globalCleanupLatch = new OneShotLatch();
final TestingResourceCleanerFactory resourceCleanerFactory = TestingResourceCleanerFactory.builder().withLocallyCleanableResource((ignoredJobId, ignoredExecutor) -> {
try {
localCleanupLatch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return FutureUtils.completedVoidFuture();
}).withGloballyCleanableResource((ignoredJobId, ignoredExecutor) -> {
try {
globalCleanupLatch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return FutureUtils.completedVoidFuture();
}).build();
final TestingDispatcher.Builder dispatcherBuilder = createTestingDispatcherBuilder().setJobResultStore(jobResultStore).setResourceCleanerFactory(resourceCleanerFactory);
final TestingJobManagerRunnerFactory jobManagerRunnerFactory = startDispatcherAndSubmitJob(dispatcherBuilder, 0);
finishJob(jobManagerRunnerFactory.takeCreatedJobManagerRunner());
assertThat(markAsCleanFuture.isDone(), is(false));
localCleanupLatch.trigger();
assertThat(markAsCleanFuture.isDone(), is(false));
globalCleanupLatch.trigger();
assertThat(markAsCleanFuture.get(), is(jobId));
}
Aggregations