SlidingTimeWindowMetrics implements Metrics { public synchronized Snapshot getSnapshot() { moveWindowToCurrentEpochSecond(getLatestPartialAggregation()); return new SnapshotImpl(totalAggregation); } SlidingTimeWindowMetrics(int timeWindowSizeInSeconds, Clock clock); @Override synchronized Snapshot record(long duration, TimeUnit durationUnit, Outcome outcome); synchronized Snapshot getSnapshot();  }
@Test public void checkInitialBucketCreation() { MockClock clock = MockClock.at(2019, 8, 4, 12, 0, 0, ZoneId.of("UTC")); SlidingTimeWindowMetrics metrics = new SlidingTimeWindowMetrics(5, clock); PartialAggregation[] buckets = metrics.partialAggregations; long epochSecond = clock.instant().getEpochSecond(); for (int i = 0; i < buckets.length; i++) { PartialAggregation bucket = buckets[i]; assertThat(bucket.getEpochSecond()).isEqualTo(epochSecond + i); } Snapshot snapshot = metrics.getSnapshot(); assertThat(snapshot.getTotalNumberOfCalls()).isEqualTo(0); assertThat(snapshot.getNumberOfSuccessfulCalls()).isEqualTo(0); assertThat(snapshot.getNumberOfFailedCalls()).isEqualTo(0); assertThat(snapshot.getTotalDuration().toMillis()).isEqualTo(0); }