@Test public void snapshotComputesPercentiles() { SlidingWindowHistogramReservoir reservoir = reservoirWithSamples(1, 100); assertThat(reservoir.getSnapshot().getMin(), is(1L)); assertThat(reservoir.getSnapshot().getMax(), is(100L)); assertThat(reservoir.getSnapshot().getMean(), is(closeTo(50.5, 1))); assertThat(reservoir.getSnapshot().get75thPercentile(), is(closeTo(75, 0.5))); assertThat(reservoir.getSnapshot().get95thPercentile(), is(closeTo(95, 0.5))); assertThat(reservoir.getSnapshot().get98thPercentile(), is(closeTo(98, 0.5))); assertThat(reservoir.getSnapshot().get99thPercentile(), is(closeTo(99, 0.5))); assertThat(reservoir.getSnapshot().getMedian(), is(closeTo(50L, 1))); }
@Override public synchronized Snapshot getSnapshot() { if (updated || snapshotExpired(clock.tickMillis())) { snapshot = new HistogramSnapshot(histogram); updated = false; snapshotCreationTime = clock.tickMillis(); } return snapshot; }
SlidingWindowHistogramReservoir implements Reservoir { @Override public synchronized Snapshot getSnapshot() { if (updated || snapshotExpired(clock.tickMillis())) { snapshot = new HistogramSnapshot(histogram); updated = false; snapshotCreationTime = clock.tickMillis(); } return snapshot; } }
SlidingWindowHistogramReservoir implements Reservoir { @Override public synchronized Snapshot getSnapshot() { if (updated || snapshotExpired(clock.tickMillis())) { snapshot = new HistogramSnapshot(histogram); updated = false; snapshotCreationTime = clock.tickMillis(); } return snapshot; } SlidingWindowHistogramReservoir();  SlidingWindowHistogramReservoir(SlidingWindowHistogram histogram);  SlidingWindowHistogramReservoir(SlidingWindowHistogram histogram, Clock clock); }
SlidingWindowHistogramReservoir implements Reservoir { @Override public synchronized Snapshot getSnapshot() { if (updated || snapshotExpired(clock.tickMillis())) { snapshot = new HistogramSnapshot(histogram); updated = false; snapshotCreationTime = clock.tickMillis(); } return snapshot; } SlidingWindowHistogramReservoir();  SlidingWindowHistogramReservoir(SlidingWindowHistogram histogram);  SlidingWindowHistogramReservoir(SlidingWindowHistogram histogram, Clock clock); @Override int size(); @Override synchronized void update(long value); @Override synchronized Snapshot getSnapshot(); }
SlidingWindowHistogramReservoir implements Reservoir { @Override public synchronized Snapshot getSnapshot() { if (updated || snapshotExpired(clock.tickMillis())) { snapshot = new HistogramSnapshot(histogram); updated = false; snapshotCreationTime = clock.tickMillis(); } return snapshot; } SlidingWindowHistogramReservoir();  SlidingWindowHistogramReservoir(SlidingWindowHistogram histogram);  SlidingWindowHistogramReservoir(SlidingWindowHistogram histogram, Clock clock); @Override int size(); @Override synchronized void update(long value); @Override synchronized Snapshot getSnapshot();  }