CircuitBreakerImpl implements CircuitBreaker<ET>, CircuitBreaker.ManualModeTask<ET> { protected boolean isEventACircuitBreakerFailure(ET event) { return breakingEventStrategy.isEventACircuitBreakerFailure(event); } 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 default_event_strategy_works_as_expected() { BreakingEventStrategy<Object> dm = (BreakingEventStrategy<Object>) CircuitBreakerImpl.DEFAULT_BREAKING_EVENT_STRATEGY; assertThat(dm.isEventACircuitBreakerFailure(new Object())).isFalse(); assertThat(dm.isEventACircuitBreakerFailure("foo")).isFalse(); assertThat(dm.isEventACircuitBreakerFailure(null)).isFalse(); }
@Test public void isEventACircuitBreakerFailure_returns_whatever_breakingEventStrategy_returns() { BreakingEventStrategy<String> falseDecider = theString -> false; Whitebox.setInternalState(cbSpy, "breakingEventStrategy", falseDecider); assertThat(cbSpy.isEventACircuitBreakerFailure("foo")).isFalse(); BreakingEventStrategy<String> trueDecider = theString -> true; Whitebox.setInternalState(cbSpy, "breakingEventStrategy", trueDecider); assertThat(cbSpy.isEventACircuitBreakerFailure("foo")).isTrue(); }