use of org.apache.flink.runtime.operators.testutils.RandomIntPairGenerator in project flink by apache.
the class FixedLengthRecordSorterTest method testSort.
@Test
public void testSort() throws Exception {
final int NUM_RECORDS = 559273;
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);
// write the records
IntPair record = new IntPair();
int num = -1;
do {
generator.next(record);
num++;
} while (sorter.write(record) && num < NUM_RECORDS);
QuickSort qs = new QuickSort();
qs.sort(sorter);
MutableObjectIterator<IntPair> iter = sorter.getIterator();
IntPair readTarget = new IntPair();
int current;
int last;
iter.next(readTarget);
last = readTarget.getKey();
while ((readTarget = iter.next(readTarget)) != null) {
current = readTarget.getKey();
final int cmp = last - current;
if (cmp > 0) {
Assert.fail("Next key is not larger or equal to previous key.");
}
last = current;
}
// release the memory occupied by the buffers
sorter.dispose();
this.memoryManager.release(memory);
}
Aggregations