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);
}
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();
}
Aggregations