[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 <rickchengx@gmail.com>
This commit is contained in:
zhihuasu 2024-01-25 15:07:11 +08:00 committed by GitHub
parent 8abb5e55b7
commit d80a29c48c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -41,7 +41,7 @@ public class RetryUtils {
*/
public static <T> T retryFunction(@NonNull Supplier<T> supplier, @NonNull RetryPolicy retryPolicy) {
int retryCount = 0;
long retryInterval = 0L;
long retryInterval = retryPolicy.getRetryInterval();
while (true) {
try {
return supplier.get();

View File

@ -37,6 +37,13 @@ public class RetryUtilsTest {
Assertions.fail();
});
long startTime = System.currentTimeMillis();
Assertions.assertThrows(RuntimeException.class, () -> RetryUtils.retryFunction((Supplier<Boolean>) () -> {
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);
}
}