GJL commented on a change in pull request #9268: [FLINK-13452] Ensure to fail 
global when exception happens during reseting tasks of regions
URL: https://github.com/apache/flink/pull/9268#discussion_r310608888
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/concurrent/FutureUtilsTest.java
 ##########
 @@ -235,6 +237,57 @@ public void testRetryWithDelayCancellation() {
                assertTrue(scheduledFuture.isCancelled());
        }
 
+       /**
+        * Tests that the operation could be scheduled with expected delay.
+        */
+       @Test
+       public void testScheduleAsyncDelay() throws Exception  {
+               final Time delay = Time.milliseconds(500L);
+               final long start = System.currentTimeMillis();
+               final AtomicInteger updateValue = new AtomicInteger(0);
+
+               CompletableFuture<Integer> scheduleAsyncFuture = 
FutureUtils.scheduleAsync(
+                       () -> 
updateValue.addAndGet(ThreadLocalRandom.current().nextInt(100)),
+                       delay,
+                       TestingUtils.defaultScheduledExecutor());
+
+               int result = scheduleAsyncFuture.get();
+               long completionTime = System.currentTimeMillis() - start;
+
+               assertEquals(updateValue.get(), result);
+               assertTrue("The completion time should larger than scheduled 
delay time.", completionTime >= delay.toMilliseconds());
+       }
+
+       /**
+        * Tests that all scheduled tasks are canceled if the scheduled future 
is being cancelled.
+        */
+       @Test
+       public void testScheduleAsyncDelayCancellation() {
+               final ManuallyTriggeredScheduledExecutor scheduledExecutor = 
new ManuallyTriggeredScheduledExecutor();
+
+               CompletableFuture<?> scheduleAsyncFuture = 
FutureUtils.scheduleAsync(
+                       () -> {
+                               throw new FlinkRuntimeException("Test 
Exception");
+                       },
+                       TestingUtils.infiniteTime(),
+                       scheduledExecutor);
+
+               assertFalse(scheduleAsyncFuture.isDone());
+
+               final Collection<ScheduledFuture<?>> scheduledTasks = 
scheduledExecutor.getScheduledTasks();
+
+               assertFalse(scheduledTasks.isEmpty());
+
+               final ScheduledFuture<?> scheduledFuture = 
scheduledTasks.iterator().next();
+
+               assertFalse(scheduledFuture.isDone());
 
 Review comment:
   I don't think this assertion is needed because you already test if the 
future can be cancelled:
   
   ```
   assertTrue(scheduledFuture.isCancelled());
   ```
   
   This assertion will fail if the future is finished normally.
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to