SlidingWindowCounter implements EventCounter { @Override public EventCount onFailure() { return onEvent(Event.FAILURE); } SlidingWindowCounter(Ticker ticker, Duration slidingWindow, Duration updateInterval); @Override EventCount count(); @Override EventCount onSuccess(); @Override EventCount onFailure();  }
@Test void testOnFailure() { final SlidingWindowCounter counter = new SlidingWindowCounter(ticker::get, Duration.ofSeconds(10), Duration.ofSeconds(1)); assertThat(counter.onFailure()).isNull(); ticker.addAndGet(TimeUnit.SECONDS.toNanos(1)); assertThat(counter.onFailure()).isEqualTo(EventCount.of(0, 1)); assertThat(counter.count()).isEqualTo(EventCount.of(0, 1)); }