CircuitBreakerImpl implements CircuitBreaker<ET>, CircuitBreaker.ManualModeTask<ET> { protected boolean isExceptionACircuitBreakerFailure(Throwable throwable) { return breakingExceptionStrategy.isExceptionACircuitBreakerFailure(throwable); } CircuitBreakerImpl();  CircuitBreakerImpl(Optional<ScheduledExecutorService> scheduler,
                              Optional<ExecutorService> stateChangeNotificationExecutor,
                              Optional<Integer> maxConsecutiveFailuresAllowed,
                              Optional<Duration> resetTimeout,
                              Optional<Duration> callTimeout,
                              Optional<String> id,
                              Optional<BreakingEventStrategy<ET>> breakingEventStrategy,
                              Optional<BreakingExceptionStrategy> breakingExceptionStrategy); static Builder<E> newBuilder(); static Builder<E> newBuilder(BreakingEventStrategy<E> breakingEventStrategy); @Override ManualModeTask<ET> newManualModeTask(); @Override void throwExceptionIfCircuitBreakerIsOpen(); @Override void handleEvent(ET event); @Override void handleException(Throwable throwable); @Override CircuitBreaker<ET> originatingCircuitBreaker(); @Override CompletableFuture<ET> executeAsyncCall(Supplier<CompletableFuture<ET>> eventFutureSupplier); @Override ET executeBlockingCall(Callable<ET> eventSupplier); @Override CircuitBreakerImpl<ET> onClose(Runnable listener); @Override CircuitBreakerImpl<ET> onHalfOpen(Runnable listener); @Override CircuitBreakerImpl<ET> onOpen(Runnable listener); @Override String getId(); static final String DEFAULT_MAX_CONSECUTIVE_FAILURES_ALLOWED_SYSTEM_PROP_KEY; static final String DEFAULT_RESET_TIMEOUT_SECONDS_SYSTEM_PROP_KEY; static final int DEFAULT_MAX_CONSECUTIVE_FAILURES_ALLOWED; static final long DEFAULT_RESET_TIMEOUT_SECONDS; static final int FALLBACK_DEFAULT_MAX_CONSECUTIVE_FAILURES_ALLOWED; static final long FALLBACK_DEFAULT_RESET_TIMEOUT_SECONDS; static final BreakingEventStrategy<?> DEFAULT_BREAKING_EVENT_STRATEGY; static final BreakingExceptionStrategy DEFAULT_BREAKING_EXCEPTION_STRATEGY; }
@Test public void isExceptionACircuitBreakerFailure_returns_whatever_breakingEventStrategy_returns() { Throwable someThrowable = new Throwable(); BreakingExceptionStrategy falseDecider = ex -> false; Whitebox.setInternalState(cbSpy, "breakingExceptionStrategy", falseDecider); assertThat(cbSpy.isExceptionACircuitBreakerFailure(someThrowable)).isFalse(); BreakingExceptionStrategy trueDecider = ex -> true; Whitebox.setInternalState(cbSpy, "breakingExceptionStrategy", trueDecider); assertThat(cbSpy.isExceptionACircuitBreakerFailure(someThrowable)).isTrue(); }
@Test public void default_exception_strategy_works_as_expected() { BreakingExceptionStrategy dm = CircuitBreakerImpl.DEFAULT_BREAKING_EXCEPTION_STRATEGY; assertThat(dm.isExceptionACircuitBreakerFailure(new Throwable())).isTrue(); assertThat(dm.isExceptionACircuitBreakerFailure(new Exception())).isTrue(); assertThat(dm.isExceptionACircuitBreakerFailure(new RuntimeException())).isTrue(); assertThat(dm.isExceptionACircuitBreakerFailure(null)).isTrue(); }