UniformSnapshot extends Snapshot { @Override public long[] getValues() { return Arrays.copyOf(values, values.length); } UniformSnapshot(Collection<Long> values);  UniformSnapshot(long[] values); @Override double getValue(double quantile); @Override int size(); @Override long[] getValues(); @Override long getMax(); @Override long getMin(); @Override double getMean(); @Override double getStdDev(); @Override void dump(OutputStream output);  }
@Test public void hasValues() { assertThat(snapshot.getValues()) .containsOnly(1, 2, 3, 4, 5); }
@Test public void canAlsoBeCreatedFromACollectionOfLongs() { final Snapshot other = new UniformSnapshot(asList(5L, 1L, 2L, 3L, 4L)); assertThat(other.getValues()) .containsOnly(1, 2, 3, 4, 5); }
@Test public void correctlyCreatedFromCollectionWithWeakIterator() throws Exception { final ConcurrentSkipListSet<Long> values = new ConcurrentSkipListSet<>(); final CountDownLatch latch = new CountDownLatch(10); final Thread backgroundThread = new Thread(() -> { final Random random = new Random(); while (!Thread.currentThread().isInterrupted()) { values.add(random.nextLong()); latch.countDown(); } }); backgroundThread.start(); try { latch.await(5, TimeUnit.SECONDS); assertThat(latch.getCount()).isEqualTo(0); final Snapshot snapshot = new UniformSnapshot(values); assertThat(snapshot.getValues().length).isGreaterThanOrEqualTo(10); } finally { backgroundThread.interrupt(); } }