@Override
    public boolean hasNext() {
        try {
            if (this.nextElement == null) {
                if (this.readPhase) {
                    // read phase, get next element from buffer
                    T tmp = getNextRecord(this.reuseElement);
                    if (tmp != null) {
                        this.nextElement = tmp;
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    if (this.input.hasNext()) {
                        final T next = this.input.next();
                        if (writeNextRecord(next)) {
                            this.nextElement = next;
                            return true;
                        } else {
                            this.leftOverElement = next;
                            return false;
                        }
                    } else {
                        this.noMoreBlocks = true;
                        return false;
                    }
                }
            } else {
                return true;
            }
        } catch (IOException ioex) {
            throw new RuntimeException(
                    "Error (de)serializing record in block resettable iterator.", ioex);
        }
    }
@Test
    void testDoubleBufferedBlockResettableIterator() throws Exception {
        final AbstractInvokable memOwner = new DummyInvokable();
        // create the resettable Iterator
        final ReusingBlockResettableIterator<Record> iterator =
                new ReusingBlockResettableIterator<Record>(
                        this.memman, this.reader, this.serializer, 2, memOwner);
        // open the iterator
        iterator.open();

        // now test walking through the iterator
        int lower = 0;
        int upper = 0;
        do {
            lower = upper;
            upper = lower;
            // find the upper bound
            while (iterator.hasNext()) {
                Record target = iterator.next();
                int val = target.getField(0, IntValue.class).getValue();
                assertThat(val).isEqualTo(upper++);
            }
            // now reset the buffer a few times
            for (int i = 0; i < 5; ++i) {
                iterator.reset();
                int count = 0;
                while (iterator.hasNext()) {
                    Record target = iterator.next();
                    int val = target.getField(0, IntValue.class).getValue();
                    assertThat(val).isEqualTo(lower + (count++));
                }
                assertThat(count).isEqualTo(upper - lower);
            }
        } while (iterator.nextBlock());
        assertThat(upper).isEqualTo(NUM_VALUES);

        // close the iterator
        iterator.close();
    }