use of io.github.resilience4j.timelimiter.TimeLimiterConfig in project resilience4j by resilience4j.
the class TimeLimiterConfigurationPropertiesTest method testTimeLimiterConfigWithDefaultConfig.
@Test
public void testTimeLimiterConfigWithDefaultConfig() {
TimeLimiterConfigurationProperties.InstanceProperties defaultConfig = new TimeLimiterConfigurationProperties.InstanceProperties();
defaultConfig.setTimeoutDuration(Duration.ofMillis(4000L));
defaultConfig.setCancelRunningFuture(false);
TimeLimiterConfigurationProperties.InstanceProperties sharedConfigWithDefaultConfig = new TimeLimiterConfigurationProperties.InstanceProperties();
sharedConfigWithDefaultConfig.setTimeoutDuration(Duration.ofMillis(3000L));
sharedConfigWithDefaultConfig.setCancelRunningFuture(true);
TimeLimiterConfigurationProperties.InstanceProperties instanceWithSharedConfig = new TimeLimiterConfigurationProperties.InstanceProperties();
instanceWithSharedConfig.setBaseConfig("sharedConfig");
TimeLimiterConfigurationProperties.InstanceProperties instanceWithDefaultConfig = new TimeLimiterConfigurationProperties.InstanceProperties();
TimeLimiterConfigurationProperties timeLimiterConfigurationProperties = new TimeLimiterConfigurationProperties();
timeLimiterConfigurationProperties.getConfigs().put("default", defaultConfig);
timeLimiterConfigurationProperties.getConfigs().put("sharedConfig", sharedConfigWithDefaultConfig);
timeLimiterConfigurationProperties.getInstances().put("instanceWithSharedConfig", instanceWithSharedConfig);
TimeLimiterConfig instance1 = timeLimiterConfigurationProperties.createTimeLimiterConfig("instanceWithSharedConfig", instanceWithSharedConfig, compositeTimeLimiterCustomizer());
assertThat(instance1).isNotNull();
assertThat(instance1.getTimeoutDuration()).isEqualTo(Duration.ofMillis(3000L));
assertThat(instance1.shouldCancelRunningFuture()).isEqualTo(true);
TimeLimiterConfig instance2 = timeLimiterConfigurationProperties.createTimeLimiterConfig("unknown", instanceWithDefaultConfig, compositeTimeLimiterCustomizer());
assertThat(instance2).isNotNull();
assertThat(instance2.getTimeoutDuration()).isEqualTo(Duration.ofMillis(4000L));
assertThat(instance2.shouldCancelRunningFuture()).isEqualTo(false);
}
use of io.github.resilience4j.timelimiter.TimeLimiterConfig in project resilience4j by resilience4j.
the class TimeLimiterConfigurationPropertiesTest method testTimeLimiterConfigWithBaseConfig.
@Test
public void testTimeLimiterConfigWithBaseConfig() {
TimeLimiterConfigurationProperties.InstanceProperties defaultConfig = new TimeLimiterConfigurationProperties.InstanceProperties();
defaultConfig.setTimeoutDuration(Duration.ofMillis(4000L));
defaultConfig.setCancelRunningFuture(false);
TimeLimiterConfigurationProperties.InstanceProperties sharedConfigWithDefaultConfig = new TimeLimiterConfigurationProperties.InstanceProperties();
sharedConfigWithDefaultConfig.setCancelRunningFuture(true);
sharedConfigWithDefaultConfig.setBaseConfig("defaultConfig");
TimeLimiterConfigurationProperties.InstanceProperties instanceWithSharedConfig = new TimeLimiterConfigurationProperties.InstanceProperties();
instanceWithSharedConfig.setBaseConfig("sharedConfig");
TimeLimiterConfigurationProperties timeLimiterConfigurationProperties = new TimeLimiterConfigurationProperties();
timeLimiterConfigurationProperties.getConfigs().put("defaultConfig", defaultConfig);
timeLimiterConfigurationProperties.getConfigs().put("sharedConfig", sharedConfigWithDefaultConfig);
timeLimiterConfigurationProperties.getInstances().put("instanceWithSharedConfig", instanceWithSharedConfig);
TimeLimiterConfig instance = timeLimiterConfigurationProperties.createTimeLimiterConfig("instanceWithSharedConfig", instanceWithSharedConfig, compositeTimeLimiterCustomizer());
assertThat(instance).isNotNull();
assertThat(instance.getTimeoutDuration()).isEqualTo(Duration.ofMillis(4000L));
assertThat(instance.shouldCancelRunningFuture()).isEqualTo(true);
}
use of io.github.resilience4j.timelimiter.TimeLimiterConfig in project resilience4j by resilience4j.
the class TimeLimiterConfigurationPropertiesTest method testCreateTimeLimiterPropertiesWithSharedConfigs.
@Test
public void testCreateTimeLimiterPropertiesWithSharedConfigs() {
// Given
TimeLimiterConfigurationProperties.InstanceProperties defaultProperties = new TimeLimiterConfigurationProperties.InstanceProperties();
defaultProperties.setTimeoutDuration(Duration.ofSeconds(3));
defaultProperties.setCancelRunningFuture(true);
defaultProperties.setEventConsumerBufferSize(200);
TimeLimiterConfigurationProperties.InstanceProperties sharedProperties = new TimeLimiterConfigurationProperties.InstanceProperties();
sharedProperties.setTimeoutDuration(Duration.ofSeconds(5));
sharedProperties.setCancelRunningFuture(false);
sharedProperties.setEventConsumerBufferSize(500);
TimeLimiterConfigurationProperties.InstanceProperties backendWithDefaultConfig = new TimeLimiterConfigurationProperties.InstanceProperties();
backendWithDefaultConfig.setBaseConfig("defaultConfig");
backendWithDefaultConfig.setTimeoutDuration(Duration.ofMillis(200L));
TimeLimiterConfigurationProperties.InstanceProperties backendWithSharedConfig = new TimeLimiterConfigurationProperties.InstanceProperties();
backendWithSharedConfig.setBaseConfig("sharedConfig");
backendWithSharedConfig.setTimeoutDuration(Duration.ofMillis(300L));
TimeLimiterConfigurationProperties timeLimiterConfigurationProperties = new TimeLimiterConfigurationProperties();
timeLimiterConfigurationProperties.getConfigs().put("defaultConfig", defaultProperties);
timeLimiterConfigurationProperties.getConfigs().put("sharedConfig", sharedProperties);
timeLimiterConfigurationProperties.getInstances().put("backendWithDefaultConfig", backendWithDefaultConfig);
timeLimiterConfigurationProperties.getInstances().put("backendWithSharedConfig", backendWithSharedConfig);
Map<String, String> globalTags = new HashMap<>();
globalTags.put("testKey1", "testKet2");
timeLimiterConfigurationProperties.setTags(globalTags);
// Then
assertThat(timeLimiterConfigurationProperties.getTags()).isNotEmpty();
// Should get default config and overwrite max attempt and wait time
TimeLimiterConfig timeLimiter1 = timeLimiterConfigurationProperties.createTimeLimiterConfig("backendWithDefaultConfig");
assertThat(timeLimiter1).isNotNull();
assertThat(timeLimiter1.shouldCancelRunningFuture()).isEqualTo(true);
assertThat(timeLimiter1.getTimeoutDuration().toMillis()).isEqualTo(200);
// Should get shared config and overwrite wait time
TimeLimiterConfig timeLimiter2 = timeLimiterConfigurationProperties.createTimeLimiterConfig("backendWithSharedConfig");
assertThat(timeLimiter2).isNotNull();
assertThat(timeLimiter2.shouldCancelRunningFuture()).isEqualTo(false);
assertThat(timeLimiter2.getTimeoutDuration().toMillis()).isEqualTo(300);
// Unknown backend should get default config of Registry
TimeLimiterConfig timeLimiter3 = timeLimiterConfigurationProperties.createTimeLimiterConfig("unknownBackend");
assertThat(timeLimiter3).isNotNull();
assertThat(timeLimiter3.getTimeoutDuration().toMillis()).isEqualTo(1000);
}
use of io.github.resilience4j.timelimiter.TimeLimiterConfig in project resilience4j by resilience4j.
the class TimeLimiterConfigurationProperties method buildConfigFromBaseConfig.
private TimeLimiterConfig buildConfigFromBaseConfig(InstanceProperties baseProperties, InstanceProperties instanceProperties, CompositeCustomizer<TimeLimiterConfigCustomizer> compositeTimeLimiterCustomizer, String backendName) {
ConfigUtils.mergePropertiesIfAny(baseProperties, instanceProperties);
TimeLimiterConfig baseConfig = createTimeLimiterConfig(backendName, baseProperties, compositeTimeLimiterCustomizer);
return buildTimeLimiterConfig(TimeLimiterConfig.from(baseConfig), instanceProperties, compositeTimeLimiterCustomizer, backendName);
}
use of io.github.resilience4j.timelimiter.TimeLimiterConfig in project resilience4j by resilience4j.
the class TimeLimiterAspect method getOrCreateTimeLimiter.
private io.github.resilience4j.timelimiter.TimeLimiter getOrCreateTimeLimiter(String methodName, String name) {
io.github.resilience4j.timelimiter.TimeLimiter timeLimiter = timeLimiterRegistry.timeLimiter(name);
if (logger.isDebugEnabled()) {
TimeLimiterConfig timeLimiterConfig = timeLimiter.getTimeLimiterConfig();
logger.debug("Created or retrieved time limiter '{}' with timeout duration '{}' and cancelRunningFuture '{}' for method: '{}'", name, timeLimiterConfig.getTimeoutDuration(), timeLimiterConfig.shouldCancelRunningFuture(), methodName);
}
return timeLimiter;
}
Aggregations