Search in sources :

Example 1 with Pair

use of org.apache.flink.runtime.operators.testutils.PairGenerator.Pair in project flink by apache.

the class FileChannelStreamsITCase method testReadTooMany.

@Test
public void testReadTooMany() {
    try {
        final List<MemorySegment> memory = memManager.allocatePages(new DummyInvokable(), NUM_MEMORY_SEGMENTS);
        final PairGenerator generator = new PairGenerator(SEED, KEY_MAX, VALUE_SHORT_LENGTH, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
        final FileIOChannel.ID channel = this.ioManager.createChannel();
        // create the writer output view
        final BlockChannelWriter<MemorySegment> writer = this.ioManager.createBlockChannelWriter(channel);
        final FileChannelOutputView outView = new FileChannelOutputView(writer, memManager, memory, MEMORY_PAGE_SIZE);
        // write a number of pairs
        Pair pair = new Pair();
        for (int i = 0; i < NUM_PAIRS_SHORT; i++) {
            generator.next(pair);
            pair.write(outView);
        }
        outView.close();
        // create the reader input view
        List<MemorySegment> readMemory = memManager.allocatePages(new DummyInvokable(), NUM_MEMORY_SEGMENTS);
        final BlockChannelReader<MemorySegment> reader = ioManager.createBlockChannelReader(channel);
        final FileChannelInputView inView = new FileChannelInputView(reader, memManager, readMemory, outView.getBytesInLatestSegment());
        generator.reset();
        // read and re-generate all records and compare them
        try {
            Pair readPair = new Pair();
            for (int i = 0; i < NUM_PAIRS_SHORT + 1; i++) {
                generator.next(pair);
                readPair.read(inView);
                assertEquals("The re-generated and the read record do not match.", pair, readPair);
            }
            fail("Expected an EOFException which did not occur.");
        } catch (EOFException eofex) {
        // expected
        }
        inView.close();
        reader.deleteChannel();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : PairGenerator(org.apache.flink.runtime.operators.testutils.PairGenerator) FileIOChannel(org.apache.flink.runtime.io.disk.iomanager.FileIOChannel) MemorySegment(org.apache.flink.core.memory.MemorySegment) EOFException(java.io.EOFException) EOFException(java.io.EOFException) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) Pair(org.apache.flink.runtime.operators.testutils.PairGenerator.Pair) Test(org.junit.Test)

Example 2 with Pair

use of org.apache.flink.runtime.operators.testutils.PairGenerator.Pair in project flink by apache.

the class FileChannelStreamsITCase method testWriteAndReadLongRecords.

@Test
public void testWriteAndReadLongRecords() {
    try {
        final List<MemorySegment> memory = memManager.allocatePages(new DummyInvokable(), NUM_MEMORY_SEGMENTS);
        final PairGenerator generator = new PairGenerator(SEED, KEY_MAX, VALUE_LONG_LENGTH, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
        final FileIOChannel.ID channel = this.ioManager.createChannel();
        // create the writer output view
        final BlockChannelWriter<MemorySegment> writer = this.ioManager.createBlockChannelWriter(channel);
        final FileChannelOutputView outView = new FileChannelOutputView(writer, memManager, memory, MEMORY_PAGE_SIZE);
        // write a number of pairs
        Pair pair = new Pair();
        for (int i = 0; i < NUM_PAIRS_LONG; i++) {
            generator.next(pair);
            pair.write(outView);
        }
        outView.close();
        // create the reader input view
        List<MemorySegment> readMemory = memManager.allocatePages(new DummyInvokable(), NUM_MEMORY_SEGMENTS);
        final BlockChannelReader<MemorySegment> reader = ioManager.createBlockChannelReader(channel);
        final FileChannelInputView inView = new FileChannelInputView(reader, memManager, readMemory, outView.getBytesInLatestSegment());
        generator.reset();
        // read and re-generate all records and compare them
        Pair readPair = new Pair();
        for (int i = 0; i < NUM_PAIRS_LONG; i++) {
            generator.next(pair);
            readPair.read(inView);
            assertEquals("The re-generated and the read record do not match.", pair, readPair);
        }
        inView.close();
        reader.deleteChannel();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : PairGenerator(org.apache.flink.runtime.operators.testutils.PairGenerator) FileIOChannel(org.apache.flink.runtime.io.disk.iomanager.FileIOChannel) MemorySegment(org.apache.flink.core.memory.MemorySegment) EOFException(java.io.EOFException) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) Pair(org.apache.flink.runtime.operators.testutils.PairGenerator.Pair) Test(org.junit.Test)

Example 3 with Pair

use of org.apache.flink.runtime.operators.testutils.PairGenerator.Pair in project flink by apache.

the class FileChannelStreamsITCase method testWriteReadOneBufferOnly.

@Test
public void testWriteReadOneBufferOnly() {
    try {
        final List<MemorySegment> memory = memManager.allocatePages(new DummyInvokable(), 1);
        final PairGenerator generator = new PairGenerator(SEED, KEY_MAX, VALUE_SHORT_LENGTH, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
        final FileIOChannel.ID channel = this.ioManager.createChannel();
        // create the writer output view
        final BlockChannelWriter<MemorySegment> writer = this.ioManager.createBlockChannelWriter(channel);
        final FileChannelOutputView outView = new FileChannelOutputView(writer, memManager, memory, MEMORY_PAGE_SIZE);
        // write a number of pairs
        Pair pair = new Pair();
        for (int i = 0; i < NUM_PAIRS_SHORT; i++) {
            generator.next(pair);
            pair.write(outView);
        }
        outView.close();
        // create the reader input view
        List<MemorySegment> readMemory = memManager.allocatePages(new DummyInvokable(), 1);
        final BlockChannelReader<MemorySegment> reader = ioManager.createBlockChannelReader(channel);
        final FileChannelInputView inView = new FileChannelInputView(reader, memManager, readMemory, outView.getBytesInLatestSegment());
        generator.reset();
        // read and re-generate all records and compare them
        Pair readPair = new Pair();
        for (int i = 0; i < NUM_PAIRS_SHORT; i++) {
            generator.next(pair);
            readPair.read(inView);
            assertEquals("The re-generated and the read record do not match.", pair, readPair);
        }
        inView.close();
        reader.deleteChannel();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : PairGenerator(org.apache.flink.runtime.operators.testutils.PairGenerator) FileIOChannel(org.apache.flink.runtime.io.disk.iomanager.FileIOChannel) MemorySegment(org.apache.flink.core.memory.MemorySegment) EOFException(java.io.EOFException) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) Pair(org.apache.flink.runtime.operators.testutils.PairGenerator.Pair) Test(org.junit.Test)

Example 4 with Pair

use of org.apache.flink.runtime.operators.testutils.PairGenerator.Pair in project flink by apache.

the class FileChannelStreamsITCase method testWriteReadSmallRecords.

// --------------------------------------------------------------------------------------------
@Test
public void testWriteReadSmallRecords() {
    try {
        List<MemorySegment> memory = memManager.allocatePages(new DummyInvokable(), NUM_MEMORY_SEGMENTS);
        final PairGenerator generator = new PairGenerator(SEED, KEY_MAX, VALUE_SHORT_LENGTH, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
        final FileIOChannel.ID channel = ioManager.createChannel();
        // create the writer output view
        final BlockChannelWriter<MemorySegment> writer = ioManager.createBlockChannelWriter(channel);
        final FileChannelOutputView outView = new FileChannelOutputView(writer, memManager, memory, MEMORY_PAGE_SIZE);
        // write a number of pairs
        Pair pair = new Pair();
        for (int i = 0; i < NUM_PAIRS_SHORT; i++) {
            generator.next(pair);
            pair.write(outView);
        }
        outView.close();
        // create the reader input view
        List<MemorySegment> readMemory = memManager.allocatePages(new DummyInvokable(), NUM_MEMORY_SEGMENTS);
        final BlockChannelReader<MemorySegment> reader = ioManager.createBlockChannelReader(channel);
        final FileChannelInputView inView = new FileChannelInputView(reader, memManager, readMemory, outView.getBytesInLatestSegment());
        generator.reset();
        // read and re-generate all records and compare them
        Pair readPair = new Pair();
        for (int i = 0; i < NUM_PAIRS_SHORT; i++) {
            generator.next(pair);
            readPair.read(inView);
            assertEquals("The re-generated and the read record do not match.", pair, readPair);
        }
        inView.close();
        reader.deleteChannel();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : PairGenerator(org.apache.flink.runtime.operators.testutils.PairGenerator) FileIOChannel(org.apache.flink.runtime.io.disk.iomanager.FileIOChannel) MemorySegment(org.apache.flink.core.memory.MemorySegment) EOFException(java.io.EOFException) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) Pair(org.apache.flink.runtime.operators.testutils.PairGenerator.Pair) Test(org.junit.Test)

Example 5 with Pair

use of org.apache.flink.runtime.operators.testutils.PairGenerator.Pair in project flink by apache.

the class FileChannelStreamsITCase method testWriteReadNotAll.

@Test
public void testWriteReadNotAll() {
    try {
        final List<MemorySegment> memory = memManager.allocatePages(new DummyInvokable(), NUM_MEMORY_SEGMENTS);
        final PairGenerator generator = new PairGenerator(SEED, KEY_MAX, VALUE_SHORT_LENGTH, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
        final FileIOChannel.ID channel = this.ioManager.createChannel();
        // create the writer output view
        final BlockChannelWriter<MemorySegment> writer = this.ioManager.createBlockChannelWriter(channel);
        final FileChannelOutputView outView = new FileChannelOutputView(writer, memManager, memory, MEMORY_PAGE_SIZE);
        // write a number of pairs
        Pair pair = new Pair();
        for (int i = 0; i < NUM_PAIRS_SHORT; i++) {
            generator.next(pair);
            pair.write(outView);
        }
        outView.close();
        // create the reader input view
        List<MemorySegment> readMemory = memManager.allocatePages(new DummyInvokable(), NUM_MEMORY_SEGMENTS);
        final BlockChannelReader<MemorySegment> reader = ioManager.createBlockChannelReader(channel);
        final FileChannelInputView inView = new FileChannelInputView(reader, memManager, readMemory, outView.getBytesInLatestSegment());
        generator.reset();
        // read and re-generate all records and compare them
        Pair readPair = new Pair();
        for (int i = 0; i < NUM_PAIRS_SHORT / 2; i++) {
            generator.next(pair);
            readPair.read(inView);
            assertEquals("The re-generated and the read record do not match.", pair, readPair);
        }
        inView.close();
        reader.deleteChannel();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : PairGenerator(org.apache.flink.runtime.operators.testutils.PairGenerator) FileIOChannel(org.apache.flink.runtime.io.disk.iomanager.FileIOChannel) MemorySegment(org.apache.flink.core.memory.MemorySegment) EOFException(java.io.EOFException) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) Pair(org.apache.flink.runtime.operators.testutils.PairGenerator.Pair) Test(org.junit.Test)

Aggregations

EOFException (java.io.EOFException)5 MemorySegment (org.apache.flink.core.memory.MemorySegment)5 FileIOChannel (org.apache.flink.runtime.io.disk.iomanager.FileIOChannel)5 DummyInvokable (org.apache.flink.runtime.operators.testutils.DummyInvokable)5 PairGenerator (org.apache.flink.runtime.operators.testutils.PairGenerator)5 Pair (org.apache.flink.runtime.operators.testutils.PairGenerator.Pair)5 Test (org.junit.Test)5