SpillingResettableIterator implements ResettableIterator<T> { @Override public T next() { if (this.next != null || hasNext()) { final T out = this.next; this.next = null; return out; } else { throw new NoSuchElementException(); } } SpillingResettableIterator(Iterator<T> input, TypeSerializer<T> serializer, 
			MemoryManager memoryManager, IOManager ioManager,
			long availableMemory, AbstractInvokable parentTask);  SpillingResettableIterator(Iterator<T> input, TypeSerializer<T> serializer,
			MemoryManager memoryManager, IOManager ioManager, List<MemorySegment> memory); private  SpillingResettableIterator(Iterator<T> input, TypeSerializer<T> serializer,
			MemoryManager memoryManager, IOManager ioManager,
			List<MemorySegment> memory, boolean releaseMemOnClose); void open(); void reset(); @Override boolean hasNext(); @Override T next(); @Override void remove(); List<MemorySegment> close();  }
@Test public void testNext() { try { SpillingResettableIterator<PactInteger> iterator = new SpillingResettableIterator<PactInteger>( this.reader, this.serializer, this.memman, this.ioman, 2 * 32 * 1024, this.memOwner); try { iterator.open(); } catch (IOException e) { Assert.fail("Could not open resettable iterator:" + e.getMessage()); } PactInteger record; int cnt = 0; while (cnt < NUM_TESTRECORDS) { record = iterator.next(); Assert.assertTrue("Record was not read from iterator", record != null); cnt++; } try { record = iterator.next(); Assert.fail("Too many records were read from iterator."); } catch (NoSuchElementException nseex) { } iterator.close(); } catch (Exception ex) { ex.printStackTrace(); Assert.fail("Test encountered an exception."); } }