CircuitBreakerForHttpStatusCode extends CircuitBreakerImpl<Integer> { public static CircuitBreaker<Integer> getDefaultHttpStatusCodeCircuitBreakerForKey(String key) { return getDefaultHttpStatusCodeCircuitBreakerForKey(key, Optional.empty(), Optional.empty()); } CircuitBreakerForHttpStatusCode();  CircuitBreakerForHttpStatusCode(Optional<ScheduledExecutorService> scheduler,
                                           Optional<ExecutorService> stateChangeNotificationExecutor,
                                           Optional<Integer> maxConsecutiveFailuresAllowed,
                                           Optional<Duration> resetTimeout,
                                           Optional<Duration> callTimeout,
                                           Optional<String> id); static CircuitBreaker<Integer> getDefaultHttpStatusCodeCircuitBreakerForKey(String key); static CircuitBreaker<Integer> getDefaultHttpStatusCodeCircuitBreakerForKey(
        String key,
        Optional<ScheduledExecutorService> scheduler,
        Optional<ExecutorService> stateChangeNotificationExecutor
    ); static final BreakingEventStrategy<Integer> DEFAULT_HTTP_RESPONSE_BREAKING_EVENT_STRATEGY; }
@Test public void getDefaultHttpStatusCodeCircuitBreakerForKey_creates_and_stores_default_instances() { String key = UUID.randomUUID().toString(); CircuitBreakerForHttpStatusCode cb = (CircuitBreakerForHttpStatusCode) CircuitBreakerForHttpStatusCode .getDefaultHttpStatusCodeCircuitBreakerForKey(key); assertThat(cb.scheduler).isSameAs(cb.getDefaultScheduledExecutorService()); assertThat(cb.stateChangeNotificationExecutor).isSameAs(cb.getDefaultStateChangeNotificationExecutorService()); assertThat(cb.maxConsecutiveFailuresAllowed).isSameAs(cb.FALLBACK_DEFAULT_MAX_CONSECUTIVE_FAILURES_ALLOWED); assertThat(cb.resetTimeoutNanos).isEqualTo(Duration.ofSeconds(cb.DEFAULT_RESET_TIMEOUT_SECONDS).toNanos()); assertThat(cb.callTimeoutNanos).isEqualTo(Optional.empty()); assertThat(cb.id).isEqualTo("default-http-status-cb-for-" + key); assertThat(cb.breakingEventStrategy).isSameAs(cb.DEFAULT_HTTP_RESPONSE_BREAKING_EVENT_STRATEGY); assertThat(cb.breakingExceptionStrategy).isSameAs(cb.DEFAULT_BREAKING_EXCEPTION_STRATEGY); CircuitBreaker<Integer> subsequentCallCb = CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey(key); assertThat(subsequentCallCb).isSameAs(cb); CircuitBreakerForHttpStatusCode cbFromOtherMethod = (CircuitBreakerForHttpStatusCode) CircuitBreakerForHttpStatusCode .getDefaultHttpStatusCodeCircuitBreakerForKey( key, Optional.of(mock(ScheduledExecutorService.class)), Optional.of(mock(ExecutorService.class)) ); assertThat(cbFromOtherMethod).isSameAs(cb); assertThat(cbFromOtherMethod.scheduler).isSameAs(cb.getDefaultScheduledExecutorService()); assertThat(cbFromOtherMethod.stateChangeNotificationExecutor) .isSameAs(cb.getDefaultStateChangeNotificationExecutorService()); }
@Test public void getDefaultHttpStatusCodeCircuitBreakerForKey_with_custom_scheduler_and_executor_service_creates_and_stores_instances() { String key = UUID.randomUUID().toString(); ScheduledExecutorService scheduler = mock(ScheduledExecutorService.class); ExecutorService scne = mock(ExecutorService.class); CircuitBreakerForHttpStatusCode cb = (CircuitBreakerForHttpStatusCode) CircuitBreakerForHttpStatusCode .getDefaultHttpStatusCodeCircuitBreakerForKey(key, Optional.of(scheduler), Optional.of(scne)); assertThat(cb.scheduler).isSameAs(scheduler); assertThat(cb.stateChangeNotificationExecutor).isSameAs(scne); assertThat(cb.maxConsecutiveFailuresAllowed).isSameAs(cb.FALLBACK_DEFAULT_MAX_CONSECUTIVE_FAILURES_ALLOWED); assertThat(cb.resetTimeoutNanos).isEqualTo(Duration.ofSeconds(cb.DEFAULT_RESET_TIMEOUT_SECONDS).toNanos()); assertThat(cb.callTimeoutNanos).isEqualTo(Optional.empty()); assertThat(cb.id).isEqualTo("default-http-status-cb-for-" + key); assertThat(cb.breakingEventStrategy).isSameAs(cb.DEFAULT_HTTP_RESPONSE_BREAKING_EVENT_STRATEGY); assertThat(cb.breakingExceptionStrategy).isSameAs(cb.DEFAULT_BREAKING_EXCEPTION_STRATEGY); CircuitBreaker<Integer> subsequentCallCb = CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey(key, Optional.of(scheduler), Optional.of(scne)); assertThat(subsequentCallCb).isSameAs(cb); CircuitBreakerForHttpStatusCode cbFromOtherMethod = (CircuitBreakerForHttpStatusCode) CircuitBreakerForHttpStatusCode .getDefaultHttpStatusCodeCircuitBreakerForKey(key); assertThat(cbFromOtherMethod).isSameAs(cb); assertThat(cbFromOtherMethod.scheduler).isSameAs(scheduler); assertThat(cbFromOtherMethod.stateChangeNotificationExecutor).isSameAs(scne); }
@Test public void getDefaultHttpStatusCodeCircuitBreakerForKey_methods_convert_null_key_to_blank_string() { Optional<ScheduledExecutorService> scheduler = Optional.of(mock(ScheduledExecutorService.class)); Optional<ExecutorService> scne = Optional.of(mock(ExecutorService.class)); CircuitBreaker<Integer> nullKeyDefaultMethodResult = CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey(null); CircuitBreaker<Integer> emptyKeyDefaultMethodResult = CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey(""); CircuitBreaker<Integer> nullKeyCustomMethodResult = CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey(null, scheduler, scne); CircuitBreaker<Integer> emptyKeyCustomMethodResult = CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey("", scheduler, scne); assertThat(emptyKeyDefaultMethodResult).isSameAs(nullKeyDefaultMethodResult); assertThat(nullKeyCustomMethodResult).isSameAs(nullKeyDefaultMethodResult); assertThat(emptyKeyCustomMethodResult).isSameAs(nullKeyDefaultMethodResult); }