CircuitBreakerImpl implements CircuitBreaker<ET>, CircuitBreaker.ManualModeTask<ET> { public static <E> Builder<E> newBuilder() { return new Builder<>(); } 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; }
@DataProvider(value = { "true", "false" }, splitBy = "\\|") @Test public void empty_builder_results_in_default_circuit_breaker(boolean useFactoryMethod) { CircuitBreakerImpl.Builder<Integer> builder = (useFactoryMethod) ? CircuitBreakerImpl.newBuilder() : new CircuitBreakerImpl.Builder<>(); CircuitBreakerImpl<Integer> cb = builder.build(); verifyDefaultsForEverything(cb); }
@DataProvider(value = { "true", "false" }, splitBy = "\\|") @Test public void builder_honors_values_set(boolean useFactoryMethod) { ScheduledExecutorService scheduler = mock(ScheduledExecutorService.class); ExecutorService scne = mock(ExecutorService.class); Integer maxFailures = 42; Duration resetTimeout = Duration.ofSeconds(42); Duration callTimeout = Duration.ofSeconds(4242); String id = UUID.randomUUID().toString(); BreakingEventStrategy<Integer> eventStrategy = mock(BreakingEventStrategy.class); BreakingExceptionStrategy errorStrategy = mock(BreakingExceptionStrategy.class); CircuitBreakerImpl.Builder<Integer> builder = (useFactoryMethod) ? CircuitBreakerImpl.newBuilder() : new CircuitBreakerImpl.Builder<>(); CircuitBreakerImpl<Integer> cb = builder .withScheduler(scheduler) .withStateChangeNotificationExecutor(scne) .withMaxConsecutiveFailuresAllowed(maxFailures) .withResetTimeout(resetTimeout) .withCallTimeout(callTimeout) .withId(id) .withBreakingEventStrategy(eventStrategy) .withBreakingExceptionStrategy(errorStrategy) .build(); assertThat(cb.scheduler).isSameAs(scheduler); assertThat(cb.stateChangeNotificationExecutor).isSameAs(scne); assertThat(cb.maxConsecutiveFailuresAllowed).isSameAs(maxFailures); assertThat(cb.resetTimeoutNanos).isEqualTo(resetTimeout.toNanos()); assertThat(cb.callTimeoutNanos).isEqualTo(Optional.of(callTimeout.toNanos())); assertThat(cb.id).isSameAs(id); assertThat(cb.breakingEventStrategy).isSameAs(eventStrategy); assertThat(cb.breakingExceptionStrategy).isSameAs(errorStrategy); }