XComp commented on a change in pull request #18637:
URL: https://github.com/apache/flink/pull/18637#discussion_r801692522



##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/cleanup/DefaultResourceCleanerTest.java
##########
@@ -173,41 +205,108 @@ public void 
testMediumPriorityCleanupBlocksAllLowerPrioritizedCleanups() {
 
         lowerThanHighPriorityCleanup.completeCleanup();
 
-        
assertThat(overallCleanupResult).succeedsWithin(Duration.ofMillis(100));
+        assertThat(overallCleanupResult).succeedsWithin(Duration.ZERO);
 
         assertThat(highPriorityCleanup.isDone()).isTrue();
         assertThat(lowerThanHighPriorityCleanup.isDone()).isTrue();
         assertThat(noPriorityCleanup0.isDone()).isTrue();
         assertThat(noPriorityCleanup1.isDone()).isTrue();
     }
 
+    @Test
+    public void testCleanupWithRetries() {
+        final Collection<JobID> actualJobIds = new ArrayList<>();
+        final CleanupCallback cleanupWithRetries = 
cleanupWithRetry(actualJobIds, 2);
+        final SingleCallCleanup oneRunCleanup = 
SingleCallCleanup.withCompletionOnCleanup();
+
+        final CompletableFuture<Void> compositeCleanupResult =
+                
createTestInstanceBuilder(TestingRetryStrategies.createWithNumberOfRetries(2))
+                        .withRegularCleanup(cleanupWithRetries)
+                        .withRegularCleanup(oneRunCleanup)
+                        .build()
+                        .cleanupAsync(JOB_ID);
+
+        
assertThat(compositeCleanupResult).succeedsWithin(TIMEOUT_FOR_RUNS_WITH_RETRY);
+
+        assertThat(oneRunCleanup.getProcessedJobId()).isEqualTo(JOB_ID);
+        assertThat(oneRunCleanup.isDone()).isTrue();
+        assertThat(actualJobIds).containsExactly(JOB_ID, JOB_ID, JOB_ID);
+    }
+
+    @Test
+    public void testCleanupWithSingleRetryInHighPriorityTask() {
+        final Collection<JobID> actualJobIds = new ArrayList<>();
+        final CleanupCallback cleanupWithRetry = 
cleanupWithRetry(actualJobIds, 1);
+        final CleanupCallback oneRunHigherPriorityCleanup =
+                SingleCallCleanup.withCompletionOnCleanup();
+        final SingleCallCleanup oneRunCleanup = 
SingleCallCleanup.withCompletionOnCleanup();
+
+        final CompletableFuture<Void> compositeCleanupResult =
+                
createTestInstanceBuilder(TestingRetryStrategies.createWithNumberOfRetries(1))
+                        .withPrioritizedCleanup(cleanupWithRetry)
+                        .withPrioritizedCleanup(oneRunHigherPriorityCleanup)
+                        .withRegularCleanup(oneRunCleanup)
+                        .build()
+                        .cleanupAsync(JOB_ID);
+
+        
assertThat(compositeCleanupResult).succeedsWithin(TIMEOUT_FOR_RUNS_WITH_RETRY);
+
+        assertThat(oneRunCleanup.getProcessedJobId()).isEqualTo(JOB_ID);
+        assertThat(oneRunCleanup.isDone()).isTrue();
+        assertThat(actualJobIds).containsExactly(JOB_ID, JOB_ID);
+    }
+
     private static DefaultResourceCleaner.Builder<CleanupCallback> 
createTestInstanceBuilder() {
+        return 
createTestInstanceBuilder(TestingRetryStrategies.NO_RETRY_STRATEGY);
+    }
+
+    private static DefaultResourceCleaner.Builder<CleanupCallback> 
createTestInstanceBuilder(
+            RetryStrategy retryStrategy) {
         return DefaultResourceCleaner.forCleanableResources(
                 ComponentMainThreadExecutorServiceAdapter.forMainThread(),
                 EXECUTOR,
-                CleanupCallback::cleanup);
+                CleanupCallback::apply,
+                retryStrategy);
+    }
+
+    private static CleanupCallback cleanupWithRetry(

Review comment:
       Good point 👍 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to