@Override
  public final int size() {
    // NOTE: because indices are on even numbers we cannot use the size util.

    /*
     * It is possible for a thread to be interrupted or reschedule between the read of the producer
     * and consumer indices, therefore protection is required to ensure size is within valid range.
     * In the event of concurrent polls/offers to this method the size is OVER estimated as we read
     * consumer index BEFORE the producer index.
     */
    long after = lvConsumerIndex(this);
    long size;
    while (true) {
      final long before = after;
      final long currentProducerIndex = lvProducerIndex(this);
      after = lvConsumerIndex(this);
      if (before == after) {
        size = ((currentProducerIndex - after) >> 1);
        break;
      }
    }
    // Long overflow is impossible, so size is always positive. Integer overflow is possible for the
    // unbounded indexed queues.
    if (size > Integer.MAX_VALUE) {
      return Integer.MAX_VALUE;
    } else {
      return (int) size;
    }
  }
@Test(dataProvider = "populated")
  public void size_whenPopulated(MpscGrowableArrayQueue<Integer> queue) {
    assertThat(queue.size()).isEqualTo(POPULATED_SIZE);
  }