Respecting the clock set in the CircuitBreakerStateMachine for detecting slow calls
See original GitHub issueResilience4j version: implementation ‘io.github.resilience4j:resilience4j-kotlin:1.1.0’ implementation ‘io.github.resilience4j:resilience4j-circuitbreaker:1.1.0’
Java version: 12
Problem description:
I’m writing unit tests to assert some of my assumptions of how the CircuitBreaker works. Especially how the it reacts to slow calls. To simulate it without a really big delay in running tests I can either set the slow threshold really low. Or I can mock the Clock (which was my initial approach).
I am setting up the CircuitBreaker with a config and injecting a Clock like this: CircuitBreakerStateMachine("myBreaker", circuitBreakerConfig, clock)
. But even if I progress the clock beyond the slow threshold for each call to the operation, it does not detect slow operations. A simple sleep provokes it (but takes a “long” time). I suspect that is because in decorateCallable(...)
it uses System.nanoTime()
to time the execution of the function.
Wouldn’t it make sense to use the same Clock here? Or are there performance issues related to that?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top GitHub Comments
I’ll try to find some time and take care of it 😃
No, the Registry does not allow to override the Clock. We could create a factory method. Would you like to create a PR?