From 5eaee02bdb6d95c8808403f7e7be4789b161ef89 Mon Sep 17 00:00:00 2001 From: MRomeh Date: Thu, 11 Jul 2019 12:10:06 +0200 Subject: [PATCH] Issue #538: Removed retry interval value contraint(#539) --- .../resilience4j/retry/RetryConfig.java | 13 +++++----- .../retry/RetryConfigBuilderTest.java | 25 ++++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/resilience4j-retry/src/main/java/io/github/resilience4j/retry/RetryConfig.java b/resilience4j-retry/src/main/java/io/github/resilience4j/retry/RetryConfig.java index 13f10cc023..9ded87babd 100644 --- a/resilience4j-retry/src/main/java/io/github/resilience4j/retry/RetryConfig.java +++ b/resilience4j-retry/src/main/java/io/github/resilience4j/retry/RetryConfig.java @@ -19,13 +19,13 @@ package io.github.resilience4j.retry; -import io.github.resilience4j.core.lang.Nullable; -import io.github.resilience4j.core.predicate.PredicateCreator; - import java.time.Duration; import java.util.function.Function; import java.util.function.Predicate; +import io.github.resilience4j.core.lang.Nullable; +import io.github.resilience4j.core.predicate.PredicateCreator; + public class RetryConfig { private static final int DEFAULT_MAX_ATTEMPTS = 3; @@ -143,10 +143,11 @@ public Builder maxAttempts(int maxAttempts) { } public Builder waitDuration(Duration waitDuration) { - if (waitDuration.toMillis() < 10) { - throw new IllegalArgumentException("waitDurationInOpenState must be at least 10ms"); + if (waitDuration.toMillis() >= 0) { + this.intervalFunction = (x) -> waitDuration.toMillis(); + } else { + throw new IllegalArgumentException("waitDurationInOpenState must be a positive value"); } - this.intervalFunction = (x) -> waitDuration.toMillis(); return this; } diff --git a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/RetryConfigBuilderTest.java b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/RetryConfigBuilderTest.java index e99992674e..e7259619a6 100644 --- a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/RetryConfigBuilderTest.java +++ b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/RetryConfigBuilderTest.java @@ -18,14 +18,14 @@ */ package io.github.resilience4j.retry; -import org.assertj.core.api.Assertions; -import org.junit.Test; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.api.Java6Assertions.assertThat; import java.time.Duration; import java.util.function.Predicate; -import static org.assertj.core.api.BDDAssertions.then; -import static org.assertj.core.api.Java6Assertions.assertThat; +import org.assertj.core.api.Assertions; +import org.junit.Test; public class RetryConfigBuilderTest { private static final Predicate TEST_PREDICATE = e -> "test".equals(e.getMessage()); @@ -35,14 +35,21 @@ public void zeroMaxAttemptsShouldFail() { RetryConfig.custom().maxAttempts(0).build(); } - @Test(expected = IllegalArgumentException.class) - public void zeroWaitIntervalShouldFail() { - RetryConfig.custom().waitDuration(Duration.ofMillis(0)).build(); + @Test + public void zeroWaitInterval() { + final RetryConfig config = RetryConfig.custom().waitDuration(Duration.ofMillis(0)).build(); + assertThat(config.getIntervalFunction().apply(1)).isEqualTo(0); + } + + @Test + public void waitIntervalUnderTenMillisShouldSucceed() { + RetryConfig config = RetryConfig.custom().waitDuration(Duration.ofMillis(5)).build(); + assertThat(config.getIntervalFunction().apply(1).compareTo(5L)); } @Test(expected = IllegalArgumentException.class) - public void waitIntervalUnderTenMillisShouldFail() { - RetryConfig.custom().waitDuration(Duration.ofMillis(5)).build(); + public void waitIntervalUnderZeroShouldFail() { + RetryConfig.custom().waitDuration(Duration.ofMillis(-1)).build(); } @Test