Source:
<code>public void testChekpointingPausesAndResumeWhenTooManyCheckpoints() throws Exception{ ManualClock clock = new ManualClock(); clock.advanceTime(1, TimeUnit.DAYS); int maxCleaningCheckpoints = 1; CheckpointsCleaner checkpointsCleaner = new CheckpointsCleaner(); CheckpointRequestDecider checkpointRequestDecider = new CheckpointRequestDecider(maxCleaningCheckpoints, unused ->{}, clock, 1, new AtomicInteger(0)::get, checkpointsCleaner::getNumberOfCheckpointsToClean); final int maxCheckpointsToRetain = 1; <START> Executors.PausableThreadPoolExecutor executor = Executors.pausableExecutor(); <END> ZooKeeperCompletedCheckpointStore checkpointStore = createCompletedCheckpoints(maxCheckpointsToRetain, executor); executor.pause(); int nbCheckpointsToInject = 3; for (int i = 1; i <= nbCheckpointsToInject; i++) { TestCompletedCheckpoint completedCheckpoint = new TestCompletedCheckpoint(new JobID(), i, i, Collections.emptyMap(), CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.RETAIN_ON_FAILURE), checkpointsCleaner::cleanCheckpoint); checkpointStore.addCheckpoint(completedCheckpoint); } Thread.sleep(100L); int nbCheckpointsSubmittedForCleaningByCheckpointStore = nbCheckpointsToInject - maxCheckpointsToRetain; assertEquals(nbCheckpointsSubmittedForCleaningByCheckpointStore, checkpointsCleaner.getNumberOfCheckpointsToClean()); assertFalse(checkpointRequestDecider.chooseRequestToExecute(regularCheckpoint(), false, 0).isPresent()); executor.resume(); Thread.sleep(100L); assertTrue(checkpointsCleaner.getNumberOfCheckpointsToClean() < nbCheckpointsSubmittedForCleaningByCheckpointStore); assertTrue(checkpointRequestDecider.chooseRequestToExecute(regularCheckpoint(), false, 0).isPresent()); checkpointStore.shutdown(JobStatus.FINISHED); }</code><technical_language>I ManuallyTriggeredScheduledExecutor suffice here. consider it</technical_language>

Target:
public void testChekpointingPausesAndResumeWhenTooManyCheckpoints() throws Exception{ ManualClock clock = new ManualClock(); clock.advanceTime(1, TimeUnit.DAYS); int maxCleaningCheckpoints = 1; CheckpointsCleaner checkpointsCleaner = new CheckpointsCleaner(); CheckpointRequestDecider checkpointRequestDecider = new CheckpointRequestDecider(maxCleaningCheckpoints, unused ->{}, clock, 1, new AtomicInteger(0)::get, checkpointsCleaner::getNumberOfCheckpointsToClean); final int maxCheckpointsToRetain = 1; ManuallyTriggeredScheduledExecutor executor = new ManuallyTriggeredScheduledExecutor(); CompletedCheckpointStore checkpointStore = createCompletedCheckpoints(maxCheckpointsToRetain, executor); int nbCheckpointsToInject = 3; for (int i = 1; i <= nbCheckpointsToInject; i++) { TestCompletedCheckpoint completedCheckpoint = new TestCompletedCheckpoint(new JobID(), i, i, Collections.emptyMap(), CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.RETAIN_ON_FAILURE), checkpointsCleaner::cleanCheckpoint); checkpointStore.addCheckpoint(completedCheckpoint); } int nbCheckpointsSubmittedForCleaning = nbCheckpointsToInject - maxCheckpointsToRetain; CommonTestUtils.waitUntilCondition(() -> checkpointsCleaner.getNumberOfCheckpointsToClean() == nbCheckpointsSubmittedForCleaning, Deadline.fromNow(Duration.ofSeconds(3))); assertEquals(nbCheckpointsSubmittedForCleaning, checkpointsCleaner.getNumberOfCheckpointsToClean()); assertFalse(checkpointRequestDecider.chooseRequestToExecute(regularCheckpoint(), false, 0).isPresent()); executor.triggerAll(); CommonTestUtils.waitUntilCondition(() -> checkpointsCleaner.getNumberOfCheckpointsToClean() < nbCheckpointsSubmittedForCleaning, Deadline.fromNow(Duration.ofSeconds(3))); assertTrue(checkpointsCleaner.getNumberOfCheckpointsToClean() < nbCheckpointsSubmittedForCleaning); assertTrue(checkpointRequestDecider.chooseRequestToExecute(regularCheckpoint(), false, 0).isPresent()); checkpointStore.shutdown(JobStatus.FINISHED); }