I'm using Spring Cloud Circuit Breaker 2.0.0 (resilience4j implementation) for circuit breaking and timeouts in my application. I've created the following configuration:
@Bean
public Customizer<Resilience4JCircuitBreakerFactory> defaultCustomizer() {
return factory ->
factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
.timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(10)).build())
.circuitBreakerConfig(..)
.build());
}
Now I want to write an integration test to verify that my behavior is correct when a timeout occurs. For this to work, I'd like to temporarily change the timeout duration specified in the configuration above to something like 1 millisecond instead of 10 seconds.
So my question is: How can I change the value of the timeout of the TimeLimiterConfig
(temporarily) when I'm writing a Spring Boot integration test?
You can use the
@Value
Spring annotation that retrieves the value at a configuration file from your resource foldersrc/main/resources/common.properties
.Then you set the value at
src/main/resources/common.properties
When you are doing your test you can configure another resource file at the
test
foldersrc/test/resources/common.properties
with a different value.