Reputation: 1
I have created a circuit breaker with the following config
CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom()
.failureRateThreshold("80f")
.waitDurationInOpenState(Duration.ofSeconds(Duration.ofSeconds(10)))
.maxWaitDurationInHalfOpenState(Duration.ofSeconds(10))
.automaticTransitionFromOpenToHalfOpenEnabled(true)
.build()
Code that will open or close the circuit breaker
if (CircuitBreaker.State.CLOSED.equals(circuitBreaker.getState())) {
CheckedFunction0<String> saveAltTextSupplier = CircuitBreaker.decorateCheckedSupplier(defaultCircuitBreaker, () -> client.predict(details, throwError));
Try<String> saveAltTextResult = Try.of(saveAltTextSupplier);
if(saveAltTextResult != null && saveAltTextResult.isSuccess()){
return saveAltTextResult.get();
}
return null;
}
throw new IllegalStateException("Blocking AltText downstream API call due to circuit breaker open");
}
client.predict function details
public String predict(AssetBase64 assetBase64, boolean throwError) throws RuntimeException{
String altText;
if(throwError) {
throw new NullPointerException("");
}else{
return "";
}
}
I initially send throwError value as true to simulate error in the method and after multiple request the circuit breaker opens. However, when I set the value as false and start sending request after 10 seconds since the waitDurationInOpenState is 10 seconds the circuit breaker still remains open and doesn't get closed.
It is not even going to Half open state.
Upvotes: 0
Views: 99