Skip to content

Commit

Permalink
Issue ReactiveX#538: Removed retry interval value contraint(ReactiveX…
Browse files Browse the repository at this point in the history
  • Loading branch information
Romeh authored and RobWin committed Jul 11, 2019
1 parent b959376 commit 5eaee02
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -143,10 +143,11 @@ public Builder<T> maxAttempts(int maxAttempts) {
}

public Builder<T> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Throwable> TEST_PREDICATE = e -> "test".equals(e.getMessage());
Expand All @@ -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
Expand Down

0 comments on commit 5eaee02

Please sign in to comment.