@Override
  public CloseableIterator<T> iterator() {
    ParallelIterator<T> iter =
        new ParallelIterator<>(iterables, workerPool, approximateMaxQueueSize);
    addCloseable(iter);
    return iter;
  }
@Test
  public void limitQueueSize() {
    List<Iterable<Integer>> iterables =
        ImmutableList.of(
            () -> IntStream.range(0, 100).iterator(),
            () -> IntStream.range(0, 100).iterator(),
            () -> IntStream.range(0, 100).iterator());

    Multiset<Integer> expectedValues =
        IntStream.range(0, 100)
            .boxed()
            .flatMap(i -> Stream.of(i, i, i))
            .collect(ImmutableMultiset.toImmutableMultiset());

    int maxQueueSize = 20;
    ExecutorService executor = Executors.newCachedThreadPool();
    ParallelIterable<Integer> parallelIterable =
        new ParallelIterable<>(iterables, executor, maxQueueSize);
    ParallelIterator<Integer> iterator = (ParallelIterator<Integer>) parallelIterable.iterator();

    Multiset<Integer> actualValues = HashMultiset.create();

    while (iterator.hasNext()) {
      assertThat(iterator.queueSize())
          .as("iterator internal queue size")
          .isLessThanOrEqualTo(maxQueueSize + iterables.size());
      actualValues.add(iterator.next());
    }

    assertThat(actualValues)
        .as("multiset of values returned by the iterator")
        .isEqualTo(expectedValues);

    iterator.close();
    executor.shutdownNow();
  }