Search in sources :

Example 6 with RandomIntPairGenerator

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);
}
Also used : DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) RandomIntPairGenerator(org.apache.flink.runtime.operators.testutils.RandomIntPairGenerator) IntPair(org.apache.flink.runtime.operators.testutils.types.IntPair) MemorySegment(org.apache.flink.core.memory.MemorySegment) Test(org.junit.Test)

Aggregations

RandomIntPairGenerator (org.apache.flink.runtime.operators.testutils.RandomIntPairGenerator)6 IntPair (org.apache.flink.runtime.operators.testutils.types.IntPair)6 Test (org.junit.Test)6 MemorySegment (org.apache.flink.core.memory.MemorySegment)5 DummyInvokable (org.apache.flink.runtime.operators.testutils.DummyInvokable)5