Search in sources :

Example 1 with FallbackDecorators

use of io.github.resilience4j.fallback.FallbackDecorators in project resilience4j by resilience4j.

the class SpringBootCommonTest method testCircuitBreakerCommonConfig.

@Test
public void testCircuitBreakerCommonConfig() {
    CircuitBreakerConfig circuitBreakerConfig = new CircuitBreakerConfig(new CircuitBreakerConfigurationProperties());
    assertThat(circuitBreakerConfig.reactorCircuitBreakerAspect()).isNotNull();
    assertThat(circuitBreakerConfig.rxJava2CircuitBreakerAspect()).isNotNull();
    assertThat(circuitBreakerConfig.circuitBreakerRegistry(new DefaultEventConsumerRegistry<>(), new CompositeRegistryEventConsumer<>(Collections.emptyList()), new CompositeCustomizer<>(Collections.singletonList(new TestCustomizer())))).isNotNull();
    final DefaultSpelResolver spelResolver = new DefaultSpelResolver(new SpelExpressionParser(), new StandardReflectionParameterNameDiscoverer(), new GenericApplicationContext());
    final FallbackDecorators fallbackDecorators = new FallbackDecorators(Collections.singletonList(new CompletionStageFallbackDecorator()));
    assertThat(circuitBreakerConfig.circuitBreakerAspect(CircuitBreakerRegistry.ofDefaults(), Collections.emptyList(), new FallbackExecutor(spelResolver, fallbackDecorators), spelResolver)).isNotNull();
    assertThat(circuitBreakerConfig.circuitBreakerRegistryEventConsumer(Optional.empty())).isNotNull();
}
Also used : CircuitBreakerConfigurationProperties(io.github.resilience4j.circuitbreaker.configure.CircuitBreakerConfigurationProperties) StandardReflectionParameterNameDiscoverer(org.springframework.core.StandardReflectionParameterNameDiscoverer) CompletionStageFallbackDecorator(io.github.resilience4j.fallback.CompletionStageFallbackDecorator) FallbackDecorators(io.github.resilience4j.fallback.FallbackDecorators) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) DefaultSpelResolver(io.github.resilience4j.spelresolver.DefaultSpelResolver) FallbackExecutor(io.github.resilience4j.fallback.FallbackExecutor) Test(org.junit.Test)

Example 2 with FallbackDecorators

use of io.github.resilience4j.fallback.FallbackDecorators in project resilience4j by resilience4j.

the class SpringBootCommonTest method testBulkHeadCommonConfig.

@Test
public void testBulkHeadCommonConfig() {
    BulkheadConfigurationOnMissingBean bulkheadConfigurationOnMissingBean = new BulkheadConfigurationOnMissingBean();
    assertThat(bulkheadConfigurationOnMissingBean.bulkheadRegistry(new BulkheadConfigurationProperties(), new DefaultEventConsumerRegistry<>(), new CompositeRegistryEventConsumer<>(Collections.emptyList()), new CompositeCustomizer<>(Collections.singletonList(BulkheadConfigCustomizer.of("backend", builder -> builder.maxConcurrentCalls(10)))))).isNotNull();
    assertThat(bulkheadConfigurationOnMissingBean.threadPoolBulkheadRegistry(new ThreadPoolBulkheadConfigurationProperties(), new DefaultEventConsumerRegistry<>(), new CompositeRegistryEventConsumer<>(Collections.emptyList()), new CompositeCustomizer<>(Collections.singletonList(ThreadPoolBulkheadConfigCustomizer.of("backend", builder -> builder.coreThreadPoolSize(10)))))).isNotNull();
    assertThat(bulkheadConfigurationOnMissingBean.reactorBulkHeadAspectExt()).isNotNull();
    assertThat(bulkheadConfigurationOnMissingBean.rxJava2BulkHeadAspectExt()).isNotNull();
    final DefaultSpelResolver spelResolver = new DefaultSpelResolver(new SpelExpressionParser(), new StandardReflectionParameterNameDiscoverer(), new GenericApplicationContext());
    final FallbackDecorators fallbackDecorators = new FallbackDecorators(Collections.singletonList(new CompletionStageFallbackDecorator()));
    assertThat(bulkheadConfigurationOnMissingBean.bulkheadAspect(new BulkheadConfigurationProperties(), ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults(), Collections.emptyList(), new FallbackExecutor(spelResolver, fallbackDecorators), spelResolver)).isNotNull();
    assertThat(bulkheadConfigurationOnMissingBean.bulkheadRegistryEventConsumer(Optional.empty())).isNotNull();
}
Also used : RetryConfigurationProperties(io.github.resilience4j.retry.configure.RetryConfigurationProperties) Arrays(java.util.Arrays) BulkheadRegistry(io.github.resilience4j.bulkhead.BulkheadRegistry) BulkheadConfigCustomizer(io.github.resilience4j.common.bulkhead.configuration.BulkheadConfigCustomizer) FallbackDecorators(io.github.resilience4j.fallback.FallbackDecorators) TimeLimiterConfigurationProperties(io.github.resilience4j.timelimiter.configure.TimeLimiterConfigurationProperties) BulkheadConfigurationProperties(io.github.resilience4j.bulkhead.configure.BulkheadConfigurationProperties) TimeLimiterRegistry(io.github.resilience4j.timelimiter.TimeLimiterRegistry) AbstractRetryConfigurationOnMissingBean(io.github.resilience4j.retry.autoconfigure.AbstractRetryConfigurationOnMissingBean) CircuitBreakerRegistry(io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry) TimeLimiterConfigCustomizer(io.github.resilience4j.common.timelimiter.configuration.TimeLimiterConfigCustomizer) DefaultSpelResolver(io.github.resilience4j.spelresolver.DefaultSpelResolver) Duration(java.time.Duration) AbstractRateLimiterConfigurationOnMissingBean(io.github.resilience4j.ratelimiter.autoconfigure.AbstractRateLimiterConfigurationOnMissingBean) CircuitBreakerConfigurationProperties(io.github.resilience4j.circuitbreaker.configure.CircuitBreakerConfigurationProperties) ThreadPoolBulkheadConfigCustomizer(io.github.resilience4j.common.bulkhead.configuration.ThreadPoolBulkheadConfigCustomizer) RetryRegistry(io.github.resilience4j.retry.RetryRegistry) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) RateLimiterRegistry(io.github.resilience4j.ratelimiter.RateLimiterRegistry) CompositeRegistryEventConsumer(io.github.resilience4j.core.registry.CompositeRegistryEventConsumer) CompositeCustomizer(io.github.resilience4j.common.CompositeCustomizer) AbstractBulkheadConfigurationOnMissingBean(io.github.resilience4j.bulkhead.autoconfigure.AbstractBulkheadConfigurationOnMissingBean) StandardReflectionParameterNameDiscoverer(org.springframework.core.StandardReflectionParameterNameDiscoverer) Test(org.junit.Test) AbstractCircuitBreakerConfigurationOnMissingBean(io.github.resilience4j.circuitbreaker.autoconfigure.AbstractCircuitBreakerConfigurationOnMissingBean) CircuitBreakerConfigCustomizer(io.github.resilience4j.common.circuitbreaker.configuration.CircuitBreakerConfigCustomizer) DefaultEventConsumerRegistry(io.github.resilience4j.consumer.DefaultEventConsumerRegistry) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) AbstractTimeLimiterConfigurationOnMissingBean(io.github.resilience4j.timelimiter.autoconfigure.AbstractTimeLimiterConfigurationOnMissingBean) FallbackExecutor(io.github.resilience4j.fallback.FallbackExecutor) RateLimiterConfigurationProperties(io.github.resilience4j.ratelimiter.configure.RateLimiterConfigurationProperties) Optional(java.util.Optional) ThreadPoolBulkheadConfigurationProperties(io.github.resilience4j.common.bulkhead.configuration.ThreadPoolBulkheadConfigurationProperties) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) CompletionStageFallbackDecorator(io.github.resilience4j.fallback.CompletionStageFallbackDecorator) Collections(java.util.Collections) ThreadPoolBulkheadRegistry(io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry) StandardReflectionParameterNameDiscoverer(org.springframework.core.StandardReflectionParameterNameDiscoverer) CompletionStageFallbackDecorator(io.github.resilience4j.fallback.CompletionStageFallbackDecorator) AbstractBulkheadConfigurationOnMissingBean(io.github.resilience4j.bulkhead.autoconfigure.AbstractBulkheadConfigurationOnMissingBean) FallbackDecorators(io.github.resilience4j.fallback.FallbackDecorators) BulkheadConfigurationProperties(io.github.resilience4j.bulkhead.configure.BulkheadConfigurationProperties) ThreadPoolBulkheadConfigurationProperties(io.github.resilience4j.common.bulkhead.configuration.ThreadPoolBulkheadConfigurationProperties) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ThreadPoolBulkheadConfigurationProperties(io.github.resilience4j.common.bulkhead.configuration.ThreadPoolBulkheadConfigurationProperties) DefaultSpelResolver(io.github.resilience4j.spelresolver.DefaultSpelResolver) FallbackExecutor(io.github.resilience4j.fallback.FallbackExecutor) Test(org.junit.Test)

Example 3 with FallbackDecorators

use of io.github.resilience4j.fallback.FallbackDecorators in project resilience4j by resilience4j.

the class SpringBootCommonTest method testTimeLimiterCommonConfig.

@Test
public void testTimeLimiterCommonConfig() {
    TimeLimiterConfigurationOnMissingBean timeLimiterConfigurationOnMissingBean = new TimeLimiterConfigurationOnMissingBean();
    assertThat(timeLimiterConfigurationOnMissingBean.reactorTimeLimiterAspectExt()).isNotNull();
    assertThat(timeLimiterConfigurationOnMissingBean.rxJava2TimeLimiterAspectExt()).isNotNull();
    assertThat(timeLimiterConfigurationOnMissingBean.timeLimiterRegistry(new TimeLimiterConfigurationProperties(), new DefaultEventConsumerRegistry<>(), new CompositeRegistryEventConsumer<>(Collections.emptyList()), new CompositeCustomizer<>(Collections.singletonList(TimeLimiterConfigCustomizer.of("backend", builder -> builder.timeoutDuration(Duration.ofSeconds(10))))))).isNotNull();
    final DefaultSpelResolver spelResolver = new DefaultSpelResolver(new SpelExpressionParser(), new StandardReflectionParameterNameDiscoverer(), new GenericApplicationContext());
    final FallbackDecorators fallbackDecorators = new FallbackDecorators(Arrays.asList(new CompletionStageFallbackDecorator()));
    assertThat(timeLimiterConfigurationOnMissingBean.timeLimiterAspect(new TimeLimiterConfigurationProperties(), TimeLimiterRegistry.ofDefaults(), Collections.emptyList(), new FallbackExecutor(spelResolver, fallbackDecorators), spelResolver, null)).isNotNull();
    assertThat(timeLimiterConfigurationOnMissingBean.timeLimiterRegistryEventConsumer(Optional.empty())).isNotNull();
}
Also used : TimeLimiterConfigurationProperties(io.github.resilience4j.timelimiter.configure.TimeLimiterConfigurationProperties) RetryConfigurationProperties(io.github.resilience4j.retry.configure.RetryConfigurationProperties) Arrays(java.util.Arrays) BulkheadRegistry(io.github.resilience4j.bulkhead.BulkheadRegistry) BulkheadConfigCustomizer(io.github.resilience4j.common.bulkhead.configuration.BulkheadConfigCustomizer) FallbackDecorators(io.github.resilience4j.fallback.FallbackDecorators) TimeLimiterConfigurationProperties(io.github.resilience4j.timelimiter.configure.TimeLimiterConfigurationProperties) BulkheadConfigurationProperties(io.github.resilience4j.bulkhead.configure.BulkheadConfigurationProperties) TimeLimiterRegistry(io.github.resilience4j.timelimiter.TimeLimiterRegistry) AbstractRetryConfigurationOnMissingBean(io.github.resilience4j.retry.autoconfigure.AbstractRetryConfigurationOnMissingBean) CircuitBreakerRegistry(io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry) TimeLimiterConfigCustomizer(io.github.resilience4j.common.timelimiter.configuration.TimeLimiterConfigCustomizer) DefaultSpelResolver(io.github.resilience4j.spelresolver.DefaultSpelResolver) Duration(java.time.Duration) AbstractRateLimiterConfigurationOnMissingBean(io.github.resilience4j.ratelimiter.autoconfigure.AbstractRateLimiterConfigurationOnMissingBean) CircuitBreakerConfigurationProperties(io.github.resilience4j.circuitbreaker.configure.CircuitBreakerConfigurationProperties) ThreadPoolBulkheadConfigCustomizer(io.github.resilience4j.common.bulkhead.configuration.ThreadPoolBulkheadConfigCustomizer) RetryRegistry(io.github.resilience4j.retry.RetryRegistry) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) RateLimiterRegistry(io.github.resilience4j.ratelimiter.RateLimiterRegistry) CompositeRegistryEventConsumer(io.github.resilience4j.core.registry.CompositeRegistryEventConsumer) CompositeCustomizer(io.github.resilience4j.common.CompositeCustomizer) AbstractBulkheadConfigurationOnMissingBean(io.github.resilience4j.bulkhead.autoconfigure.AbstractBulkheadConfigurationOnMissingBean) StandardReflectionParameterNameDiscoverer(org.springframework.core.StandardReflectionParameterNameDiscoverer) Test(org.junit.Test) AbstractCircuitBreakerConfigurationOnMissingBean(io.github.resilience4j.circuitbreaker.autoconfigure.AbstractCircuitBreakerConfigurationOnMissingBean) CircuitBreakerConfigCustomizer(io.github.resilience4j.common.circuitbreaker.configuration.CircuitBreakerConfigCustomizer) DefaultEventConsumerRegistry(io.github.resilience4j.consumer.DefaultEventConsumerRegistry) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) AbstractTimeLimiterConfigurationOnMissingBean(io.github.resilience4j.timelimiter.autoconfigure.AbstractTimeLimiterConfigurationOnMissingBean) FallbackExecutor(io.github.resilience4j.fallback.FallbackExecutor) RateLimiterConfigurationProperties(io.github.resilience4j.ratelimiter.configure.RateLimiterConfigurationProperties) Optional(java.util.Optional) ThreadPoolBulkheadConfigurationProperties(io.github.resilience4j.common.bulkhead.configuration.ThreadPoolBulkheadConfigurationProperties) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) CompletionStageFallbackDecorator(io.github.resilience4j.fallback.CompletionStageFallbackDecorator) Collections(java.util.Collections) ThreadPoolBulkheadRegistry(io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry) StandardReflectionParameterNameDiscoverer(org.springframework.core.StandardReflectionParameterNameDiscoverer) CompletionStageFallbackDecorator(io.github.resilience4j.fallback.CompletionStageFallbackDecorator) AbstractTimeLimiterConfigurationOnMissingBean(io.github.resilience4j.timelimiter.autoconfigure.AbstractTimeLimiterConfigurationOnMissingBean) FallbackDecorators(io.github.resilience4j.fallback.FallbackDecorators) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) DefaultSpelResolver(io.github.resilience4j.spelresolver.DefaultSpelResolver) FallbackExecutor(io.github.resilience4j.fallback.FallbackExecutor) Test(org.junit.Test)

Example 4 with FallbackDecorators

use of io.github.resilience4j.fallback.FallbackDecorators in project resilience4j by resilience4j.

the class SpringBootCommonTest method testRetryCommonConfig.

@Test
public void testRetryCommonConfig() {
    RetryConfigurationOnMissingBean retryConfigurationOnMissingBean = new RetryConfigurationOnMissingBean();
    assertThat(retryConfigurationOnMissingBean.reactorRetryAspectExt()).isNotNull();
    assertThat(retryConfigurationOnMissingBean.rxJava2RetryAspectExt()).isNotNull();
    assertThat(retryConfigurationOnMissingBean.retryRegistry(new RetryConfigurationProperties(), new DefaultEventConsumerRegistry<>(), new CompositeRegistryEventConsumer<>(Collections.emptyList()), new CompositeCustomizer<>(Collections.emptyList()))).isNotNull();
    final DefaultSpelResolver spelResolver = new DefaultSpelResolver(new SpelExpressionParser(), new StandardReflectionParameterNameDiscoverer(), new GenericApplicationContext());
    final FallbackDecorators fallbackDecorators = new FallbackDecorators(Collections.singletonList(new CompletionStageFallbackDecorator()));
    assertThat(retryConfigurationOnMissingBean.retryAspect(new RetryConfigurationProperties(), RetryRegistry.ofDefaults(), Collections.emptyList(), new FallbackExecutor(spelResolver, fallbackDecorators), spelResolver, null)).isNotNull();
    assertThat(retryConfigurationOnMissingBean.retryRegistryEventConsumer(Optional.empty())).isNotNull();
}
Also used : AbstractRetryConfigurationOnMissingBean(io.github.resilience4j.retry.autoconfigure.AbstractRetryConfigurationOnMissingBean) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardReflectionParameterNameDiscoverer(org.springframework.core.StandardReflectionParameterNameDiscoverer) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) CompletionStageFallbackDecorator(io.github.resilience4j.fallback.CompletionStageFallbackDecorator) DefaultSpelResolver(io.github.resilience4j.spelresolver.DefaultSpelResolver) RetryConfigurationProperties(io.github.resilience4j.retry.configure.RetryConfigurationProperties) FallbackDecorators(io.github.resilience4j.fallback.FallbackDecorators) FallbackExecutor(io.github.resilience4j.fallback.FallbackExecutor) Test(org.junit.Test)

Example 5 with FallbackDecorators

use of io.github.resilience4j.fallback.FallbackDecorators in project resilience4j by resilience4j.

the class SpringBootCommonTest method testRateLimiterCommonConfig.

@Test
public void testRateLimiterCommonConfig() {
    RateLimiterConfigurationOnMissingBean rateLimiterConfigurationOnMissingBean = new RateLimiterConfigurationOnMissingBean();
    assertThat(rateLimiterConfigurationOnMissingBean.reactorRateLimiterAspectExt()).isNotNull();
    assertThat(rateLimiterConfigurationOnMissingBean.rxJava2RateLimiterAspectExt()).isNotNull();
    assertThat(rateLimiterConfigurationOnMissingBean.rateLimiterRegistry(new RateLimiterConfigurationProperties(), new DefaultEventConsumerRegistry<>(), new CompositeRegistryEventConsumer<>(Collections.emptyList()), new CompositeCustomizer<>(Collections.emptyList()))).isNotNull();
    final FallbackDecorators fallbackDecorators = new FallbackDecorators(Arrays.asList(new CompletionStageFallbackDecorator()));
    final DefaultSpelResolver spelResolver = new DefaultSpelResolver(new SpelExpressionParser(), new StandardReflectionParameterNameDiscoverer(), new GenericApplicationContext());
    assertThat(rateLimiterConfigurationOnMissingBean.rateLimiterAspect(new RateLimiterConfigurationProperties(), RateLimiterRegistry.ofDefaults(), Collections.emptyList(), new FallbackExecutor(spelResolver, fallbackDecorators), spelResolver)).isNotNull();
    assertThat(rateLimiterConfigurationOnMissingBean.rateLimiterRegistryEventConsumer(Optional.empty())).isNotNull();
}
Also used : RateLimiterConfigurationProperties(io.github.resilience4j.ratelimiter.configure.RateLimiterConfigurationProperties) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardReflectionParameterNameDiscoverer(org.springframework.core.StandardReflectionParameterNameDiscoverer) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) CompletionStageFallbackDecorator(io.github.resilience4j.fallback.CompletionStageFallbackDecorator) AbstractRateLimiterConfigurationOnMissingBean(io.github.resilience4j.ratelimiter.autoconfigure.AbstractRateLimiterConfigurationOnMissingBean) DefaultSpelResolver(io.github.resilience4j.spelresolver.DefaultSpelResolver) FallbackDecorators(io.github.resilience4j.fallback.FallbackDecorators) FallbackExecutor(io.github.resilience4j.fallback.FallbackExecutor) Test(org.junit.Test)

Aggregations

CompletionStageFallbackDecorator (io.github.resilience4j.fallback.CompletionStageFallbackDecorator)5 FallbackDecorators (io.github.resilience4j.fallback.FallbackDecorators)5 FallbackExecutor (io.github.resilience4j.fallback.FallbackExecutor)5 DefaultSpelResolver (io.github.resilience4j.spelresolver.DefaultSpelResolver)5 Test (org.junit.Test)5 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 StandardReflectionParameterNameDiscoverer (org.springframework.core.StandardReflectionParameterNameDiscoverer)5 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)5 CircuitBreakerConfigurationProperties (io.github.resilience4j.circuitbreaker.configure.CircuitBreakerConfigurationProperties)3 AbstractRateLimiterConfigurationOnMissingBean (io.github.resilience4j.ratelimiter.autoconfigure.AbstractRateLimiterConfigurationOnMissingBean)3 RateLimiterConfigurationProperties (io.github.resilience4j.ratelimiter.configure.RateLimiterConfigurationProperties)3 AbstractRetryConfigurationOnMissingBean (io.github.resilience4j.retry.autoconfigure.AbstractRetryConfigurationOnMissingBean)3 RetryConfigurationProperties (io.github.resilience4j.retry.configure.RetryConfigurationProperties)3 BulkheadRegistry (io.github.resilience4j.bulkhead.BulkheadRegistry)2 ThreadPoolBulkheadRegistry (io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry)2 AbstractBulkheadConfigurationOnMissingBean (io.github.resilience4j.bulkhead.autoconfigure.AbstractBulkheadConfigurationOnMissingBean)2 BulkheadConfigurationProperties (io.github.resilience4j.bulkhead.configure.BulkheadConfigurationProperties)2 CircuitBreakerRegistry (io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry)2 AbstractCircuitBreakerConfigurationOnMissingBean (io.github.resilience4j.circuitbreaker.autoconfigure.AbstractCircuitBreakerConfigurationOnMissingBean)2 CompositeCustomizer (io.github.resilience4j.common.CompositeCustomizer)2