Search in sources :

Example 16 with DefaultEventConsumerRegistry

use of io.github.resilience4j.consumer.DefaultEventConsumerRegistry in project resilience4j by resilience4j.

the class RateLimiterConfigurationTest method testRateLimiterRegistry.

@Test
public void testRateLimiterRegistry() {
    io.github.resilience4j.common.ratelimiter.configuration.RateLimiterConfigurationProperties.InstanceProperties instanceProperties1 = new io.github.resilience4j.common.ratelimiter.configuration.RateLimiterConfigurationProperties.InstanceProperties();
    instanceProperties1.setLimitForPeriod(2);
    instanceProperties1.setSubscribeForEvents(true);
    io.github.resilience4j.common.ratelimiter.configuration.RateLimiterConfigurationProperties.InstanceProperties instanceProperties2 = new io.github.resilience4j.common.ratelimiter.configuration.RateLimiterConfigurationProperties.InstanceProperties();
    instanceProperties2.setLimitForPeriod(4);
    instanceProperties2.setSubscribeForEvents(true);
    RateLimiterConfigurationProperties rateLimiterConfigurationProperties = new RateLimiterConfigurationProperties();
    rateLimiterConfigurationProperties.getInstances().put("backend1", instanceProperties1);
    rateLimiterConfigurationProperties.getInstances().put("backend2", instanceProperties2);
    rateLimiterConfigurationProperties.setRateLimiterAspectOrder(300);
    RateLimiterConfiguration rateLimiterConfiguration = new RateLimiterConfiguration();
    DefaultEventConsumerRegistry<RateLimiterEvent> eventConsumerRegistry = new DefaultEventConsumerRegistry<>();
    RateLimiterRegistry rateLimiterRegistry = rateLimiterConfiguration.rateLimiterRegistry(rateLimiterConfigurationProperties, eventConsumerRegistry, new CompositeRegistryEventConsumer<>(emptyList()), compositeRateLimiterCustomizerTest());
    assertThat(rateLimiterConfigurationProperties.getRateLimiterAspectOrder()).isEqualTo(300);
    assertThat(rateLimiterRegistry.getAllRateLimiters().size()).isEqualTo(2);
    RateLimiter rateLimiter = rateLimiterRegistry.rateLimiter("backend1");
    assertThat(rateLimiter).isNotNull();
    assertThat(rateLimiter.getRateLimiterConfig().getLimitForPeriod()).isEqualTo(2);
    RateLimiter rateLimiter2 = rateLimiterRegistry.rateLimiter("backend2");
    assertThat(rateLimiter2).isNotNull();
    assertThat(rateLimiter2.getRateLimiterConfig().getLimitForPeriod()).isEqualTo(4);
    assertThat(eventConsumerRegistry.getAllEventConsumer()).hasSize(2);
}
Also used : RateLimiterEvent(io.github.resilience4j.ratelimiter.event.RateLimiterEvent) DefaultEventConsumerRegistry(io.github.resilience4j.consumer.DefaultEventConsumerRegistry) RateLimiterRegistry(io.github.resilience4j.ratelimiter.RateLimiterRegistry) RateLimiter(io.github.resilience4j.ratelimiter.RateLimiter) Test(org.junit.Test)

Example 17 with DefaultEventConsumerRegistry

use of io.github.resilience4j.consumer.DefaultEventConsumerRegistry 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)

Aggregations

DefaultEventConsumerRegistry (io.github.resilience4j.consumer.DefaultEventConsumerRegistry)17 Test (org.junit.Test)17 ThreadPoolBulkheadConfigurationProperties (io.github.resilience4j.common.bulkhead.configuration.ThreadPoolBulkheadConfigurationProperties)7 CompositeRegistryEventConsumer (io.github.resilience4j.core.registry.CompositeRegistryEventConsumer)6 ThreadPoolBulkheadConfiguration (io.github.resilience4j.bulkhead.configure.threadpool.ThreadPoolBulkheadConfiguration)5 BulkheadEvent (io.github.resilience4j.bulkhead.event.BulkheadEvent)5 io.github.resilience4j.bulkhead (io.github.resilience4j.bulkhead)4 CircuitBreakerRegistry (io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry)4 CompositeCustomizer (io.github.resilience4j.common.CompositeCustomizer)4 ConfigurationNotFoundException (io.github.resilience4j.core.ConfigurationNotFoundException)4 RateLimiterRegistry (io.github.resilience4j.ratelimiter.RateLimiterRegistry)4 RetryRegistry (io.github.resilience4j.retry.RetryRegistry)4 TimeLimiterRegistry (io.github.resilience4j.timelimiter.TimeLimiterRegistry)4 CircuitBreakerEvent (io.github.resilience4j.circuitbreaker.event.CircuitBreakerEvent)3 InstanceProperties (io.github.resilience4j.common.circuitbreaker.configuration.CircuitBreakerConfigurationProperties.InstanceProperties)3 InstanceProperties (io.github.resilience4j.common.retry.configuration.RetryConfigurationProperties.InstanceProperties)3 RetryEvent (io.github.resilience4j.retry.event.RetryEvent)3 Duration (java.time.Duration)3 Collections (java.util.Collections)3 BulkheadRegistry (io.github.resilience4j.bulkhead.BulkheadRegistry)2