@Override
    public long[] getValues() {
        return Arrays.copyOf(values, values.length);
    }
@Test
    public void correctlyCreatedFromCollectionWithWeakIterator() throws Exception {
        final ConcurrentSkipListSet<Long> values = new ConcurrentSkipListSet<>();

        // Create a latch to make sure that the background thread has started and
        // pushed some data to the collection.
        final CountDownLatch latch = new CountDownLatch(10);
        final Thread backgroundThread = new Thread(() -> {
            final Random random = new Random();
            // Update the collection in the loop to trigger a potential `ArrayOutOfBoundException`
            // and verify that the snapshot doesn't make assumptions about the size of the iterator.
            while (!Thread.currentThread().isInterrupted()) {
                values.add(random.nextLong());
                latch.countDown();
            }
        });
        backgroundThread.start();

        try {
            latch.await(5, TimeUnit.SECONDS);
            assertThat(latch.getCount()).isEqualTo(0);

            // Create a snapshot while the  collection is being updated.
            final Snapshot snapshot = new UniformSnapshot(values);
            assertThat(snapshot.getValues().length).isGreaterThanOrEqualTo(10);
        } finally {
            backgroundThread.interrupt();
        }
    }