@Test public void shouldBufferAllEvents() { CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom() .slidingWindowSize(3) .ignoreExceptions(IOException.class) .build(); CircuitBreaker circuitBreaker = CircuitBreaker.of("testName", circuitBreakerConfig); CircularEventConsumer<CircuitBreakerEvent> ringBuffer = new CircularEventConsumer<>(10); circuitBreaker.getEventPublisher().onEvent(ringBuffer); assertThat(ringBuffer.getBufferedEvents()).isEmpty(); circuitBreaker.onSuccess(0, TimeUnit.NANOSECONDS); circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new RuntimeException("Bla")); circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new IOException("Bla")); circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new RuntimeException("Bla")); CircuitBreaker.Metrics metrics = circuitBreaker.getMetrics(); assertThat(metrics.getNumberOfBufferedCalls()).isEqualTo(3); assertThat(metrics.getNumberOfFailedCalls()).isEqualTo(2); circuitBreaker.reset(); CircuitBreaker.Metrics resetMetrics = circuitBreaker.getMetrics(); assertThat(resetMetrics.getNumberOfBufferedCalls()).isEqualTo(0); assertThat(resetMetrics.getNumberOfFailedCalls()).isEqualTo(0); assertThat(ringBuffer.getBufferedEvents()).hasSize(8); assertThat(ringBuffer.getBufferedEvents()).extracting("eventType") .containsExactly(Type.SUCCESS, Type.ERROR, Type.IGNORED_ERROR, Type.ERROR, Type.FAILURE_RATE_EXCEEDED, Type.STATE_TRANSITION, Type.STATE_TRANSITION, Type.RESET); }
public List<T> getBufferedEvents() { return eventCircularFifoBuffer.toList(); }
CircularEventConsumer implements EventConsumer<T> { public List<T> getBufferedEvents() { return eventCircularFifoBuffer.toList(); } }
CircularEventConsumer implements EventConsumer<T> { public List<T> getBufferedEvents() { return eventCircularFifoBuffer.toList(); } CircularEventConsumer(int capacity); }
CircularEventConsumer implements EventConsumer<T> { public List<T> getBufferedEvents() { return eventCircularFifoBuffer.toList(); } CircularEventConsumer(int capacity); @Override void consumeEvent(T event); List<T> getBufferedEvents(); }
CircularEventConsumer implements EventConsumer<T> { public List<T> getBufferedEvents() { return eventCircularFifoBuffer.toList(); } CircularEventConsumer(int capacity); @Override void consumeEvent(T event); List<T> getBufferedEvents();  }