use of org.apache.flink.runtime.dispatcher.cleanup.DispatcherResourceCleanerFactory in project flink by apache.
the class DispatcherCleanupITCase method testCleanupThroughRetries.
@Test
public void testCleanupThroughRetries() throws Exception {
final JobGraph jobGraph = createJobGraph();
final JobID jobId = jobGraph.getJobID();
// JobGraphStore
final AtomicInteger actualGlobalCleanupCallCount = new AtomicInteger();
final OneShotLatch successfulCleanupLatch = new OneShotLatch();
final int numberOfErrors = 5;
final RuntimeException temporaryError = new RuntimeException("Expected RuntimeException: Unable to remove job graph.");
final JobGraphStore jobGraphStore = createAndStartJobGraphStoreWithCleanupFailures(numberOfErrors, temporaryError, actualGlobalCleanupCallCount, successfulCleanupLatch);
haServices.setJobGraphStore(jobGraphStore);
// Construct leader election service.
final TestingLeaderElectionService leaderElectionService = new TestingLeaderElectionService();
haServices.setJobMasterLeaderElectionService(jobId, leaderElectionService);
// start the dispatcher with enough retries on cleanup
final JobManagerRunnerRegistry jobManagerRunnerRegistry = new DefaultJobManagerRunnerRegistry(2);
final Dispatcher dispatcher = createTestingDispatcherBuilder().setResourceCleanerFactory(new DispatcherResourceCleanerFactory(ForkJoinPool.commonPool(), TestingRetryStrategies.createWithNumberOfRetries(numberOfErrors), jobManagerRunnerRegistry, haServices.getJobGraphStore(), blobServer, haServices, UnregisteredMetricGroups.createUnregisteredJobManagerMetricGroup())).build();
dispatcher.start();
toTerminate.add(dispatcher);
leaderElectionService.isLeader(UUID.randomUUID());
final DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
waitForJobToFinish(leaderElectionService, dispatcherGateway, jobId);
successfulCleanupLatch.await();
assertThat(actualGlobalCleanupCallCount.get(), equalTo(numberOfErrors + 1));
assertThat("The JobGraph should be removed from JobGraphStore.", haServices.getJobGraphStore().getJobIds(), IsEmptyCollection.empty());
CommonTestUtils.waitUntilCondition(() -> haServices.getJobResultStore().hasJobResultEntry(jobId), Deadline.fromNow(Duration.ofMinutes(5)), "The JobResultStore should have this job marked as clean.");
}
Aggregations