Search in sources :

Example 1 with InstanceProperties

use of io.github.resilience4j.common.retry.configuration.RetryConfigurationProperties.InstanceProperties in project resilience4j by resilience4j.

the class RetryConfigurationTest method testCreateRetryRegistryWithSharedConfigs.

@Test
public void testCreateRetryRegistryWithSharedConfigs() {
    InstanceProperties defaultProperties = new InstanceProperties();
    defaultProperties.setMaxAttempts(3);
    defaultProperties.setWaitDuration(Duration.ofMillis(100L));
    InstanceProperties sharedProperties = new InstanceProperties();
    sharedProperties.setMaxAttempts(2);
    sharedProperties.setWaitDuration(Duration.ofMillis(100L));
    InstanceProperties backendWithDefaultConfig = new InstanceProperties();
    backendWithDefaultConfig.setBaseConfig("default");
    backendWithDefaultConfig.setWaitDuration(Duration.ofMillis(200L));
    InstanceProperties backendWithSharedConfig = new InstanceProperties();
    backendWithSharedConfig.setBaseConfig("sharedConfig");
    backendWithSharedConfig.setWaitDuration(Duration.ofMillis(300L));
    RetryConfigurationProperties retryConfigurationProperties = new RetryConfigurationProperties();
    retryConfigurationProperties.getConfigs().put("default", defaultProperties);
    retryConfigurationProperties.getConfigs().put("sharedConfig", sharedProperties);
    retryConfigurationProperties.getInstances().put("backendWithDefaultConfig", backendWithDefaultConfig);
    retryConfigurationProperties.getInstances().put("backendWithSharedConfig", backendWithSharedConfig);
    RetryConfiguration retryConfiguration = new RetryConfiguration();
    DefaultEventConsumerRegistry<RetryEvent> eventConsumerRegistry = new DefaultEventConsumerRegistry<>();
    RetryRegistry retryRegistry = retryConfiguration.retryRegistry(retryConfigurationProperties, eventConsumerRegistry, new CompositeRegistryEventConsumer<>(emptyList()), compositeRetryCustomizerTest());
    assertThat(retryRegistry.getAllRetries().size()).isEqualTo(2);
    // Should get default config and overwrite max attempt and wait time
    Retry retry1 = retryRegistry.retry("backendWithDefaultConfig");
    assertThat(retry1).isNotNull();
    assertThat(retry1.getRetryConfig().getMaxAttempts()).isEqualTo(3);
    assertThat(retry1.getRetryConfig().getIntervalBiFunction().apply(1, null)).isEqualTo(200L);
    // Should get shared config and overwrite wait time
    Retry retry2 = retryRegistry.retry("backendWithSharedConfig");
    assertThat(retry2).isNotNull();
    assertThat(retry2.getRetryConfig().getMaxAttempts()).isEqualTo(2);
    assertThat(retry2.getRetryConfig().getIntervalBiFunction().apply(1, null)).isEqualTo(300L);
    // Unknown backend should get default config of Registry
    Retry retry3 = retryRegistry.retry("unknownBackend");
    assertThat(retry3).isNotNull();
    assertThat(retry3.getRetryConfig().getMaxAttempts()).isEqualTo(3);
    assertThat(eventConsumerRegistry.getAllEventConsumer()).hasSize(3);
}
Also used : RetryEvent(io.github.resilience4j.retry.event.RetryEvent) InstanceProperties(io.github.resilience4j.common.retry.configuration.RetryConfigurationProperties.InstanceProperties) RetryRegistry(io.github.resilience4j.retry.RetryRegistry) DefaultEventConsumerRegistry(io.github.resilience4j.consumer.DefaultEventConsumerRegistry) Retry(io.github.resilience4j.retry.Retry) Test(org.junit.Test)

Example 2 with InstanceProperties

use of io.github.resilience4j.common.retry.configuration.RetryConfigurationProperties.InstanceProperties in project resilience4j by resilience4j.

the class RetryConfigurationTest method testRetryRegistry.

@Test
public void testRetryRegistry() {
    InstanceProperties instanceProperties1 = new InstanceProperties();
    instanceProperties1.setMaxAttempts(3);
    InstanceProperties instanceProperties2 = new InstanceProperties();
    instanceProperties2.setMaxAttempts(2);
    RetryConfigurationProperties retryConfigurationProperties = new RetryConfigurationProperties();
    retryConfigurationProperties.getInstances().put("backend1", instanceProperties1);
    retryConfigurationProperties.getInstances().put("backend2", instanceProperties2);
    retryConfigurationProperties.setRetryAspectOrder(200);
    RetryConfiguration retryConfiguration = new RetryConfiguration();
    DefaultEventConsumerRegistry<RetryEvent> eventConsumerRegistry = new DefaultEventConsumerRegistry<>();
    RetryRegistry retryRegistry = retryConfiguration.retryRegistry(retryConfigurationProperties, eventConsumerRegistry, new CompositeRegistryEventConsumer<>(emptyList()), compositeRetryCustomizerTest());
    assertThat(retryConfigurationProperties.getRetryAspectOrder()).isEqualTo(200);
    assertThat(retryRegistry.getAllRetries().size()).isEqualTo(2);
    Retry retry1 = retryRegistry.retry("backend1");
    assertThat(retry1).isNotNull();
    assertThat(retry1.getRetryConfig().getMaxAttempts()).isEqualTo(3);
    Retry retry2 = retryRegistry.retry("backend2");
    assertThat(retry2).isNotNull();
    assertThat(retry2.getRetryConfig().getMaxAttempts()).isEqualTo(2);
    assertThat(eventConsumerRegistry.getAllEventConsumer()).hasSize(2);
}
Also used : RetryEvent(io.github.resilience4j.retry.event.RetryEvent) InstanceProperties(io.github.resilience4j.common.retry.configuration.RetryConfigurationProperties.InstanceProperties) RetryRegistry(io.github.resilience4j.retry.RetryRegistry) DefaultEventConsumerRegistry(io.github.resilience4j.consumer.DefaultEventConsumerRegistry) Retry(io.github.resilience4j.retry.Retry) Test(org.junit.Test)

Example 3 with InstanceProperties

use of io.github.resilience4j.common.retry.configuration.RetryConfigurationProperties.InstanceProperties in project resilience4j by resilience4j.

the class RetryConfigurationTest method testCreateRetryRegistryWithUnknownConfig.

@Test
public void testCreateRetryRegistryWithUnknownConfig() {
    RetryConfigurationProperties retryConfigurationProperties = new RetryConfigurationProperties();
    InstanceProperties instanceProperties = new InstanceProperties();
    instanceProperties.setBaseConfig("unknownConfig");
    retryConfigurationProperties.getInstances().put("backend", instanceProperties);
    RetryConfiguration retryConfiguration = new RetryConfiguration();
    DefaultEventConsumerRegistry<RetryEvent> eventConsumerRegistry = new DefaultEventConsumerRegistry<>();
    assertThatThrownBy(() -> retryConfiguration.retryRegistry(retryConfigurationProperties, eventConsumerRegistry, new CompositeRegistryEventConsumer<>(emptyList()), compositeRetryCustomizerTest())).isInstanceOf(ConfigurationNotFoundException.class).hasMessage("Configuration with name 'unknownConfig' does not exist");
}
Also used : RetryEvent(io.github.resilience4j.retry.event.RetryEvent) InstanceProperties(io.github.resilience4j.common.retry.configuration.RetryConfigurationProperties.InstanceProperties) DefaultEventConsumerRegistry(io.github.resilience4j.consumer.DefaultEventConsumerRegistry) CompositeRegistryEventConsumer(io.github.resilience4j.core.registry.CompositeRegistryEventConsumer) ConfigurationNotFoundException(io.github.resilience4j.core.ConfigurationNotFoundException) Test(org.junit.Test)

Aggregations

InstanceProperties (io.github.resilience4j.common.retry.configuration.RetryConfigurationProperties.InstanceProperties)3 DefaultEventConsumerRegistry (io.github.resilience4j.consumer.DefaultEventConsumerRegistry)3 RetryEvent (io.github.resilience4j.retry.event.RetryEvent)3 Test (org.junit.Test)3 Retry (io.github.resilience4j.retry.Retry)2 RetryRegistry (io.github.resilience4j.retry.RetryRegistry)2 ConfigurationNotFoundException (io.github.resilience4j.core.ConfigurationNotFoundException)1 CompositeRegistryEventConsumer (io.github.resilience4j.core.registry.CompositeRegistryEventConsumer)1