diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfiguration.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfiguration.java index 45d7cdd3..58c0a9a6 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfiguration.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfiguration.java @@ -86,7 +86,7 @@ public void init() { if (factory != null) { if (taggedCircuitBreakerMetrics == null) { taggedCircuitBreakerMetrics = TaggedCircuitBreakerMetrics - .ofCircuitBreakerRegistry(factory.getCircuitBreakerRegistry()); + .ofCircuitBreakerRegistry(factory.getCircuitBreakerRegistry()); } taggedCircuitBreakerMetrics.bindTo(meterRegistry); } diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreaker.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreaker.java index 11bd5b56..f4966ddb 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreaker.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreaker.java @@ -91,11 +91,11 @@ public Mono run(Mono toRun, Function> fallback) { if (tuple.getT2().isPresent()) { final Duration timeoutDuration = tuple.getT2().get().getTimeLimiterConfig().getTimeoutDuration(); toReturn = toReturn.timeout(timeoutDuration) - // Since we are using the Mono timeout we need to tell the circuit - // breaker - // about the error - .doOnError(TimeoutException.class, - t -> tuple.getT1().onError(timeoutDuration.toMillis(), TimeUnit.MILLISECONDS, t)); + // Since we are using the Mono timeout we need to tell the circuit + // breaker + // about the error + .doOnError(TimeoutException.class, + t -> tuple.getT1().onError(timeoutDuration.toMillis(), TimeUnit.MILLISECONDS, t)); } if (fallback != null) { toReturn = toReturn.onErrorResume(fallback); @@ -110,11 +110,11 @@ public Flux run(Flux toRun, Function> fallback) { if (tuple.getT2().isPresent()) { final Duration timeoutDuration = tuple.getT2().get().getTimeLimiterConfig().getTimeoutDuration(); toReturn = toReturn.timeout(timeoutDuration) - // Since we are using the Flux timeout we need to tell the circuit - // breaker - // about the error - .doOnError(TimeoutException.class, - t -> tuple.getT1().onError(timeoutDuration.toMillis(), TimeUnit.MILLISECONDS, t)); + // Since we are using the Flux timeout we need to tell the circuit + // breaker + // about the error + .doOnError(TimeoutException.class, + t -> tuple.getT1().onError(timeoutDuration.toMillis(), TimeUnit.MILLISECONDS, t)); } if (fallback != null) { toReturn = toReturn.onErrorResume(fallback); @@ -132,8 +132,8 @@ private Tuple2> buildCircuitBreakerAndTime } /* provide time-limiter */ TimeLimiter timeLimiter = this.timeLimiterRegistry.find(this.id) - .orElseGet(() -> this.timeLimiterRegistry.find(this.groupName) - .orElseGet(() -> this.timeLimiterRegistry.timeLimiter(this.id, this.timeLimiterConfig, tags))); + .orElseGet(() -> this.timeLimiterRegistry.find(this.groupName) + .orElseGet(() -> this.timeLimiterRegistry.timeLimiter(this.id, this.timeLimiterConfig, tags))); return Tuples.of(circuitBreaker, Optional.of(timeLimiter)); } diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerFactory.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerFactory.java index db709939..f7252330 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerFactory.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerFactory.java @@ -62,8 +62,9 @@ public ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry circuitB this.circuitBreakerRegistry = circuitBreakerRegistry; this.timeLimiterRegistry = timeLimiterRegistry; this.defaultConfiguration = id -> new Resilience4JConfigBuilder(id) - .circuitBreakerConfig(this.circuitBreakerRegistry.getDefaultConfig()) - .timeLimiterConfig(this.timeLimiterRegistry.getDefaultConfig()).build(); + .circuitBreakerConfig(this.circuitBreakerRegistry.getDefaultConfig()) + .timeLimiterConfig(this.timeLimiterRegistry.getDefaultConfig()) + .build(); this.resilience4JConfigurationProperties = resilience4JConfigurationProperties; } @@ -91,15 +92,17 @@ public ReactiveCircuitBreaker create(String id, String groupName) { Assert.hasText(id, "A CircuitBreaker must have an id."); Assert.hasText(groupName, "A CircuitBreaker must have a group name."); Resilience4JConfigBuilder.Resilience4JCircuitBreakerConfiguration defaultConfig = getConfigurations() - .computeIfAbsent(id, defaultConfiguration); + .computeIfAbsent(id, defaultConfiguration); CircuitBreakerConfig circuitBreakerConfig = this.circuitBreakerRegistry.getConfiguration(id) - .orElseGet(() -> this.circuitBreakerRegistry.getConfiguration(groupName) - .orElseGet(defaultConfig::getCircuitBreakerConfig)); + .orElseGet(() -> this.circuitBreakerRegistry.getConfiguration(groupName) + .orElseGet(defaultConfig::getCircuitBreakerConfig)); TimeLimiterConfig timeLimiterConfig = this.timeLimiterRegistry.getConfiguration(id) - .orElseGet(() -> this.timeLimiterRegistry.getConfiguration(groupName) - .orElseGet(defaultConfig::getTimeLimiterConfig)); + .orElseGet(() -> this.timeLimiterRegistry.getConfiguration(groupName) + .orElseGet(defaultConfig::getTimeLimiterConfig)); Resilience4JConfigBuilder.Resilience4JCircuitBreakerConfiguration config = new Resilience4JConfigBuilder(id) - .circuitBreakerConfig(circuitBreakerConfig).timeLimiterConfig(timeLimiterConfig).build(); + .circuitBreakerConfig(circuitBreakerConfig) + .timeLimiterConfig(timeLimiterConfig) + .build(); return new ReactiveResilience4JCircuitBreaker(id, groupName, config, circuitBreakerRegistry, timeLimiterRegistry, Optional.ofNullable(circuitBreakerCustomizers.get(id)), isDisableTimeLimiter()); } diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfiguration.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfiguration.java index b728f876..14ec122e 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfiguration.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfiguration.java @@ -141,21 +141,21 @@ public void init() { if (factory != null) { if (taggedCircuitBreakerMetrics == null) { taggedCircuitBreakerMetrics = TaggedCircuitBreakerMetrics - .ofCircuitBreakerRegistry(factory.getCircuitBreakerRegistry()); + .ofCircuitBreakerRegistry(factory.getCircuitBreakerRegistry()); } taggedCircuitBreakerMetrics.bindTo(meterRegistry); } if (bulkheadProvider != null) { TaggedBulkheadMetrics.ofBulkheadRegistry(bulkheadProvider.getBulkheadRegistry()).bindTo(meterRegistry); TaggedThreadPoolBulkheadMetrics - .ofThreadPoolBulkheadRegistry(bulkheadProvider.getThreadPoolBulkheadRegistry()) - .bindTo(meterRegistry); + .ofThreadPoolBulkheadRegistry(bulkheadProvider.getThreadPoolBulkheadRegistry()) + .bindTo(meterRegistry); } if (bulkheadProvider != null) { TaggedBulkheadMetrics.ofBulkheadRegistry(bulkheadProvider.getBulkheadRegistry()).bindTo(meterRegistry); TaggedThreadPoolBulkheadMetrics - .ofThreadPoolBulkheadRegistry(bulkheadProvider.getThreadPoolBulkheadRegistry()) - .bindTo(meterRegistry); + .ofThreadPoolBulkheadRegistry(bulkheadProvider.getThreadPoolBulkheadRegistry()) + .bindTo(meterRegistry); } } diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreaker.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreaker.java index 882a3145..6c73312f 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreaker.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreaker.java @@ -117,17 +117,17 @@ public T run(Supplier toRun, Function fallback) { Supplier> futureSupplier = () -> executorService.submit(toRun::get); /* conditionally wrap in time-limiter */ Callable timeLimitedCall = timeLimiter - .map(tl -> TimeLimiter.decorateFutureSupplier(tl, futureSupplier)) - .orElse(() -> futureSupplier.get().get()); + .map(tl -> TimeLimiter.decorateFutureSupplier(tl, futureSupplier)) + .orElse(() -> futureSupplier.get().get()); Callable bulkheadCall = bulkheadProvider.decorateCallable(this.groupName, tags, timeLimitedCall); Callable circuitBreakerCall = io.github.resilience4j.circuitbreaker.CircuitBreaker - .decorateCallable(defaultCircuitBreaker, bulkheadCall); + .decorateCallable(defaultCircuitBreaker, bulkheadCall); return getAndApplyFallback(circuitBreakerCall, fallback); } else { Callable bulkheadCall = bulkheadProvider.decorateCallable(this.groupName, tags, toRun::get); Callable circuitBreakerCall = io.github.resilience4j.circuitbreaker.CircuitBreaker - .decorateCallable(defaultCircuitBreaker, bulkheadCall); + .decorateCallable(defaultCircuitBreaker, bulkheadCall); return getAndApplyFallback(circuitBreakerCall, fallback); } } @@ -136,15 +136,15 @@ public T run(Supplier toRun, Function fallback) { Supplier> futureSupplier = () -> executorService.submit(toRun::get); /* conditionally wrap in time-limiter */ Callable restrictedCall = timeLimiter - .map(tl -> TimeLimiter.decorateFutureSupplier(tl, futureSupplier)) - .orElse(() -> futureSupplier.get().get()); + .map(tl -> TimeLimiter.decorateFutureSupplier(tl, futureSupplier)) + .orElse(() -> futureSupplier.get().get()); Callable callable = io.github.resilience4j.circuitbreaker.CircuitBreaker - .decorateCallable(defaultCircuitBreaker, restrictedCall); + .decorateCallable(defaultCircuitBreaker, restrictedCall); return getAndApplyFallback(callable, fallback); } else { Supplier decorator = io.github.resilience4j.circuitbreaker.CircuitBreaker - .decorateSupplier(defaultCircuitBreaker, toRun); + .decorateSupplier(defaultCircuitBreaker, toRun); return getAndApplyFallback(decorator, fallback); } } @@ -173,8 +173,8 @@ private Optional loadTimeLimiter() { return Optional.empty(); } return Optional.of(this.timeLimiterRegistry.find(this.id) - .orElseGet(() -> this.timeLimiterRegistry.find(this.groupName).orElseGet( - () -> this.timeLimiterRegistry.timeLimiter(this.id, this.timeLimiterConfig, this.tags)))); + .orElseGet(() -> this.timeLimiterRegistry.find(this.groupName) + .orElseGet(() -> this.timeLimiterRegistry.timeLimiter(this.id, this.timeLimiterConfig, this.tags)))); } } diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerFactory.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerFactory.java index ee736b2f..4e8622c0 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerFactory.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerFactory.java @@ -76,8 +76,9 @@ public Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry circuitBreakerRe this.timeLimiterRegistry = timeLimiterRegistry; this.bulkheadProvider = bulkheadProvider; this.defaultConfiguration = id -> new Resilience4JConfigBuilder(id) - .circuitBreakerConfig(this.circuitBreakerRegistry.getDefaultConfig()) - .timeLimiterConfig(this.timeLimiterRegistry.getDefaultConfig()).build(); + .circuitBreakerConfig(this.circuitBreakerRegistry.getDefaultConfig()) + .timeLimiterConfig(this.timeLimiterRegistry.getDefaultConfig()) + .build(); this.resilience4JConfigurationProperties = resilience4JConfigurationProperties; } @@ -167,13 +168,13 @@ public void addCircuitBreakerCustomizer(Customizer customizer, S private Resilience4JCircuitBreaker create(String id, String groupName, ExecutorService circuitBreakerExecutorService) { Resilience4JConfigBuilder.Resilience4JCircuitBreakerConfiguration defaultConfig = getConfigurations() - .computeIfAbsent(id, defaultConfiguration); + .computeIfAbsent(id, defaultConfiguration); CircuitBreakerConfig circuitBreakerConfig = this.circuitBreakerRegistry.getConfiguration(id) - .orElseGet(() -> this.circuitBreakerRegistry.getConfiguration(groupName) - .orElseGet(defaultConfig::getCircuitBreakerConfig)); + .orElseGet(() -> this.circuitBreakerRegistry.getConfiguration(groupName) + .orElseGet(defaultConfig::getCircuitBreakerConfig)); TimeLimiterConfig timeLimiterConfig = this.timeLimiterRegistry.getConfiguration(id) - .orElseGet(() -> this.timeLimiterRegistry.getConfiguration(groupName) - .orElseGet(defaultConfig::getTimeLimiterConfig)); + .orElseGet(() -> this.timeLimiterRegistry.getConfiguration(groupName) + .orElseGet(defaultConfig::getTimeLimiterConfig)); if (resilience4JConfigurationProperties.isDisableThreadPool()) { return new Resilience4JCircuitBreaker(id, groupName, circuitBreakerConfig, timeLimiterConfig, circuitBreakerRegistry, timeLimiterRegistry, Optional.ofNullable(circuitBreakerCustomizers.get(id)), diff --git a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4jBulkheadProvider.java b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4jBulkheadProvider.java index 4cb84488..a4f7c330 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4jBulkheadProvider.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4jBulkheadProvider.java @@ -57,8 +57,9 @@ public Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry threadPoolBulkhea this.bulkheadRegistry = bulkheadRegistry; this.threadPoolBulkheadRegistry = threadPoolBulkheadRegistry; defaultConfiguration = id -> new Resilience4jBulkheadConfigurationBuilder() - .bulkheadConfig(this.bulkheadRegistry.getDefaultConfig()) - .threadPoolBulkheadConfig(this.threadPoolBulkheadRegistry.getDefaultConfig()).build(); + .bulkheadConfig(this.bulkheadRegistry.getDefaultConfig()) + .threadPoolBulkheadConfig(this.threadPoolBulkheadRegistry.getDefaultConfig()) + .build(); this.semaphoreDefaultBulkhead = resilience4JConfigurationProperties.isEnableSemaphoreDefaultBulkhead(); } @@ -79,7 +80,7 @@ public void configure(Consumer consume public void addBulkheadCustomizer(Customizer customizer, String... ids) { for (String id : ids) { Resilience4jBulkheadConfigurationBuilder.BulkheadConfiguration configuration = configurations - .computeIfAbsent(id, defaultConfiguration); + .computeIfAbsent(id, defaultConfiguration); Bulkhead bulkhead = bulkheadRegistry.bulkhead(id, configuration.getBulkheadConfig()); customizer.customize(bulkhead); } @@ -88,7 +89,7 @@ public void addBulkheadCustomizer(Customizer customizer, String... ids public void addThreadPoolBulkheadCustomizer(Customizer customizer, String... ids) { for (String id : ids) { Resilience4jBulkheadConfigurationBuilder.BulkheadConfiguration configuration = configurations - .computeIfAbsent(id, defaultConfiguration); + .computeIfAbsent(id, defaultConfiguration); ThreadPoolBulkhead threadPoolBulkhead = threadPoolBulkheadRegistry.bulkhead(id, configuration.getThreadPoolBulkheadConfig()); customizer.customize(threadPoolBulkhead); @@ -119,7 +120,7 @@ public T run(String id, Supplier toRun, Function fallback, private Supplier> decorateBulkhead(final String id, final Map tags, final Supplier supplier) { Resilience4jBulkheadConfigurationBuilder.BulkheadConfiguration configuration = configurations - .computeIfAbsent(id, defaultConfiguration); + .computeIfAbsent(id, defaultConfiguration); if (useSemaphoreBulkhead(id)) { Bulkhead bulkhead = bulkheadRegistry.bulkhead(id, configuration.getBulkheadConfig(), tags); @@ -136,7 +137,7 @@ private Supplier> decorateBulkhead(final String id, final public Callable decorateCallable(final String id, final Map tags, final Callable callable) { Resilience4jBulkheadConfigurationBuilder.BulkheadConfiguration configuration = configurations - .computeIfAbsent(id, defaultConfiguration); + .computeIfAbsent(id, defaultConfiguration); if (useSemaphoreBulkhead(id)) { Bulkhead bulkhead = bulkheadRegistry.bulkhead(id, configuration.getBulkheadConfig(), tags); diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationPropertyTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationPropertyTest.java index 06bb4377..dd3b5188 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationPropertyTest.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationPropertyTest.java @@ -54,7 +54,7 @@ public void testCircuitBreakerPropertiesPopulated() { assertThat(circuitBreakerRegistry.find("test_circuit")).isPresent(); assertThat( circuitBreakerRegistry.find("test_circuit").get().getCircuitBreakerConfig().getMinimumNumberOfCalls()) - .isEqualTo(5); + .isEqualTo(5); } @Test @@ -63,7 +63,7 @@ public void testTimeLimiterPropertiesPopulated() { assertThat(timeLimiterRegistry).isNotNull(); assertThat(timeLimiterRegistry.find("test_circuit")).isPresent(); assertThat(timeLimiterRegistry.find("test_circuit").get().getTimeLimiterConfig().getTimeoutDuration()) - .isEqualTo(Duration.ofSeconds(18)); + .isEqualTo(Duration.ofSeconds(18)); } @Test @@ -72,8 +72,10 @@ public void testDefaultCircuitBreakerPropertiesPopulated() { CircuitBreakerRegistry circuitBreakerRegistry = factory.getCircuitBreakerRegistry(); assertThat(circuitBreakerRegistry).isNotNull(); assertThat(circuitBreakerRegistry.find("default_circuitBreaker")).isPresent(); - assertThat(circuitBreakerRegistry.find("default_circuitBreaker").get().getCircuitBreakerConfig() - .getMinimumNumberOfCalls()).isEqualTo(20); + assertThat(circuitBreakerRegistry.find("default_circuitBreaker") + .get() + .getCircuitBreakerConfig() + .getMinimumNumberOfCalls()).isEqualTo(20); } @Test @@ -83,7 +85,7 @@ public void testDefaultTimeLimiterPropertiesPopulated() { assertThat(timeLimiterRegistry).isNotNull(); assertThat(timeLimiterRegistry.find("default_circuitBreaker")).isPresent(); assertThat(timeLimiterRegistry.find("default_circuitBreaker").get().getTimeLimiterConfig().getTimeoutDuration()) - .isEqualTo(Duration.ofMillis(150)); + .isEqualTo(Duration.ofMillis(150)); } @Test diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationWithoutMetricsTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationWithoutMetricsTest.java index c47775eb..7d7fd16a 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationWithoutMetricsTest.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JAutoConfigurationWithoutMetricsTest.java @@ -49,7 +49,8 @@ public class ReactiveResilience4JAutoConfigurationWithoutMetricsTest { @Test public void testWithoutMetrics() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .sources(TestApp.class).run()) { + .sources(TestApp.class) + .run()) { verify(circuitBreakerFactory, times(0)).getCircuitBreakerRegistry(); } } diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerIntegrationTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerIntegrationTest.java index a3935f24..d1f14f74 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerIntegrationTest.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerIntegrationTest.java @@ -110,8 +110,12 @@ public void test() { StepVerifier.create(service.normal()).expectNext("normal").expectComplete().verify(); verify(normalErrorConsumer, times(0)).consumeEvent(any()); verify(normalSuccessConsumer, times(1)).consumeEvent(any()); - StepVerifier.withVirtualTime(() -> service.slow()).expectSubscription().expectNoEvent(Duration.ofSeconds(2)) - .expectNext("fallback").expectComplete().verify(); + StepVerifier.withVirtualTime(() -> service.slow()) + .expectSubscription() + .expectNoEvent(Duration.ofSeconds(2)) + .expectNext("fallback") + .expectComplete() + .verify(); verify(slowErrorConsumer, times(1)).consumeEvent(any()); verify(slowSuccessConsumer, times(0)).consumeEvent(any()); StepVerifier.create(service.normalFlux()).expectNext("normalflux").verifyComplete(); @@ -120,10 +124,15 @@ public void test() { StepVerifier.create(service.slowFlux()).expectNext("fluxfallback").verifyComplete(); verify(slowFluxErrorConsumer, times(1)).consumeEvent(any()); verify(slowSuccessConsumer, times(0)).consumeEvent(any()); - assertThat( - ((List) webClient.get().uri("/actuator/metrics").exchange().expectStatus().isOk().expectBody(Map.class) - .returnResult().getResponseBody().get("names")).contains("resilience4j.circuitbreaker.calls")) - .isTrue(); + assertThat(((List) webClient.get() + .uri("/actuator/metrics") + .exchange() + .expectStatus() + .isOk() + .expectBody(Map.class) + .returnResult() + .getResponseBody() + .get("names")).contains("resilience4j.circuitbreaker.calls")).isTrue(); } @Configuration(proxyBeanMethods = false) @@ -156,20 +165,24 @@ public Customizer slowCusomtizer() { return factory -> { factory.configureDefault( id -> new Resilience4JConfigBuilder(id).circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig( - TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) - .build()); + .timeLimiterConfig( + TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) + .build()); factory.configure(builder -> builder - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()), "slow", "slowflux"); + .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()) + .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()), "slow", "slowflux"); factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(slowErrorConsumer).onSuccess(slowSuccessConsumer), "slow"); + .onError(slowErrorConsumer) + .onSuccess(slowSuccessConsumer), "slow"); factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalErrorConsumer).onSuccess(normalSuccessConsumer), "normal"); + .onError(normalErrorConsumer) + .onSuccess(normalSuccessConsumer), "normal"); factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(slowFluxErrorConsumer).onSuccess(slowFluxSuccessConsumer), "slowflux"); + .onError(slowFluxErrorConsumer) + .onSuccess(slowFluxSuccessConsumer), "slowflux"); factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalFluxErrorConsumer).onSuccess(normalFluxSuccessConsumer), "normalflux"); + .onError(normalFluxErrorConsumer) + .onSuccess(normalFluxSuccessConsumer), "normalflux"); }; } @@ -188,37 +201,60 @@ public static class DemoControllerService { } public Mono slow() { - return WebClient.builder().baseUrl("http://localhost:" + port).build().get().uri("/slow").retrieve() - .bodyToMono(String.class).transform(it -> circuitBreakerSlow.run(it, t -> { - t.printStackTrace(); - return Mono.just("fallback"); - })); + return WebClient.builder() + .baseUrl("http://localhost:" + port) + .build() + .get() + .uri("/slow") + .retrieve() + .bodyToMono(String.class) + .transform(it -> circuitBreakerSlow.run(it, t -> { + t.printStackTrace(); + return Mono.just("fallback"); + })); } public Mono normal() { - return WebClient.builder().baseUrl("http://localhost:" + port).build().get().uri("/normal").retrieve() - .bodyToMono(String.class).transform(it -> cbFactory.create("normal").run(it, t -> { - t.printStackTrace(); - return Mono.just("fallback"); - })); + return WebClient.builder() + .baseUrl("http://localhost:" + port) + .build() + .get() + .uri("/normal") + .retrieve() + .bodyToMono(String.class) + .transform(it -> cbFactory.create("normal").run(it, t -> { + t.printStackTrace(); + return Mono.just("fallback"); + })); } public Flux slowFlux() { - return WebClient.builder().baseUrl("http://localhost:" + port).build().get().uri("/slowflux").retrieve() - .bodyToFlux(new ParameterizedTypeReference() { - }).transform(it -> cbFactory.create("slowflux").run(it, t -> { - t.printStackTrace(); - return Flux.just("fluxfallback"); - })); + return WebClient.builder() + .baseUrl("http://localhost:" + port) + .build() + .get() + .uri("/slowflux") + .retrieve() + .bodyToFlux(new ParameterizedTypeReference() { + }) + .transform(it -> cbFactory.create("slowflux").run(it, t -> { + t.printStackTrace(); + return Flux.just("fluxfallback"); + })); } public Flux normalFlux() { - return WebClient.builder().baseUrl("http://localhost:" + port).build().get().uri("/normalflux") - .retrieve().bodyToFlux(String.class) - .transform(it -> cbFactory.create("normalflux").run(it, t -> { - t.printStackTrace(); - return Flux.just("fluxfallback"); - })); + return WebClient.builder() + .baseUrl("http://localhost:" + port) + .build() + .get() + .uri("/normalflux") + .retrieve() + .bodyToFlux(String.class) + .transform(it -> cbFactory.create("normalflux").run(it, t -> { + t.printStackTrace(); + return Flux.just("fluxfallback"); + })); } public void setPort(int port) { diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerTest.java index 243fc8af..37d91d72 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerTest.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/ReactiveResilience4JCircuitBreakerTest.java @@ -42,32 +42,39 @@ public class ReactiveResilience4JCircuitBreakerTest { @Test public void runMono() { ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), new Resilience4JConfigurationProperties()).create("foo"); + TimeLimiterRegistry.ofDefaults(), new Resilience4JConfigurationProperties()) + .create("foo"); assertThat(Mono.just("foobar").transform(cb::run).block()).isEqualTo("foobar"); } @Test public void runMonoWithFallback() { ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), new Resilience4JConfigurationProperties()).create("foo"); - assertThat(Mono.error(new RuntimeException("boom")).transform(it -> cb.run(it, t -> Mono.just("fallback"))) - .block()).isEqualTo("fallback"); + TimeLimiterRegistry.ofDefaults(), new Resilience4JConfigurationProperties()) + .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(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), new Resilience4JConfigurationProperties()).create("foo"); + TimeLimiterRegistry.ofDefaults(), new Resilience4JConfigurationProperties()) + .create("foo"); assertThat(Flux.just("foobar", "hello world").transform(cb::run).collectList().block()) - .isEqualTo(Arrays.asList("foobar", "hello world")); + .isEqualTo(Arrays.asList("foobar", "hello world")); } @Test public void runFluxWithFallback() { ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), new Resilience4JConfigurationProperties()).create("foo"); - assertThat(Flux.error(new RuntimeException("boom")).transform(it -> cb.run(it, t -> Flux.just("fallback"))) - .collectList().block()).isEqualTo(Collections.singletonList("fallback")); + TimeLimiterRegistry.ofDefaults(), new Resilience4JConfigurationProperties()) + .create("foo"); + assertThat(Flux.error(new RuntimeException("boom")) + .transform(it -> cb.run(it, t -> Flux.just("fallback"))) + .collectList() + .block()).isEqualTo(Collections.singletonList("fallback")); } /** @@ -78,13 +85,14 @@ public void runFluxWithFallback() { public void runWithDefaultTimeLimiter() { final TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.ofDefaults(); ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - timeLimiterRegistry, new Resilience4JConfigurationProperties()).create("foo"); + timeLimiterRegistry, new Resilience4JConfigurationProperties()) + .create("foo"); assertThat(Mono.fromCallable(() -> { try { /* sleep less than time limit allows us to */ - TimeUnit.MILLISECONDS.sleep( - Math.min(timeLimiterRegistry.getDefaultConfig().getTimeoutDuration().toMillis() / 2L, 0L)); + TimeUnit.MILLISECONDS + .sleep(Math.min(timeLimiterRegistry.getDefaultConfig().getTimeoutDuration().toMillis() / 2L, 0L)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -102,13 +110,14 @@ public void runWithDefaultTimeLimiter() { public void runWithDefaultTimeLimiterTooSlow() { final TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.ofDefaults(); ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - timeLimiterRegistry, new Resilience4JConfigurationProperties()).create("foo"); + timeLimiterRegistry, new Resilience4JConfigurationProperties()) + .create("foo"); Mono.fromCallable(() -> { try { /* sleep longer than time limit allows us to */ - TimeUnit.MILLISECONDS.sleep( - Math.max(timeLimiterRegistry.getDefaultConfig().getTimeoutDuration().toMillis(), 100L) * 2); + TimeUnit.MILLISECONDS + .sleep(Math.max(timeLimiterRegistry.getDefaultConfig().getTimeoutDuration().toMillis(), 100L) * 2); } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -132,13 +141,14 @@ public void runWithDisabledTimeLimiter() { final Resilience4JConfigurationProperties resilience4JConfigurationProperties = new Resilience4JConfigurationProperties(); resilience4JConfigurationProperties.setDisableTimeLimiter(true); ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - timeLimiterRegistry, resilience4JConfigurationProperties).create("foo"); + timeLimiterRegistry, resilience4JConfigurationProperties) + .create("foo"); assertThat(Mono.fromCallable(() -> { try { /* sleep longer than timit limit allows us to */ - TimeUnit.MILLISECONDS.sleep( - Math.max(timeLimiterRegistry.getDefaultConfig().getTimeoutDuration().toMillis(), 100L) * 2); + TimeUnit.MILLISECONDS + .sleep(Math.max(timeLimiterRegistry.getDefaultConfig().getTimeoutDuration().toMillis(), 100L) * 2); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationMetricsConfigRun.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationMetricsConfigRun.java index 9a95c5fa..d59e9c61 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationMetricsConfigRun.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationMetricsConfigRun.java @@ -51,8 +51,9 @@ public class Resilience4JAutoConfigurationMetricsConfigRun { @Test public void testWithMetricsConfigReactive() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .properties("resilience4j.circuitbreaker.metrics.legacy.enabled").sources(TestAppReactive.class) - .run()) { + .properties("resilience4j.circuitbreaker.metrics.legacy.enabled") + .sources(TestAppReactive.class) + .run()) { verify(reactiveCircuitBreakerFactory, times(1)).getCircuitBreakerRegistry(); } } @@ -60,7 +61,9 @@ public void testWithMetricsConfigReactive() { @Test public void testWithMetricsConfig() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .properties("resilience4j.circuitbreaker.metrics.legacy.enabled").sources(TestApp.class).run()) { + .properties("resilience4j.circuitbreaker.metrics.legacy.enabled") + .sources(TestApp.class) + .run()) { verify(circuitBreakerFactory, times(1)).getCircuitBreakerRegistry(); } } diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationPropertyTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationPropertyTest.java index 11ed10e4..d22c2296 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationPropertyTest.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationPropertyTest.java @@ -56,7 +56,7 @@ public void testCircuitBreakerPropertiesPopulated() { assertThat(circuitBreakerRegistry.find("test_circuit")).isPresent(); assertThat( circuitBreakerRegistry.find("test_circuit").get().getCircuitBreakerConfig().getMinimumNumberOfCalls()) - .isEqualTo(5); + .isEqualTo(5); } @Test @@ -65,17 +65,17 @@ public void testTimeLimiterPropertiesPopulated() { assertThat(timeLimiterRegistry).isNotNull(); assertThat(timeLimiterRegistry.find("test_circuit")).isPresent(); assertThat(timeLimiterRegistry.find("test_circuit").get().getTimeLimiterConfig().getTimeoutDuration()) - .isEqualTo(Duration.ofSeconds(18)); + .isEqualTo(Duration.ofSeconds(18)); } @Test public void testThreadPoolBulkheadPropertiesPopulated() { ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry = factory.getBulkheadProvider() - .getThreadPoolBulkheadRegistry(); + .getThreadPoolBulkheadRegistry(); assertThat(threadPoolBulkheadRegistry).isNotNull(); assertThat(threadPoolBulkheadRegistry.find("test_circuit")).isPresent(); assertThat(threadPoolBulkheadRegistry.find("test_circuit").get().getBulkheadConfig().getMaxThreadPoolSize()) - .isEqualTo(100); + .isEqualTo(100); } @Test @@ -84,7 +84,7 @@ public void testBulkheadPropertiesPopulated() { assertThat(bulkheadRegistry).isNotNull(); assertThat(bulkheadRegistry.find("test_circuit")).isPresent(); assertThat(bulkheadRegistry.find("test_circuit").get().getBulkheadConfig().getMaxConcurrentCalls()) - .isEqualTo(50); + .isEqualTo(50); } @Test @@ -93,8 +93,10 @@ public void testDefaultCircuitBreakerPropertiesPopulated() { CircuitBreakerRegistry circuitBreakerRegistry = factory.getCircuitBreakerRegistry(); assertThat(circuitBreakerRegistry).isNotNull(); assertThat(circuitBreakerRegistry.find("default_circuitBreaker")).isPresent(); - assertThat(circuitBreakerRegistry.find("default_circuitBreaker").get().getCircuitBreakerConfig() - .getMinimumNumberOfCalls()).isEqualTo(20); + assertThat(circuitBreakerRegistry.find("default_circuitBreaker") + .get() + .getCircuitBreakerConfig() + .getMinimumNumberOfCalls()).isEqualTo(20); } @Test @@ -104,18 +106,20 @@ public void testDefaultTimeLimiterPropertiesPopulated() { assertThat(timeLimiterRegistry).isNotNull(); assertThat(timeLimiterRegistry.find("default_circuitBreaker")).isPresent(); assertThat(timeLimiterRegistry.find("default_circuitBreaker").get().getTimeLimiterConfig().getTimeoutDuration()) - .isEqualTo(Duration.ofMillis(150)); + .isEqualTo(Duration.ofMillis(150)); } @Test public void testDefaultThreadPoolBulkheadPropertiesPopulated() { factory.create("default_circuitBreaker").run(() -> "result"); ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry = factory.getBulkheadProvider() - .getThreadPoolBulkheadRegistry(); + .getThreadPoolBulkheadRegistry(); assertThat(threadPoolBulkheadRegistry).isNotNull(); assertThat(threadPoolBulkheadRegistry.find("default_circuitBreaker")).isPresent(); - assertThat(threadPoolBulkheadRegistry.find("default_circuitBreaker").get().getBulkheadConfig() - .getMaxThreadPoolSize()).isEqualTo(50); + assertThat(threadPoolBulkheadRegistry.find("default_circuitBreaker") + .get() + .getBulkheadConfig() + .getMaxThreadPoolSize()).isEqualTo(50); } @Test diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationTests.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationTests.java index 2499cff8..08b03d82 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationTests.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationTests.java @@ -42,7 +42,8 @@ public class Resilience4JAutoConfigurationTests { @Test public void meterFilterEnabled() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .sources(Resilience4JAutoConfigurationTests.TestApp.class).run()) { + .sources(Resilience4JAutoConfigurationTests.TestApp.class) + .run()) { assertThat(context.getBean("resilience4JMeterFilter")).isNotNull(); } } @@ -50,8 +51,9 @@ public void meterFilterEnabled() { @Test public void meterFilterDisabled() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .sources(Resilience4JAutoConfigurationTests.TestApp.class) - .properties("spring.cloud.circuitbreaker.resilience4j.enableGroupMeterFilter=false").run()) { + .sources(Resilience4JAutoConfigurationTests.TestApp.class) + .properties("spring.cloud.circuitbreaker.resilience4j.enableGroupMeterFilter=false") + .run()) { assertThat(context.containsBean("resilience4JMeterFilter")).isFalse(); } } diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutBulkheadTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutBulkheadTest.java index db9b7bd5..05c0f538 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutBulkheadTest.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutBulkheadTest.java @@ -39,7 +39,8 @@ public class Resilience4JAutoConfigurationWithoutBulkheadTest { @Test public void testWithoutBulkhead() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .sources(TestApp.class).run()) { + .sources(TestApp.class) + .run()) { assertThat(context.containsBean("bulkheadProvider")).isFalse(); } } diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutMetricsTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutMetricsTest.java index 0ca3e7ef..1c328fa3 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutMetricsTest.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JAutoConfigurationWithoutMetricsTest.java @@ -49,7 +49,8 @@ public class Resilience4JAutoConfigurationWithoutMetricsTest { @Test public void testWithoutMetrics() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE) - .sources(TestApp.class).run()) { + .sources(TestApp.class) + .run()) { verify(circuitBreakerFactory, times(0)).getCircuitBreakerRegistry(); } } diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JBulkheadAndTimeLimiterIntegrationTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JBulkheadAndTimeLimiterIntegrationTest.java index 62a86112..cadf7c1d 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JBulkheadAndTimeLimiterIntegrationTest.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JBulkheadAndTimeLimiterIntegrationTest.java @@ -115,10 +115,11 @@ protected static class Application { @Bean public Customizer slowBulkheadCustomizer() { - TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom().timeoutDuration(Duration.ofMillis(500)) - .build(); + TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom() + .timeoutDuration(Duration.ofMillis(500)) + .build(); return circuitBreakerFactory -> circuitBreakerFactory - .configure(builder -> builder.timeLimiterConfig(timeLimiterConfig), SLOW_BULKHEAD); + .configure(builder -> builder.timeLimiterConfig(timeLimiterConfig), SLOW_BULKHEAD); } @Bean diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JBulkheadIntegrationTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JBulkheadIntegrationTest.java index 1b06f038..18282671 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JBulkheadIntegrationTest.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JBulkheadIntegrationTest.java @@ -141,11 +141,11 @@ public void testThreadPoolBulkheadThreeParallelSlowOneNotPermitted() throws Inte public void testResilience4JMetricsAvailable() { assertThat(service.normal()).isEqualTo("normal"); assertThat(((List) rest.getForObject("/actuator/metrics", Map.class).get("names")) - .contains("resilience4j.bulkhead.max.thread.pool.size")).isTrue(); + .contains("resilience4j.bulkhead.max.thread.pool.size")).isTrue(); assertThat(((List) rest - .getForObject("/actuator/metrics/resilience4j.bulkhead.max.thread.pool.size?tag=group:none", Map.class) - .get("availableTags"))).hasSize(1); + .getForObject("/actuator/metrics/resilience4j.bulkhead.max.thread.pool.size?tag=group:none", Map.class) + .get("availableTags"))).hasSize(1); } @Configuration(proxyBeanMethods = false) @@ -227,15 +227,18 @@ public Customizer slowCustomizer() { }).when(normalSuccessConsumer).consumeEvent(any(CircuitBreakerOnSuccessEvent.class)); return factory -> { factory.configure(builder -> builder.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(3)).build()), + .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(3)).build()), "slow"); factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()).build()); + .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) + .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) + .build()); factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(slowErrorConsumer).onSuccess(slowSuccessConsumer), "slow"); + .onError(slowErrorConsumer) + .onSuccess(slowSuccessConsumer), "slow"); factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalErrorConsumer).onSuccess(normalSuccessConsumer), "normal"); + .onError(normalErrorConsumer) + .onSuccess(normalSuccessConsumer), "normal"); }; } @@ -259,29 +262,31 @@ public Customizer slowBulkheadProviderCustomizer() builder -> builder.bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(1).build()), "slowBulkhead"); provider.addBulkheadCustomizer(bulkhead -> bulkhead.getEventPublisher() - .onCallRejected(slowRejectedConsumer).onCallFinished(slowFinishedConsumer), "slowBulkhead"); + .onCallRejected(slowRejectedConsumer) + .onCallFinished(slowFinishedConsumer), "slowBulkhead"); }; } static EventConsumer slowThreadPoolRejectedConsumer = Mockito - .mock(EventConsumer.class); + .mock(EventConsumer.class); static EventConsumer slowThreadPoolFinishedConsumer = Mockito - .mock(EventConsumer.class); + .mock(EventConsumer.class); @Bean Customizer slowBulkheadThreadPoolProviderCustomizer() { return provider -> provider - .configure( - builder -> builder.threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.custom() - .coreThreadPoolSize(1).maxThreadPoolSize(1).queueCapacity(1).build()), - "slowThreadPoolBulkhead"); + .configure(builder -> builder.threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.custom() + .coreThreadPoolSize(1) + .maxThreadPoolSize(1) + .queueCapacity(1) + .build()), "slowThreadPoolBulkhead"); } @Bean public Customizer slowThreadPoolCustomizer() { return factory -> factory.configure( - builder -> builder.timeLimiterConfig( - TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(8)).build()), + builder -> builder + .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(8)).build()), "slowThreadPoolBulkhead"); } @@ -297,8 +302,9 @@ public Customizer slowThreadPoolBulkheadCustomizer LOG.info(event.getBulkheadName() + " threadpool finished: " + event.getEventType()); return null; }).when(slowThreadPoolFinishedConsumer).consumeEvent(any(BulkheadOnCallFinishedEvent.class)); - return provider -> provider.addThreadPoolBulkheadCustomizer(threadPoolBulkhead -> threadPoolBulkhead - .getEventPublisher().onCallRejected(slowThreadPoolRejectedConsumer) + return provider -> provider + .addThreadPoolBulkheadCustomizer(threadPoolBulkhead -> threadPoolBulkhead.getEventPublisher() + .onCallRejected(slowThreadPoolRejectedConsumer) .onCallFinished(slowThreadPoolFinishedConsumer), "slowThreadPoolBulkhead"); } @@ -322,27 +328,27 @@ public String slow() { } public String normal() { - return cbFactory.create("normal").run(() -> rest.getForObject("/normal", String.class), - t -> "fallback"); + return cbFactory.create("normal") + .run(() -> rest.getForObject("/normal", String.class), t -> "fallback"); } public String slowOnDemand(int delayInMilliseconds) { LOG.info("delay: " + delayInMilliseconds); return circuitBreakerSlow - .run(() -> rest - .exchange("/slowOnDemand", HttpMethod.GET, - createEntityWithOptionalDelayHeader(delayInMilliseconds), String.class) - .getBody(), t -> "fallback"); + .run(() -> rest + .exchange("/slowOnDemand", HttpMethod.GET, + createEntityWithOptionalDelayHeader(delayInMilliseconds), String.class) + .getBody(), t -> "fallback"); } public String slowBulkhead() { - return cbFactory.create("slowBulkhead").run(() -> rest.getForObject("/slowBulkhead", String.class), - t -> "fallback"); + return cbFactory.create("slowBulkhead") + .run(() -> rest.getForObject("/slowBulkhead", String.class), t -> "fallback"); } public String slowThreadPoolBulkhead() { return cbFactory.create("slowThreadPoolBulkhead") - .run(() -> rest.getForObject("/slowThreadPoolBulkhead", String.class), t -> "fallback"); + .run(() -> rest.getForObject("/slowThreadPoolBulkhead", String.class), t -> "fallback"); } private HttpEntity createEntityWithOptionalDelayHeader(int delayInMilliseconds) { diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerIntegrationTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerIntegrationTest.java index b1c9427c..9ef02578 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerIntegrationTest.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerIntegrationTest.java @@ -123,13 +123,13 @@ public void testSlowResponsesDontFailSubsequentGoodRequests() { public void testResilience4JMetricsAvailable() { assertThat(service.normal()).isEqualTo("normal"); assertThat(((List) rest.getForObject("/actuator/metrics", Map.class).get("names")) - .contains("resilience4j.circuitbreaker.calls")).isTrue(); + .contains("resilience4j.circuitbreaker.calls")).isTrue(); // CircuitBreaker and TimeLimiter should have 3 metrics: name, kind, group assertThat(((List) rest.getForObject("/actuator/metrics/resilience4j.circuitbreaker.calls", Map.class) - .get("availableTags"))).hasSize(3); + .get("availableTags"))).hasSize(3); assertThat(((List) rest.getForObject("/actuator/metrics/resilience4j.timelimiter.calls", Map.class) - .get("availableTags"))).hasSize(3); + .get("availableTags"))).hasSize(3); } @Test @@ -147,13 +147,16 @@ public void testObservationRegistry() throws InterruptedException { List contexts = myObservationHandler.contexts; assertThat(contexts).hasSize(3); assertThat(contexts.get(0)).satisfies(context -> ObservationContextAssert.then(context) - .hasNameEqualTo("spring.cloud.circuitbreaker").hasContextualNameEqualTo("circuit-breaker") - .hasLowCardinalityKeyValue("spring.cloud.circuitbreaker.type", "supplier")); - BDDAssertions.then(contexts.get(1)).satisfies(context -> ObservationContextAssert.then(context) - .hasNameEqualTo("spring.cloud.circuitbreaker").hasContextualNameEqualTo("circuit-breaker fallback") + .hasNameEqualTo("spring.cloud.circuitbreaker") + .hasContextualNameEqualTo("circuit-breaker") + .hasLowCardinalityKeyValue("spring.cloud.circuitbreaker.type", "supplier")); + BDDAssertions.then(contexts.get(1)) + .satisfies(context -> ObservationContextAssert.then(context) + .hasNameEqualTo("spring.cloud.circuitbreaker") + .hasContextualNameEqualTo("circuit-breaker fallback") .hasLowCardinalityKeyValue("spring.cloud.circuitbreaker.type", "function")); BDDAssertions.then(contexts.get(2)) - .satisfies(context -> ObservationContextAssert.then(context).hasNameEqualTo("my.observation")); + .satisfies(context -> ObservationContextAssert.then(context).hasNameEqualTo("my.observation")); } @Configuration(proxyBeanMethods = false) @@ -198,15 +201,18 @@ public String slowOnDemand(@RequestHeader HttpHeaders headers) { public Customizer slowCustomizer() { return factory -> { factory.configure(builder -> builder.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()), + .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()), "slow"); factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()).build()); + .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) + .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) + .build()); factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(slowErrorConsumer).onSuccess(slowSuccessConsumer), "slow"); + .onError(slowErrorConsumer) + .onSuccess(slowSuccessConsumer), "slow"); factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalErrorConsumer).onSuccess(normalSuccessConsumer), "normal"); + .onError(normalErrorConsumer) + .onSuccess(normalSuccessConsumer), "normal"); }; } @@ -251,22 +257,22 @@ public String slow() { } public String normal() { - return cbFactory.create("normal").run(() -> rest.getForObject("/normal", String.class), - t -> "fallback"); + return cbFactory.create("normal") + .run(() -> rest.getForObject("/normal", String.class), t -> "fallback"); } public String withObservationRegistry() { return Observation.createNotStarted("my.observation", observationRegistry) - .observe(() -> cbFactory.create("exception").run( - () -> new RestTemplate().getForObject("/exception", String.class), t -> "fallback")); + .observe(() -> cbFactory.create("exception") + .run(() -> new RestTemplate().getForObject("/exception", String.class), t -> "fallback")); } public String slowOnDemand(int delayInMilliseconds) { return circuitBreakerSlow - .run(() -> rest - .exchange("/slowOnDemand", HttpMethod.GET, - createEntityWithOptionalDelayHeader(delayInMilliseconds), String.class) - .getBody(), t -> "fallback"); + .run(() -> rest + .exchange("/slowOnDemand", HttpMethod.GET, + createEntityWithOptionalDelayHeader(delayInMilliseconds), String.class) + .getBody(), t -> "fallback"); } private HttpEntity createEntityWithOptionalDelayHeader(int delayInMilliseconds) { diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerTest.java index a612b675..b163f509 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerTest.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreakerTest.java @@ -50,21 +50,24 @@ public void before() { @Test public void run() { CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), null, properties).create("foo"); + TimeLimiterRegistry.ofDefaults(), null, properties) + .create("foo"); assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); } @Test public void runWithOutProperties() { CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), null).create("foo"); + TimeLimiterRegistry.ofDefaults(), null) + .create("foo"); assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); } @Test public void runWithGroupName() { CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), null).create("foo", "groupFoo"); + TimeLimiterRegistry.ofDefaults(), null) + .create("foo", "groupFoo"); assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); } @@ -73,7 +76,8 @@ public void runWithGroupName() { public void runWithoutThreadPool() { properties.setDisableThreadPool(true); CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), null, properties).create("foo", "groupFoo"); + TimeLimiterRegistry.ofDefaults(), null, properties) + .create("foo", "groupFoo"); assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); } @@ -81,7 +85,8 @@ public void runWithoutThreadPool() { @Test public void runWithFallback() { CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), null, properties).create("foo"); + TimeLimiterRegistry.ofDefaults(), null, properties) + .create("foo"); assertThat((String) cb.run(() -> { throw new RuntimeException("boom"); }, t -> "fallback")).isEqualTo("fallback"); @@ -90,7 +95,8 @@ public void runWithFallback() { @Test public void runWithFallbackAndGroupName() { CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - TimeLimiterRegistry.ofDefaults(), null, properties).create("foo", "groupFoo"); + TimeLimiterRegistry.ofDefaults(), null, properties) + .create("foo", "groupFoo"); assertThat((String) cb.run(() -> { throw new RuntimeException("boom"); }, t -> "fallback")).isEqualTo("fallback"); @@ -102,7 +108,8 @@ public void runWithBulkheadProvider() { TimeLimiterRegistry.ofDefaults(), new Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults(), new Resilience4JConfigurationProperties()), - properties).create("foo"); + properties) + .create("foo"); assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); } @@ -113,7 +120,8 @@ public void runWithBulkheadProviderAndNoThreadPool() { TimeLimiterRegistry.ofDefaults(), new Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults(), new Resilience4JConfigurationProperties()), - properties).create("foo"); + properties) + .create("foo"); assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); } @@ -123,7 +131,8 @@ public void runWithBulkheadProviderAndGroupName() { TimeLimiterRegistry.ofDefaults(), new Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults(), new Resilience4JConfigurationProperties()), - properties).create("foo", "groupFoo"); + properties) + .create("foo", "groupFoo"); assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); } @@ -134,7 +143,8 @@ public void runWithBulkheadProviderAndGroupNameAndNoThreadPool() { TimeLimiterRegistry.ofDefaults(), new Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults(), new Resilience4JConfigurationProperties()), - properties).create("foo", "groupFoo"); + properties) + .create("foo", "groupFoo"); assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); } @@ -144,7 +154,8 @@ public void runWithFallbackBulkheadProvider() { TimeLimiterRegistry.ofDefaults(), new Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults(), new Resilience4JConfigurationProperties()), - properties).create("foo"); + properties) + .create("foo"); assertThat((String) cb.run(() -> { throw new RuntimeException("boom"); }, t -> "fallback")).isEqualTo("fallback"); @@ -156,7 +167,8 @@ public void runWithFallbackBulkheadProviderAndGroupName() { TimeLimiterRegistry.ofDefaults(), new Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults(), new Resilience4JConfigurationProperties()), - properties).create("foo", "groupFoo"); + properties) + .create("foo", "groupFoo"); assertThat((String) cb.run(() -> { throw new RuntimeException("boom"); }, t -> "fallback")).isEqualTo("fallback"); @@ -170,12 +182,13 @@ public void runWithFallbackBulkheadProviderAndGroupName() { public void runWithDefaultTimeLimiter() { final TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.ofDefaults(); CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - timeLimiterRegistry, null, properties).create("foo"); + timeLimiterRegistry, null, properties) + .create("foo"); assertThat(cb.run(() -> { try { /* sleep less than time limit allows us to */ - TimeUnit.MILLISECONDS.sleep( - Math.min(timeLimiterRegistry.getDefaultConfig().getTimeoutDuration().toMillis() / 2L, 0L)); + TimeUnit.MILLISECONDS + .sleep(Math.min(timeLimiterRegistry.getDefaultConfig().getTimeoutDuration().toMillis() / 2L, 0L)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -193,12 +206,13 @@ public void runWithDefaultTimeLimiter() { public void runWithDefaultTimeLimiterTooSlow() { final TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.ofDefaults(); CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - timeLimiterRegistry, null, properties).create("foo"); + timeLimiterRegistry, null, properties) + .create("foo"); cb.run(() -> { try { /* sleep longer than time limit allows us to */ - TimeUnit.MILLISECONDS.sleep( - Math.max(timeLimiterRegistry.getDefaultConfig().getTimeoutDuration().toMillis(), 100L) * 2); + TimeUnit.MILLISECONDS + .sleep(Math.max(timeLimiterRegistry.getDefaultConfig().getTimeoutDuration().toMillis(), 100L) * 2); } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -218,12 +232,13 @@ public void runWithDisabledTimeLimiter() { properties.setDisableTimeLimiter(true); final TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.ofDefaults(); CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), - timeLimiterRegistry, null, properties).create("foo"); + timeLimiterRegistry, null, properties) + .create("foo"); assertThat(cb.run(() -> { try { /* sleep longer than limit limit allows us to */ - TimeUnit.MILLISECONDS.sleep( - Math.max(timeLimiterRegistry.getDefaultConfig().getTimeoutDuration().toMillis(), 100L) * 2); + TimeUnit.MILLISECONDS + .sleep(Math.max(timeLimiterRegistry.getDefaultConfig().getTimeoutDuration().toMillis(), 100L) * 2); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JDefaultSemaphoreBulkheadIntegrationTest.java b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JDefaultSemaphoreBulkheadIntegrationTest.java index 100512f1..25686e7a 100644 --- a/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JDefaultSemaphoreBulkheadIntegrationTest.java +++ b/spring-cloud-circuitbreaker-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JDefaultSemaphoreBulkheadIntegrationTest.java @@ -111,13 +111,15 @@ public String slow() throws InterruptedException { public Customizer slowCustomizer() { return factory -> { factory.configure(builder -> builder.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()), + .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()), "slow"); factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()).build()); + .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) + .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) + .build()); factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(slowErrorConsumer).onSuccess(slowSuccessConsumer), "slow"); + .onError(slowErrorConsumer) + .onSuccess(slowSuccessConsumer), "slow"); }; } diff --git a/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryConfigBuilder.java b/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryConfigBuilder.java index 2babf8ba..0bc5ddf4 100644 --- a/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryConfigBuilder.java +++ b/spring-cloud-circuitbreaker-spring-retry/src/main/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryConfigBuilder.java @@ -92,8 +92,11 @@ public SpringRetryConfigBuilder stateClassifier(Classifier c @Override public SpringRetryConfig build() { - return new SpringRetryConfig().setBackOffPolicy(backOffPolicy).setId(id).setRetryPolicy(retryPolicy) - .setForceRefreshState(forceRefreshState).setStateClassifier(stateClassifier); + return new SpringRetryConfig().setBackOffPolicy(backOffPolicy) + .setId(id) + .setRetryPolicy(retryPolicy) + .setForceRefreshState(forceRefreshState) + .setStateClassifier(stateClassifier); } } diff --git a/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryAutoConfigurationTests.java b/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryAutoConfigurationTests.java index bf62cfb7..b3681d6a 100644 --- a/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryAutoConfigurationTests.java +++ b/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryAutoConfigurationTests.java @@ -44,14 +44,14 @@ class SpringRetryAutoConfigurationTests { class NoCustomizers { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(SpringRetryAutoConfiguration.class)); + .withConfiguration(AutoConfigurations.of(SpringRetryAutoConfiguration.class)); @Test void testNoCustomizers() { contextRunner.run(context -> { String[] arr = context - .getBeanNamesForType(ResolvableType.forClassWithGenerics(List.class, Customizer.class)); + .getBeanNamesForType(ResolvableType.forClassWithGenerics(List.class, Customizer.class)); Assertions.assertEquals(0, arr.length, "Default auto-configuration must not have any customizers"); @SuppressWarnings("rawtypes") @@ -67,15 +67,15 @@ void testNoCustomizers() { class WithEmptyCustomizers { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(SpringRetryAutoConfiguration.class)) - .withConfiguration(AutoConfigurations.of(ListWithEmptyCustomizers.class)); + .withConfiguration(AutoConfigurations.of(SpringRetryAutoConfiguration.class)) + .withConfiguration(AutoConfigurations.of(ListWithEmptyCustomizers.class)); @Test void testWithCustomizers() { contextRunner.run(context -> { String[] arr = context - .getBeanNamesForType(ResolvableType.forClassWithGenerics(List.class, Customizer.class)); + .getBeanNamesForType(ResolvableType.forClassWithGenerics(List.class, Customizer.class)); Assertions.assertEquals(1, arr.length); Assertions.assertArrayEquals(arr, new String[] { "customizers" }); @@ -103,15 +103,15 @@ List> customizers() { class WithCustomizers { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(SpringRetryAutoConfiguration.class)) - .withConfiguration(AutoConfigurations.of(WithCustomizers.MyConfig.class)); + .withConfiguration(AutoConfigurations.of(SpringRetryAutoConfiguration.class)) + .withConfiguration(AutoConfigurations.of(WithCustomizers.MyConfig.class)); @Test void testCustomizer(CapturedOutput output) { contextRunner.run(context -> { String[] arr = context - .getBeanNamesForType(ResolvableType.forClassWithGenerics(List.class, Customizer.class)); + .getBeanNamesForType(ResolvableType.forClassWithGenerics(List.class, Customizer.class)); Assertions.assertEquals(1, arr.length); Assertions.assertArrayEquals(arr, new String[] { "customizers" }); diff --git a/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerIntegrationTest.java b/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerIntegrationTest.java index baf8e081..e8b8a27b 100644 --- a/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerIntegrationTest.java +++ b/spring-cloud-circuitbreaker-spring-retry/src/test/java/org/springframework/cloud/circuitbreaker/springretry/SpringRetryCircuitBreakerIntegrationTest.java @@ -93,27 +93,27 @@ Customizer factoryCustomizer() { factory.configureDefault( id -> new SpringRetryConfigBuilder(id).retryPolicy(new TimeoutRetryPolicy()).build()); factory.configure(builder -> builder.retryPolicy(new SimpleRetryPolicy(1)).build(), "slow"); - factory.addRetryTemplateCustomizers( - retryTemplate -> retryTemplate.registerListener(new RetryListener() { + factory + .addRetryTemplateCustomizers(retryTemplate -> retryTemplate.registerListener(new RetryListener() { - @Override - public boolean open(RetryContext context, - RetryCallback callback) { - return false; - } + @Override + public boolean open(RetryContext context, + RetryCallback callback) { + return false; + } - @Override - public void close(RetryContext context, - RetryCallback callback, Throwable throwable) { + @Override + public void close(RetryContext context, RetryCallback callback, + Throwable throwable) { - } + } - @Override - public void onError(RetryContext context, - RetryCallback callback, Throwable throwable) { + @Override + public void onError(RetryContext context, RetryCallback callback, + Throwable throwable) { - } - })); + } + })); }; } @@ -140,8 +140,8 @@ String slow() { } String normal() { - return cbFactory.create("normal").run(() -> rest.getForObject("/normal", String.class), - t -> "fallback"); + return cbFactory.create("normal") + .run(() -> rest.getForObject("/normal", String.class), t -> "fallback"); } void verifyTimesSlowInvoked() {