@Test public void shouldBufferErrorEvents() { CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("testName"); CircularEventConsumer<CircuitBreakerEvent> ringBuffer = new CircularEventConsumer<>(2); circuitBreaker.getEventPublisher().onEvent(ringBuffer); assertThat(ringBuffer.getBufferedEvents()).isEmpty(); circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new RuntimeException("Bla")); circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new RuntimeException("Bla")); circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new RuntimeException("Bla")); CircuitBreaker.Metrics metrics = circuitBreaker.getMetrics(); assertThat(metrics.getNumberOfBufferedCalls()).isEqualTo(3); assertThat(metrics.getNumberOfFailedCalls()).isEqualTo(3); assertThat(ringBuffer.getBufferedEvents()).hasSize(2); }
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();  }