FixedLengthRecordSorter implements InMemorySorter<T> { @Override public void reset() { this.numRecords = 0; this.currentSortBufferOffset = 0; this.sortBufferBytes = 0; this.freeMemory.addAll(this.sortBuffer); this.sortBuffer.clear(); this.currentSortBufferSegment = nextMemorySegment(); this.sortBuffer.add(this.currentSortBufferSegment); this.outView.set(this.currentSortBufferSegment); } FixedLengthRecordSorter(TypeSerializer<T> serializer, TypeComparator<T> comparator, 
			List<MemorySegment> memory); @Override void reset(); @Override boolean isEmpty(); @Override void dispose(); @Override long getCapacity(); @Override long getOccupancy(); @Override T getRecord(int logicalPosition); @Override T getRecord(T reuse, int logicalPosition); @Override boolean write(T record); @Override int compare(int i, int j); @Override void swap(int i, int j); @Override int size(); @Override final MutableObjectIterator<T> getIterator(); @Override void writeToOutput(final ChannelWriterOutputView output); @Override void writeToOutput(ChannelWriterOutputView output, LargeRecordHandler<T> largeRecordsOutput); @Override void writeToOutput(final ChannelWriterOutputView output, final int start, int num);  }
@Test public void testReset() throws Exception { final int numSegments = MEMORY_SIZE / MEMORY_PAGE_SIZE; final List<MemorySegment> memory = this.memoryManager.allocatePages(new DummyInvokable(), numSegments); FixedLengthRecordSorter<IntPair> sorter = newSortBuffer(memory); RandomIntPairGenerator generator = new RandomIntPairGenerator(SEED); IntPair record = new IntPair(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record) && num < 3354624); sorter.reset(); generator.reset(); int num2 = -1; do { generator.next(record); num2++; } while (sorter.write(record) && num2 < 3354624); Assert.assertEquals("The number of records written after the reset was not the same as before.", num, num2); generator.reset(); IntPair readTarget = new IntPair(); int i = 0; while (i < num) { generator.next(record); readTarget = sorter.getRecord(readTarget, i++); int rk = readTarget.getKey(); int gk = record.getKey(); int rv = readTarget.getValue(); int gv = record.getValue(); Assert.assertEquals("The re-read key is wrong", gk, rk); Assert.assertEquals("The re-read value is wrong", gv, rv); } sorter.dispose(); this.memoryManager.release(memory); }