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 3a2bc62d9..502138549 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 @@ -245,7 +245,7 @@ public Builder maxAttempts(int maxAttempts) { public Builder waitDuration(Duration waitDuration) { if (waitDuration.toMillis() >= 0) { - this.intervalBiFunction = (attempt, either) -> waitDuration.toMillis(); + this.intervalBiFunction((attempt, either) -> waitDuration.toMillis()); } else { throw new IllegalArgumentException( "waitDuration must be a positive value"); @@ -311,6 +311,7 @@ public Builder writableStackTraceEnabled(boolean bool) { */ public Builder intervalFunction(IntervalFunction f) { this.intervalFunction = f; + this.intervalBiFunction = null; return this; } @@ -322,6 +323,7 @@ public Builder intervalFunction(IntervalFunction f) { */ public Builder intervalBiFunction(IntervalBiFunction f) { this.intervalBiFunction = f; + this.intervalFunction = null; 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 f49eb1458..c51cbdb60 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 @@ -216,11 +216,29 @@ public void shouldBuilderCreateConfigEveryTime() { assertThat(config1.getMaxAttempts()).isEqualTo(5); } - @Test(expected = IllegalStateException.class) - public void intervalFunctionUsedWithIntervalBiFunctionShouldFail() { - RetryConfig.custom().intervalBiFunction((attempt, either) -> 100L) - .intervalFunction(IntervalFunction.ofDefaults()) - .build(); + @Test() + public void intervalFunctionClearIntervalBiFunction() { + IntervalBiFunction biFunction = (attempt, either) -> 100L; + IntervalFunction function = IntervalFunction.ofDefaults(); + RetryConfig config = RetryConfig.custom().intervalBiFunction(biFunction) + .intervalFunction(function) + .build(); + assertThat(config).isNotNull(); + assertThat(config.getIntervalFunction()).isEqualTo(function); + assertThat(config.getIntervalBiFunction()).isNotEqualTo(biFunction); + } + + @Test + public void intervalBiFunctionClearIntervalFunction() { + IntervalBiFunction biFunction = (attempt, either) -> 100L; + IntervalFunction function = IntervalFunction.ofDefaults(); + RetryConfig config = RetryConfig.custom().intervalFunction(function) + .intervalBiFunction(biFunction) + .build(); + assertThat(config).isNotNull(); + assertThat(config.getIntervalFunction()).isNull(); + assertThat(config.getIntervalFunction()).isNotEqualTo(function); + assertThat(config.getIntervalBiFunction()).isEqualTo(biFunction); } @Test