### Question:
ReactiveResilience4JCircuitBreaker implements ReactiveCircuitBreaker { @Override public <T> Mono<T> run(Mono<T> toRun, Function<Throwable, Mono<T>> fallback) { io.github.resilience4j.circuitbreaker.CircuitBreaker defaultCircuitBreaker = registry.circuitBreaker(id, config.getCircuitBreakerConfig()); circuitBreakerCustomizer.ifPresent(customizer -> customizer.customize(defaultCircuitBreaker)); Mono<T> toReturn = toRun.transform(CircuitBreakerOperator.of(defaultCircuitBreaker)) .timeout(config.getTimeLimiterConfig().getTimeoutDuration()) .doOnError(TimeoutException.class, t -> defaultCircuitBreaker.onError( config.getTimeLimiterConfig().getTimeoutDuration().toMillis(), TimeUnit.MILLISECONDS, t)); if (fallback != null) { toReturn = toReturn.onErrorResume(fallback); } return toReturn; } ReactiveResilience4JCircuitBreaker(String id,
			Resilience4JConfigBuilder.Resilience4JCircuitBreakerConfiguration config,
			CircuitBreakerRegistry circuitBreakerRegistry,
			Optional<Customizer<CircuitBreaker>> circuitBreakerCustomizer); @Override Mono<T> run(Mono<T> toRun, Function<Throwable, Mono<T>> fallback); Flux<T> run(Flux<T> toRun, Function<Throwable, Flux<T>> fallback);  }### Answer:
@Test public void runMono() { ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory().create("foo"); assertThat(Mono.just("foobar").transform(it -> cb.run(it)).block()).isEqualTo("foobar"); }
@Test public void runMonoWithFallback() { ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory().create("foo"); assertThat(Mono.error(new RuntimeException("boom")).transform(it -> cb.run(it, t -> Mono.just("fallback"))) .block()).isEqualTo("fallback"); }
@Test public void runFlux() { ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory().create("foo"); assertThat(Flux.just("foobar", "hello world").transform(it -> cb.run(it)).collectList().block()) .isEqualTo(Arrays.asList("foobar", "hello world")); }
@Test public void runFluxWithFallback() { ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory().create("foo"); assertThat(Flux.error(new RuntimeException("boom")).transform(it -> cb.run(it, t -> Flux.just("fallback"))) .collectList().block()).isEqualTo(Arrays.asList("fallback")); }