@Override
    public CompletableFuture<Void> cleanupAsync(JobID jobId) {
        mainThreadExecutor.assertRunningInMainThread();

        CompletableFuture<Void> cleanupFuture = FutureUtils.completedVoidFuture();
        for (CleanupWithLabel<T> cleanupWithLabel : prioritizedCleanup) {
            cleanupFuture =
                    cleanupFuture.thenCompose(
                            ignoredValue ->
                                    withRetry(
                                            jobId,
                                            cleanupWithLabel.getLabel(),
                                            cleanupWithLabel.getCleanup()));
        }

        return cleanupFuture.thenCompose(
                ignoredValue ->
                        FutureUtils.completeAll(
                                regularCleanup.stream()
                                        .map(
                                                cleanupWithLabel ->
                                                        withRetry(
                                                                jobId,
                                                                cleanupWithLabel.getLabel(),
                                                                cleanupWithLabel.getCleanup()))
                                        .collect(Collectors.toList())));
    }
@Test
    void testCleanupWithSingleRetryInHighPriorityTask() {
        final Collection<JobID> actualJobIds = new ArrayList<>();
        final CleanupCallback cleanupWithRetry = cleanupWithInitialFailingRuns(actualJobIds, 1);
        final CleanupCallback oneRunHigherPriorityCleanup =
                SingleCallCleanup.withCompletionOnCleanup();
        final SingleCallCleanup oneRunCleanup = SingleCallCleanup.withCompletionOnCleanup();

        final CompletableFuture<Void> compositeCleanupResult =
                createTestInstanceBuilder(TestingRetryStrategies.createWithNumberOfRetries(1))
                        .withPrioritizedCleanup("Prio #0", cleanupWithRetry)
                        .withPrioritizedCleanup("Prio #1", oneRunHigherPriorityCleanup)
                        .withRegularCleanup("Reg #0", oneRunCleanup)
                        .build()
                        .cleanupAsync(JOB_ID);

        assertThatFuture(compositeCleanupResult).eventuallySucceeds();

        assertThat(oneRunCleanup.getProcessedJobId()).isEqualTo(JOB_ID);
        assertThat(oneRunCleanup.isDone()).isTrue();
        assertThat(actualJobIds).containsExactly(JOB_ID, JOB_ID);
    }