Skip to content

Commit

Permalink
improve exception message, add test (resilience4j#2222)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukbaran authored Oct 21, 2024
1 parent a2a0616 commit ce6cf63
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public Builder() {
public Builder failureRateThreshold(float failureRateThreshold) {
if (failureRateThreshold <= 0 || failureRateThreshold > 100) {
throw new IllegalArgumentException(
"failureRateThreshold must be between 1 and 100");
"failureRateThreshold must be greater than 0 and lower than 100, but was " + failureRateThreshold);
}
this.failureRateThreshold = failureRateThreshold;
return this;
Expand All @@ -388,7 +388,7 @@ public Builder failureRateThreshold(float failureRateThreshold) {
public Builder slowCallRateThreshold(float slowCallRateThreshold) {
if (slowCallRateThreshold <= 0 || slowCallRateThreshold > 100) {
throw new IllegalArgumentException(
"slowCallRateThreshold must be between 1 and 100");
"slowCallRateThreshold must be greater than 0 and not greater than 100, but was " + slowCallRateThreshold);
}
this.slowCallRateThreshold = slowCallRateThreshold;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ public void shouldSetFailureRateThreshold() {
then(circuitBreakerConfig.getFailureRateThreshold()).isEqualTo(25);
}


@Test
public void shouldSetFailureRateThresholdAsAFloatGreaterThanZero() {
CircuitBreakerConfig circuitBreakerConfig = custom().failureRateThreshold(0.5f).build();
then(circuitBreakerConfig.getFailureRateThreshold()).isEqualTo(0.5f);
}

@Test
public void shouldSetWaitDurationInHalfOpenState() {
CircuitBreakerConfig circuitBreakerConfig = custom().maxWaitDurationInHalfOpenState(Duration.ofMillis(1000)).build();
Expand All @@ -143,6 +150,12 @@ public void shouldSetSlowCallRateThreshold() {
then(circuitBreakerConfig.getSlowCallRateThreshold()).isEqualTo(25);
}

@Test
public void shouldSetSlowCallRateThresholdAsFloatGreaterThanZero() {
CircuitBreakerConfig circuitBreakerConfig = custom().slowCallRateThreshold(0.5f).build();
then(circuitBreakerConfig.getSlowCallRateThreshold()).isEqualTo(0.5f);
}

@Test
public void shouldSetSlowCallDurationThreshold() {
CircuitBreakerConfig circuitBreakerConfig = custom()
Expand Down

0 comments on commit ce6cf63

Please sign in to comment.