From d80a29c48cc5a29b0ef3888d6e2f6aa678742de3 Mon Sep 17 00:00:00 2001 From: zhihuasu <126552658+zhihuasu1@users.noreply.github.com> Date: Thu, 25 Jan 2024 15:07:11 +0800 Subject: [PATCH] [BUG] #15013 Fix retryInterval in RetryPolicy will never be used in RetryUtils (#15014) * Update RetryUtils.java assigned * UT * Update RetryUtilsTest.java --------- Co-authored-by: xiangzihao <460888207@qq.com> Co-authored-by: Rick Cheng --- .../dolphinscheduler/plugin/task/api/utils/RetryUtils.java | 2 +- .../plugin/task/api/utils/RetryUtilsTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtils.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtils.java index 1246d85f15..e9672eaad8 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtils.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtils.java @@ -41,7 +41,7 @@ public class RetryUtils { */ public static T retryFunction(@NonNull Supplier supplier, @NonNull RetryPolicy retryPolicy) { int retryCount = 0; - long retryInterval = 0L; + long retryInterval = retryPolicy.getRetryInterval(); while (true) { try { return supplier.get(); diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtilsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtilsTest.java index 9f402c81c0..2df0cfe8e5 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtilsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/RetryUtilsTest.java @@ -37,6 +37,13 @@ public class RetryUtilsTest { Assertions.fail(); }); + long startTime = System.currentTimeMillis(); + Assertions.assertThrows(RuntimeException.class, () -> RetryUtils.retryFunction((Supplier) () -> { + throw new RuntimeException("Test failed function"); + }, new RetryUtils.RetryPolicy(3, 1000L))); + long endTime = System.currentTimeMillis(); + long elapsedTime = endTime - startTime; + Assertions.assertTrue(elapsedTime >= 3000L && elapsedTime < 4000L); } }