### Question:
StatsSlidingWindow { public Bucket getStat() { return getStat(size); } StatsSlidingWindow(Duration period, int size);  StatsSlidingWindow(Duration period, int size, Clock clock); Bucket getCurrent(); Bucket getStat(); Bucket getStat(int count); void reset(); long getPeriodMillis(); int getSize(); @Override String toString();  }### Answer:
@Test(groups = "unit") public void getStat() throws Exception { Instant start = Instant.now(); TestClock clock = new TestClock(); clock.setCurrentTime(start.plusSeconds(23)); StatsSlidingWindow slidingWindow = new StatsSlidingWindow(Duration.ofSeconds(1), 10, clock); slidingWindow.getCurrent() .requestEnd( ThriftRequestStatus.SUCCESS, 20); slidingWindow.getCurrent() .requestEnd(ThriftRequestStatus.SUCCESS, 40); StatsSlidingWindow.Bucket stat = slidingWindow.getStat(); assertEquals(stat.getRequestEndCount(1), 2); assertEquals(stat.getRequestLatencyNanos(1), 30.0, 0.001); assertEquals(stat.getErrorRatio(1), 0.0, 0.001); clock.setCurrentTime(start.plusSeconds(25)); slidingWindow.getCurrent().requestEnd(ThriftRequestStatus.CONNECTION_ERROR, 60); stat = slidingWindow.getStat(); assertEquals(stat.getRequestEndCount(1), 3); assertEquals(stat.getRequestLatencyNanos(1), 40.0, 0.001); assertEquals(stat.getErrorRatio(1), 0.3333, 0.001); clock.setCurrentTime(start.plusSeconds(26)); slidingWindow.getCurrent() .requestEnd(ThriftRequestStatus.CONNECTION_ERROR, 60); clock.setCurrentTime(start.plusSeconds(27)); slidingWindow.getCurrent() .requestEnd(ThriftRequestStatus.CONNECTION_ERROR, 60); clock.setCurrentTime(start.plusSeconds(28)); slidingWindow.getCurrent().requestEnd(ThriftRequestStatus.CONNECTION_ERROR, 60); clock.setCurrentTime(start.plusSeconds(29)); slidingWindow.getCurrent().requestEnd(ThriftRequestStatus.CONNECTION_ERROR, 60); clock.setCurrentTime(start.plusSeconds(30)); slidingWindow.getCurrent().requestEnd(ThriftRequestStatus.CONNECTION_ERROR, 60); clock.setCurrentTime(start.plusSeconds(31)); slidingWindow.getCurrent().requestEnd(ThriftRequestStatus.CONNECTION_ERROR, 60); clock.setCurrentTime(start.plusSeconds(32)); slidingWindow.getCurrent().requestEnd(ThriftRequestStatus.CONNECTION_ERROR, 60); clock.setCurrentTime(start.plusSeconds(33)); slidingWindow.getCurrent().requestEnd(ThriftRequestStatus.CONNECTION_ERROR, 60); clock.setCurrentTime(start.plusSeconds(34)); slidingWindow.getCurrent().requestEnd(ThriftRequestStatus.CONNECTION_ERROR, 60); stat = slidingWindow.getStat(); assertEquals(stat.getRequestEndCount(1), 10); assertEquals(stat.getRequestLatencyNanos(1), 60.0, 0.001); assertEquals(stat.getErrorRatio(1), 1.0, 0.001); }