Java Code Examples for org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter#addBufferConsumer()
The following examples show how to use
org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter#addBufferConsumer() .
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: ResultPartitionTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests {@link ResultPartition#addBufferConsumer(BufferConsumer, int)} on a working partition. * * @param partitionType the result partition type to set up */ private void testAddOnPartition(final ResultPartitionType partitionType) throws Exception { ResultPartitionConsumableNotifier notifier = mock(ResultPartitionConsumableNotifier.class); JobID jobId = new JobID(); TaskActions taskActions = new NoOpTaskActions(); ResultPartitionWriter consumableNotifyingPartitionWriter = createConsumableNotifyingResultPartitionWriter( partitionType, taskActions, jobId, notifier); BufferConsumer bufferConsumer = createFilledBufferConsumer(BufferBuilderTestUtils.BUFFER_SIZE); try { // partition.add() adds the bufferConsumer without recycling it (if not spilling) consumableNotifyingPartitionWriter.addBufferConsumer(bufferConsumer, 0); assertFalse("bufferConsumer should not be recycled (still in the queue)", bufferConsumer.isRecycled()); } finally { if (!bufferConsumer.isRecycled()) { bufferConsumer.close(); } // should have been notified for pipelined partitions if (partitionType.isPipelined()) { verify(notifier, times(1)) .notifyPartitionConsumable(eq(jobId), eq(consumableNotifyingPartitionWriter.getPartitionId()), eq(taskActions)); } } }
Example 2
Source File: ResultPartitionTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests {@link ResultPartition#addBufferConsumer(BufferConsumer, int)} on a working partition. * * @param partitionType the result partition type to set up */ private void testAddOnPartition(final ResultPartitionType partitionType) throws Exception { ResultPartitionConsumableNotifier notifier = mock(ResultPartitionConsumableNotifier.class); JobID jobId = new JobID(); TaskActions taskActions = new NoOpTaskActions(); ResultPartitionWriter consumableNotifyingPartitionWriter = createConsumableNotifyingResultPartitionWriter( partitionType, taskActions, jobId, notifier); BufferConsumer bufferConsumer = createFilledFinishedBufferConsumer(BufferBuilderTestUtils.BUFFER_SIZE); try { // partition.add() adds the bufferConsumer without recycling it (if not spilling) consumableNotifyingPartitionWriter.addBufferConsumer(bufferConsumer, 0); assertFalse("bufferConsumer should not be recycled (still in the queue)", bufferConsumer.isRecycled()); } finally { if (!bufferConsumer.isRecycled()) { bufferConsumer.close(); } // should have been notified for pipelined partitions if (partitionType.isPipelined()) { verify(notifier, times(1)) .notifyPartitionConsumable(eq(jobId), eq(consumableNotifyingPartitionWriter.getPartitionId()), eq(taskActions)); } } }
Example 3
Source File: PartialConsumePipelinedResultTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public void invoke() throws Exception { final ResultPartitionWriter writer = getEnvironment().getWriter(0); for (int i = 0; i < 8; i++) { final BufferBuilder bufferBuilder = writer.getBufferProvider().requestBufferBuilderBlocking(); writer.addBufferConsumer(bufferBuilder.createBufferConsumer(), 0); Thread.sleep(50); bufferBuilder.finish(); } }
Example 4
Source File: ResultPartitionTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests {@link ResultPartition#addBufferConsumer} on a partition which has already finished. * * @param partitionType the result partition type to set up */ private void testAddOnFinishedPartition(final ResultPartitionType partitionType) throws Exception { BufferConsumer bufferConsumer = createFilledBufferConsumer(BufferBuilderTestUtils.BUFFER_SIZE); ResultPartitionConsumableNotifier notifier = mock(ResultPartitionConsumableNotifier.class); JobID jobId = new JobID(); TaskActions taskActions = new NoOpTaskActions(); ResultPartitionWriter consumableNotifyingPartitionWriter = createConsumableNotifyingResultPartitionWriter( partitionType, taskActions, jobId, notifier); try { consumableNotifyingPartitionWriter.finish(); reset(notifier); // partition.add() should fail consumableNotifyingPartitionWriter.addBufferConsumer(bufferConsumer, 0); Assert.fail("exception expected"); } catch (IllegalStateException e) { // expected => ignored } finally { if (!bufferConsumer.isRecycled()) { bufferConsumer.close(); Assert.fail("bufferConsumer not recycled"); } // should not have notified either verify(notifier, never()).notifyPartitionConsumable( eq(jobId), eq(consumableNotifyingPartitionWriter.getPartitionId()), eq(taskActions)); } }
Example 5
Source File: ResultPartitionTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests {@link ResultPartition#addBufferConsumer} on a partition which has already been released. * * @param partitionType the result partition type to set up */ private void testAddOnReleasedPartition(final ResultPartitionType partitionType) throws Exception { BufferConsumer bufferConsumer = createFilledBufferConsumer(BufferBuilderTestUtils.BUFFER_SIZE); ResultPartitionConsumableNotifier notifier = mock(ResultPartitionConsumableNotifier.class); JobID jobId = new JobID(); TaskActions taskActions = new NoOpTaskActions(); ResultPartition partition = partitionType == ResultPartitionType.BLOCKING ? createPartition(partitionType, fileChannelManager) : createPartition(partitionType); ResultPartitionWriter consumableNotifyingPartitionWriter = ConsumableNotifyingResultPartitionWriterDecorator.decorate( Collections.singleton(PartitionTestUtils.createPartitionDeploymentDescriptor(partitionType)), new ResultPartitionWriter[] {partition}, taskActions, jobId, notifier)[0]; try { partition.release(); // partition.add() silently drops the bufferConsumer but recycles it consumableNotifyingPartitionWriter.addBufferConsumer(bufferConsumer, 0); assertTrue(partition.isReleased()); } finally { if (!bufferConsumer.isRecycled()) { bufferConsumer.close(); Assert.fail("bufferConsumer not recycled"); } // should not have notified either verify(notifier, never()).notifyPartitionConsumable(eq(jobId), eq(partition.getPartitionId()), eq(taskActions)); } }
Example 6
Source File: PartialConsumePipelinedResultTest.java From flink with Apache License 2.0 | 5 votes |
@Override public void invoke() throws Exception { final ResultPartitionWriter writer = getEnvironment().getWriter(0); for (int i = 0; i < 8; i++) { final BufferBuilder bufferBuilder = writer.getBufferBuilder(); writer.addBufferConsumer(bufferBuilder.createBufferConsumer(), 0); Thread.sleep(50); bufferBuilder.finish(); } }
Example 7
Source File: ResultPartitionTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests {@link ResultPartition#addBufferConsumer} on a partition which has already finished. * * @param partitionType the result partition type to set up */ private void testAddOnFinishedPartition(final ResultPartitionType partitionType) throws Exception { BufferConsumer bufferConsumer = createFilledFinishedBufferConsumer(BufferBuilderTestUtils.BUFFER_SIZE); ResultPartitionConsumableNotifier notifier = mock(ResultPartitionConsumableNotifier.class); JobID jobId = new JobID(); TaskActions taskActions = new NoOpTaskActions(); ResultPartitionWriter consumableNotifyingPartitionWriter = createConsumableNotifyingResultPartitionWriter( partitionType, taskActions, jobId, notifier); try { consumableNotifyingPartitionWriter.finish(); reset(notifier); // partition.add() should fail consumableNotifyingPartitionWriter.addBufferConsumer(bufferConsumer, 0); Assert.fail("exception expected"); } catch (IllegalStateException e) { // expected => ignored } finally { if (!bufferConsumer.isRecycled()) { bufferConsumer.close(); Assert.fail("bufferConsumer not recycled"); } // should not have notified either verify(notifier, never()).notifyPartitionConsumable( eq(jobId), eq(consumableNotifyingPartitionWriter.getPartitionId()), eq(taskActions)); } }
Example 8
Source File: ResultPartitionTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests {@link ResultPartition#addBufferConsumer} on a partition which has already been released. * * @param partitionType the result partition type to set up */ private void testAddOnReleasedPartition(final ResultPartitionType partitionType) throws Exception { BufferConsumer bufferConsumer = createFilledFinishedBufferConsumer(BufferBuilderTestUtils.BUFFER_SIZE); ResultPartitionConsumableNotifier notifier = mock(ResultPartitionConsumableNotifier.class); JobID jobId = new JobID(); TaskActions taskActions = new NoOpTaskActions(); ResultPartition partition = partitionType == ResultPartitionType.BLOCKING ? createPartition(partitionType, fileChannelManager) : createPartition(partitionType); ResultPartitionWriter consumableNotifyingPartitionWriter = ConsumableNotifyingResultPartitionWriterDecorator.decorate( Collections.singleton(PartitionTestUtils.createPartitionDeploymentDescriptor(partitionType)), new ResultPartitionWriter[] {partition}, taskActions, jobId, notifier)[0]; try { partition.release(); // partition.add() silently drops the bufferConsumer but recycles it consumableNotifyingPartitionWriter.addBufferConsumer(bufferConsumer, 0); assertTrue(partition.isReleased()); } finally { if (!bufferConsumer.isRecycled()) { bufferConsumer.close(); Assert.fail("bufferConsumer not recycled"); } // should not have notified either verify(notifier, never()).notifyPartitionConsumable(eq(jobId), eq(partition.getPartitionId()), eq(taskActions)); } }
Example 9
Source File: PartialConsumePipelinedResultTest.java From flink with Apache License 2.0 | 5 votes |
@Override public void invoke() throws Exception { final ResultPartitionWriter writer = getEnvironment().getWriter(0); for (int i = 0; i < 8; i++) { final BufferBuilder bufferBuilder = writer.getBufferBuilder(0); writer.addBufferConsumer(bufferBuilder.createBufferConsumer(), 0); Thread.sleep(50); bufferBuilder.finish(); } }