Skip to content

Commit

Permalink
Bumping versions
Browse files Browse the repository at this point in the history
  • Loading branch information
spring-builds committed Jul 23, 2024
1 parent 7b08c36 commit b6d4a62
Show file tree
Hide file tree
Showing 24 changed files with 332 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void init() {
if (factory != null) {
if (taggedCircuitBreakerMetrics == null) {
taggedCircuitBreakerMetrics = TaggedCircuitBreakerMetrics
.ofCircuitBreakerRegistry(factory.getCircuitBreakerRegistry());
.ofCircuitBreakerRegistry(factory.getCircuitBreakerRegistry());
}
taggedCircuitBreakerMetrics.bindTo(meterRegistry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public <T> Mono<T> run(Mono<T> toRun, Function<Throwable, Mono<T>> 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);
Expand All @@ -110,11 +110,11 @@ public <T> Flux<T> run(Flux<T> toRun, Function<Throwable, Flux<T>> 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);
Expand All @@ -132,8 +132,8 @@ private Tuple2<CircuitBreaker, Optional<TimeLimiter>> 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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ public <T> T run(Supplier<T> toRun, Function<Throwable, T> fallback) {
Supplier<Future<T>> futureSupplier = () -> executorService.submit(toRun::get);
/* conditionally wrap in time-limiter */
Callable<T> timeLimitedCall = timeLimiter
.map(tl -> TimeLimiter.decorateFutureSupplier(tl, futureSupplier))
.orElse(() -> futureSupplier.get().get());
.map(tl -> TimeLimiter.decorateFutureSupplier(tl, futureSupplier))
.orElse(() -> futureSupplier.get().get());
Callable<T> bulkheadCall = bulkheadProvider.decorateCallable(this.groupName, tags, timeLimitedCall);
Callable<T> circuitBreakerCall = io.github.resilience4j.circuitbreaker.CircuitBreaker
.decorateCallable(defaultCircuitBreaker, bulkheadCall);
.decorateCallable(defaultCircuitBreaker, bulkheadCall);
return getAndApplyFallback(circuitBreakerCall, fallback);
}
else {
Callable<T> bulkheadCall = bulkheadProvider.decorateCallable(this.groupName, tags, toRun::get);
Callable<T> circuitBreakerCall = io.github.resilience4j.circuitbreaker.CircuitBreaker
.decorateCallable(defaultCircuitBreaker, bulkheadCall);
.decorateCallable(defaultCircuitBreaker, bulkheadCall);
return getAndApplyFallback(circuitBreakerCall, fallback);
}
}
Expand All @@ -136,15 +136,15 @@ public <T> T run(Supplier<T> toRun, Function<Throwable, T> fallback) {
Supplier<Future<T>> futureSupplier = () -> executorService.submit(toRun::get);
/* conditionally wrap in time-limiter */
Callable<T> restrictedCall = timeLimiter
.map(tl -> TimeLimiter.decorateFutureSupplier(tl, futureSupplier))
.orElse(() -> futureSupplier.get().get());
.map(tl -> TimeLimiter.decorateFutureSupplier(tl, futureSupplier))
.orElse(() -> futureSupplier.get().get());
Callable<T> callable = io.github.resilience4j.circuitbreaker.CircuitBreaker
.decorateCallable(defaultCircuitBreaker, restrictedCall);
.decorateCallable(defaultCircuitBreaker, restrictedCall);
return getAndApplyFallback(callable, fallback);
}
else {
Supplier<T> decorator = io.github.resilience4j.circuitbreaker.CircuitBreaker
.decorateSupplier(defaultCircuitBreaker, toRun);
.decorateSupplier(defaultCircuitBreaker, toRun);
return getAndApplyFallback(decorator, fallback);
}
}
Expand Down Expand Up @@ -173,8 +173,8 @@ private Optional<TimeLimiter> 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))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -167,13 +168,13 @@ public void addCircuitBreakerCustomizer(Customizer<CircuitBreaker> 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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -79,7 +80,7 @@ public void configure(Consumer<Resilience4jBulkheadConfigurationBuilder> consume
public void addBulkheadCustomizer(Customizer<Bulkhead> 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);
}
Expand All @@ -88,7 +89,7 @@ public void addBulkheadCustomizer(Customizer<Bulkhead> customizer, String... ids
public void addThreadPoolBulkheadCustomizer(Customizer<ThreadPoolBulkhead> 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);
Expand Down Expand Up @@ -119,7 +120,7 @@ public <T> T run(String id, Supplier<T> toRun, Function<Throwable, T> fallback,
private <T> Supplier<CompletionStage<T>> decorateBulkhead(final String id, final Map<String, String> tags,
final Supplier<T> supplier) {
Resilience4jBulkheadConfigurationBuilder.BulkheadConfiguration configuration = configurations
.computeIfAbsent(id, defaultConfiguration);
.computeIfAbsent(id, defaultConfiguration);

if (useSemaphoreBulkhead(id)) {
Bulkhead bulkhead = bulkheadRegistry.bulkhead(id, configuration.getBulkheadConfig(), tags);
Expand All @@ -136,7 +137,7 @@ private <T> Supplier<CompletionStage<T>> decorateBulkhead(final String id, final
public <T> Callable<T> decorateCallable(final String id, final Map<String, String> tags,
final Callable<T> callable) {
Resilience4jBulkheadConfigurationBuilder.BulkheadConfiguration configuration = configurations
.computeIfAbsent(id, defaultConfiguration);
.computeIfAbsent(id, defaultConfiguration);

if (useSemaphoreBulkhead(id)) {
Bulkhead bulkhead = bulkheadRegistry.bulkhead(id, configuration.getBulkheadConfig(), tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
Loading

0 comments on commit b6d4a62

Please sign in to comment.