use of io.github.resilience4j.circuitbreaker.monitoring.endpoint.CircuitBreakerEventDTO in project resilience4j by resilience4j.
the class CircuitBreakerEventEmitterTest method testEmitter.
@Test
public void testEmitter() throws IOException {
CircuitBreakerConfig config = CircuitBreakerConfig.custom().ringBufferSizeInClosedState(3).ringBufferSizeInHalfOpenState(2).failureRateThreshold(66).waitDurationInOpenState(Duration.ofSeconds(1)).recordFailure(e -> !(e instanceof IllegalArgumentException)).build();
CircuitBreaker circuitBreaker = CircuitBreakerRegistry.ofDefaults().circuitBreaker("test", config);
Runnable run = decorateRunnable(circuitBreaker, () -> System.out.println("."));
Runnable fail = decorateRunnable(circuitBreaker, () -> {
throw new ConcurrentModificationException();
});
Runnable ignore = decorateRunnable(circuitBreaker, () -> {
throw new IllegalArgumentException();
});
SseEmitter sseEmitter = createSseEmitter(ReactorAdapter.toFlux(circuitBreaker.getEventPublisher()));
TestHandler handler = new TestHandler();
sseEmitter.initialize(handler);
exec(run, 2);
exec(ignore, 1);
exec(fail, 3);
circuitBreaker.reset();
exec(run, 2);
circuitBreaker.reset();
sseEmitter.complete();
assert handler.isCompleted;
exec(run, 2);
List<CircuitBreakerEvent.Type> events = handler.events.stream().map(CircuitBreakerEventDTO::getType).collect(toList());
then(events).containsExactly(SUCCESS, SUCCESS, IGNORED_ERROR, ERROR, ERROR, STATE_TRANSITION, NOT_PERMITTED, STATE_TRANSITION, RESET, SUCCESS, SUCCESS, RESET);
}
Aggregations