Skip to content

Commit

Permalink
fix 2097 (resilience4j#2193)
Browse files Browse the repository at this point in the history
* fix 2097

* fix assertion
  • Loading branch information
dowenliu-xyz authored Sep 3, 2024
1 parent 2ceed95 commit 27b21ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public Builder<T> maxAttempts(int maxAttempts) {

public Builder<T> 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");
Expand Down Expand Up @@ -311,6 +311,7 @@ public Builder<T> writableStackTraceEnabled(boolean bool) {
*/
public Builder<T> intervalFunction(IntervalFunction f) {
this.intervalFunction = f;
this.intervalBiFunction = null;
return this;
}

Expand All @@ -322,6 +323,7 @@ public Builder<T> intervalFunction(IntervalFunction f) {
*/
public Builder<T> intervalBiFunction(IntervalBiFunction<T> f) {
this.intervalBiFunction = f;
this.intervalFunction = null;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> 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<Object> 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
Expand Down

0 comments on commit 27b21ff

Please sign in to comment.