Java Code Examples for org.apache.flink.runtime.operators.testutils.UniformIntPairGenerator#next()
The following examples show how to use
org.apache.flink.runtime.operators.testutils.UniformIntPairGenerator#next() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FixedLengthRecordSorterTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * The compare test creates a sorted stream, writes it to the buffer and * compares random elements. It expects that earlier elements are lower than later * ones. */ @Test public void testCompare() 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); UniformIntPairGenerator generator = new UniformIntPairGenerator(Integer.MAX_VALUE, 1, true); // write the records IntPair record = new IntPair(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record) && num < 3354624); // compare random elements Random rnd = new Random(SEED << 1); for (int i = 0; i < 2 * num; i++) { int pos1 = rnd.nextInt(num); int pos2 = rnd.nextInt(num); int cmp = sorter.compare(pos1, pos2); if (pos1 < pos2) { Assert.assertTrue(cmp <= 0); } else { Assert.assertTrue(cmp >= 0); } } // release the memory occupied by the buffers sorter.dispose(); this.memoryManager.release(memory); }
Example 2
Source File: FixedLengthRecordSorterTest.java From flink with Apache License 2.0 | 5 votes |
/** * The compare test creates a sorted stream, writes it to the buffer and * compares random elements. It expects that earlier elements are lower than later * ones. */ @Test public void testCompare() 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); UniformIntPairGenerator generator = new UniformIntPairGenerator(Integer.MAX_VALUE, 1, true); // write the records IntPair record = new IntPair(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record) && num < 3354624); // compare random elements Random rnd = new Random(SEED << 1); for (int i = 0; i < 2 * num; i++) { int pos1 = rnd.nextInt(num); int pos2 = rnd.nextInt(num); int cmp = sorter.compare(pos1, pos2); if (pos1 < pos2) { Assert.assertTrue(cmp <= 0); } else { Assert.assertTrue(cmp >= 0); } } // release the memory occupied by the buffers sorter.dispose(); this.memoryManager.release(memory); }
Example 3
Source File: FixedLengthRecordSorterTest.java From flink with Apache License 2.0 | 5 votes |
/** * The compare test creates a sorted stream, writes it to the buffer and * compares random elements. It expects that earlier elements are lower than later * ones. */ @Test public void testCompare() 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); UniformIntPairGenerator generator = new UniformIntPairGenerator(Integer.MAX_VALUE, 1, true); // write the records IntPair record = new IntPair(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record) && num < 3354624); // compare random elements Random rnd = new Random(SEED << 1); for (int i = 0; i < 2 * num; i++) { int pos1 = rnd.nextInt(num); int pos2 = rnd.nextInt(num); int cmp = sorter.compare(pos1, pos2); if (pos1 < pos2) { Assert.assertTrue(cmp <= 0); } else { Assert.assertTrue(cmp >= 0); } } // release the memory occupied by the buffers sorter.dispose(); this.memoryManager.release(memory); }
Example 4
Source File: FixedLengthRecordSorterTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testFlushFullMemoryPage() throws Exception { // Insert IntPair which would fill 2 memory pages. final int NUM_RECORDS = 2 * MEMORY_PAGE_SIZE / 8; final List<MemorySegment> memory = this.memoryManager.allocatePages(new DummyInvokable(), 3); FixedLengthRecordSorter<IntPair> sorter = newSortBuffer(memory); UniformIntPairGenerator generator = new UniformIntPairGenerator(Integer.MAX_VALUE, 1, false); // write the records IntPair record = new IntPair(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record) && num < NUM_RECORDS); FileIOChannel.ID channelID = this.ioManager.createChannelEnumerator().next(); BlockChannelWriter<MemorySegment> blockChannelWriter = this.ioManager.createBlockChannelWriter(channelID); final List<MemorySegment> writeBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelWriterOutputView outputView = new ChannelWriterOutputView(blockChannelWriter, writeBuffer, writeBuffer.get(0).size()); sorter.writeToOutput(outputView, 0, NUM_RECORDS); this.memoryManager.release(outputView.close()); BlockChannelReader<MemorySegment> blockChannelReader = this.ioManager.createBlockChannelReader(channelID); final List<MemorySegment> readBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelReaderInputView readerInputView = new ChannelReaderInputView(blockChannelReader, readBuffer, false); final List<MemorySegment> dataBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelReaderInputViewIterator<IntPair> iterator = new ChannelReaderInputViewIterator(readerInputView, dataBuffer, this.serializer); record = iterator.next(record); int i =0; while (record != null) { Assert.assertEquals(i, record.getKey()); record = iterator.next(record); i++; } Assert.assertEquals(NUM_RECORDS, i); this.memoryManager.release(dataBuffer); // release the memory occupied by the buffers sorter.dispose(); this.memoryManager.release(memory); }
Example 5
Source File: FixedLengthRecordSorterTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testFlushPartialMemoryPage() throws Exception { // Insert IntPair which would fill 2 memory pages. final int NUM_RECORDS = 2 * MEMORY_PAGE_SIZE / 8; final List<MemorySegment> memory = this.memoryManager.allocatePages(new DummyInvokable(), 3); FixedLengthRecordSorter<IntPair> sorter = newSortBuffer(memory); UniformIntPairGenerator generator = new UniformIntPairGenerator(Integer.MAX_VALUE, 1, false); // write the records IntPair record = new IntPair(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record) && num < NUM_RECORDS); FileIOChannel.ID channelID = this.ioManager.createChannelEnumerator().next(); BlockChannelWriter<MemorySegment> blockChannelWriter = this.ioManager.createBlockChannelWriter(channelID); final List<MemorySegment> writeBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelWriterOutputView outputView = new ChannelWriterOutputView(blockChannelWriter, writeBuffer, writeBuffer.get(0).size()); sorter.writeToOutput(outputView, 1, NUM_RECORDS - 1); this.memoryManager.release(outputView.close()); BlockChannelReader<MemorySegment> blockChannelReader = this.ioManager.createBlockChannelReader(channelID); final List<MemorySegment> readBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelReaderInputView readerInputView = new ChannelReaderInputView(blockChannelReader, readBuffer, false); final List<MemorySegment> dataBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelReaderInputViewIterator<IntPair> iterator = new ChannelReaderInputViewIterator(readerInputView, dataBuffer, this.serializer); record = iterator.next(record); int i =1; while (record != null) { Assert.assertEquals(i, record.getKey()); record = iterator.next(record); i++; } Assert.assertEquals(NUM_RECORDS, i); this.memoryManager.release(dataBuffer); // release the memory occupied by the buffers sorter.dispose(); this.memoryManager.release(memory); }
Example 6
Source File: FixedLengthRecordSorterTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testFlushFullMemoryPage() throws Exception { // Insert IntPair which would fill 2 memory pages. final int NUM_RECORDS = 2 * MEMORY_PAGE_SIZE / 8; final List<MemorySegment> memory = this.memoryManager.allocatePages(new DummyInvokable(), 3); FixedLengthRecordSorter<IntPair> sorter = newSortBuffer(memory); UniformIntPairGenerator generator = new UniformIntPairGenerator(Integer.MAX_VALUE, 1, false); // write the records IntPair record = new IntPair(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record) && num < NUM_RECORDS); FileIOChannel.ID channelID = this.ioManager.createChannelEnumerator().next(); BlockChannelWriter<MemorySegment> blockChannelWriter = this.ioManager.createBlockChannelWriter(channelID); final List<MemorySegment> writeBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelWriterOutputView outputView = new ChannelWriterOutputView(blockChannelWriter, writeBuffer, writeBuffer.get(0).size()); sorter.writeToOutput(outputView, 0, NUM_RECORDS); this.memoryManager.release(outputView.close()); BlockChannelReader<MemorySegment> blockChannelReader = this.ioManager.createBlockChannelReader(channelID); final List<MemorySegment> readBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelReaderInputView readerInputView = new ChannelReaderInputView(blockChannelReader, readBuffer, false); final List<MemorySegment> dataBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelReaderInputViewIterator<IntPair> iterator = new ChannelReaderInputViewIterator(readerInputView, dataBuffer, this.serializer); record = iterator.next(record); int i =0; while (record != null) { Assert.assertEquals(i, record.getKey()); record = iterator.next(record); i++; } Assert.assertEquals(NUM_RECORDS, i); this.memoryManager.release(dataBuffer); // release the memory occupied by the buffers sorter.dispose(); this.memoryManager.release(memory); }
Example 7
Source File: FixedLengthRecordSorterTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testFlushPartialMemoryPage() throws Exception { // Insert IntPair which would fill 2 memory pages. final int NUM_RECORDS = 2 * MEMORY_PAGE_SIZE / 8; final List<MemorySegment> memory = this.memoryManager.allocatePages(new DummyInvokable(), 3); FixedLengthRecordSorter<IntPair> sorter = newSortBuffer(memory); UniformIntPairGenerator generator = new UniformIntPairGenerator(Integer.MAX_VALUE, 1, false); // write the records IntPair record = new IntPair(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record) && num < NUM_RECORDS); FileIOChannel.ID channelID = this.ioManager.createChannelEnumerator().next(); BlockChannelWriter<MemorySegment> blockChannelWriter = this.ioManager.createBlockChannelWriter(channelID); final List<MemorySegment> writeBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelWriterOutputView outputView = new ChannelWriterOutputView(blockChannelWriter, writeBuffer, writeBuffer.get(0).size()); sorter.writeToOutput(outputView, 1, NUM_RECORDS - 1); this.memoryManager.release(outputView.close()); BlockChannelReader<MemorySegment> blockChannelReader = this.ioManager.createBlockChannelReader(channelID); final List<MemorySegment> readBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelReaderInputView readerInputView = new ChannelReaderInputView(blockChannelReader, readBuffer, false); final List<MemorySegment> dataBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelReaderInputViewIterator<IntPair> iterator = new ChannelReaderInputViewIterator(readerInputView, dataBuffer, this.serializer); record = iterator.next(record); int i =1; while (record != null) { Assert.assertEquals(i, record.getKey()); record = iterator.next(record); i++; } Assert.assertEquals(NUM_RECORDS, i); this.memoryManager.release(dataBuffer); // release the memory occupied by the buffers sorter.dispose(); this.memoryManager.release(memory); }
Example 8
Source File: FixedLengthRecordSorterTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testFlushFullMemoryPage() throws Exception { // Insert IntPair which would fill 2 memory pages. final int NUM_RECORDS = 2 * MEMORY_PAGE_SIZE / 8; final List<MemorySegment> memory = this.memoryManager.allocatePages(new DummyInvokable(), 3); FixedLengthRecordSorter<IntPair> sorter = newSortBuffer(memory); UniformIntPairGenerator generator = new UniformIntPairGenerator(Integer.MAX_VALUE, 1, false); // write the records IntPair record = new IntPair(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record) && num < NUM_RECORDS); FileIOChannel.ID channelID = this.ioManager.createChannelEnumerator().next(); BlockChannelWriter<MemorySegment> blockChannelWriter = this.ioManager.createBlockChannelWriter(channelID); final List<MemorySegment> writeBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelWriterOutputView outputView = new ChannelWriterOutputView(blockChannelWriter, writeBuffer, writeBuffer.get(0).size()); sorter.writeToOutput(outputView, 0, NUM_RECORDS); this.memoryManager.release(outputView.close()); BlockChannelReader<MemorySegment> blockChannelReader = this.ioManager.createBlockChannelReader(channelID); final List<MemorySegment> readBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelReaderInputView readerInputView = new ChannelReaderInputView(blockChannelReader, readBuffer, false); final List<MemorySegment> dataBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelReaderInputViewIterator<IntPair> iterator = new ChannelReaderInputViewIterator(readerInputView, dataBuffer, this.serializer); record = iterator.next(record); int i =0; while (record != null) { Assert.assertEquals(i, record.getKey()); record = iterator.next(record); i++; } Assert.assertEquals(NUM_RECORDS, i); this.memoryManager.release(dataBuffer); // release the memory occupied by the buffers sorter.dispose(); this.memoryManager.release(memory); }
Example 9
Source File: FixedLengthRecordSorterTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testFlushPartialMemoryPage() throws Exception { // Insert IntPair which would fill 2 memory pages. final int NUM_RECORDS = 2 * MEMORY_PAGE_SIZE / 8; final List<MemorySegment> memory = this.memoryManager.allocatePages(new DummyInvokable(), 3); FixedLengthRecordSorter<IntPair> sorter = newSortBuffer(memory); UniformIntPairGenerator generator = new UniformIntPairGenerator(Integer.MAX_VALUE, 1, false); // write the records IntPair record = new IntPair(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record) && num < NUM_RECORDS); FileIOChannel.ID channelID = this.ioManager.createChannelEnumerator().next(); BlockChannelWriter<MemorySegment> blockChannelWriter = this.ioManager.createBlockChannelWriter(channelID); final List<MemorySegment> writeBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelWriterOutputView outputView = new ChannelWriterOutputView(blockChannelWriter, writeBuffer, writeBuffer.get(0).size()); sorter.writeToOutput(outputView, 1, NUM_RECORDS - 1); this.memoryManager.release(outputView.close()); BlockChannelReader<MemorySegment> blockChannelReader = this.ioManager.createBlockChannelReader(channelID); final List<MemorySegment> readBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelReaderInputView readerInputView = new ChannelReaderInputView(blockChannelReader, readBuffer, false); final List<MemorySegment> dataBuffer = this.memoryManager.allocatePages(new DummyInvokable(), 3); ChannelReaderInputViewIterator<IntPair> iterator = new ChannelReaderInputViewIterator(readerInputView, dataBuffer, this.serializer); record = iterator.next(record); int i =1; while (record != null) { Assert.assertEquals(i, record.getKey()); record = iterator.next(record); i++; } Assert.assertEquals(NUM_RECORDS, i); this.memoryManager.release(dataBuffer); // release the memory occupied by the buffers sorter.dispose(); this.memoryManager.release(memory); }