Search in sources :

Example 6 with BufferWritingResultPartition

use of org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition in project flink by apache.

the class ChannelPersistenceITCase method testReadWritten.

@Test
public void testReadWritten() throws Exception {
    byte[] inputChannelInfoData = randomBytes(1024);
    byte[] resultSubpartitionInfoData = randomBytes(1024);
    int partitionIndex = 0;
    SequentialChannelStateReader reader = new SequentialChannelStateReaderImpl(toTaskStateSnapshot(write(1L, singletonMap(new InputChannelInfo(0, 0), inputChannelInfoData), singletonMap(new ResultSubpartitionInfo(partitionIndex, 0), resultSubpartitionInfoData))));
    NetworkBufferPool networkBufferPool = new NetworkBufferPool(4, 1024);
    try {
        int numChannels = 1;
        InputGate gate = buildGate(networkBufferPool, numChannels);
        reader.readInputData(new InputGate[] { gate });
        assertArrayEquals(inputChannelInfoData, collectBytes(gate::pollNext, BufferOrEvent::getBuffer));
        BufferWritingResultPartition resultPartition = buildResultPartition(networkBufferPool, ResultPartitionType.PIPELINED, partitionIndex, numChannels);
        reader.readOutputData(new BufferWritingResultPartition[] { resultPartition }, false);
        ResultSubpartitionView view = resultPartition.createSubpartitionView(0, new NoOpBufferAvailablityListener());
        assertArrayEquals(resultSubpartitionInfoData, collectBytes(() -> Optional.ofNullable(view.getNextBuffer()), BufferAndBacklog::buffer));
    } finally {
        networkBufferPool.destroy();
    }
}
Also used : InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) BufferWritingResultPartition(org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) SequentialChannelStateReaderImpl(org.apache.flink.runtime.checkpoint.channel.SequentialChannelStateReaderImpl) ResultSubpartitionInfo(org.apache.flink.runtime.checkpoint.channel.ResultSubpartitionInfo) SequentialChannelStateReader(org.apache.flink.runtime.checkpoint.channel.SequentialChannelStateReader) NoOpBufferAvailablityListener(org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) InputGate(org.apache.flink.runtime.io.network.partition.consumer.InputGate) Test(org.junit.Test)

Example 7 with BufferWritingResultPartition

use of org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition in project flink by apache.

the class ChannelPersistenceITCase method buildResultPartition.

private BufferWritingResultPartition buildResultPartition(NetworkBufferPool networkBufferPool, ResultPartitionType resultPartitionType, int index, int numberOfSubpartitions) throws IOException {
    ResultPartition resultPartition = new ResultPartitionBuilder().setResultPartitionIndex(index).setResultPartitionType(resultPartitionType).setNumberOfSubpartitions(numberOfSubpartitions).setBufferPoolFactory(() -> networkBufferPool.createBufferPool(numberOfSubpartitions, Integer.MAX_VALUE, numberOfSubpartitions, Integer.MAX_VALUE)).build();
    resultPartition.setup();
    return (BufferWritingResultPartition) resultPartition;
}
Also used : BufferWritingResultPartition(org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition) ResultPartitionBuilder(org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) BufferWritingResultPartition(org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition)

Aggregations

BufferWritingResultPartition (org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition)7 NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)5 ResultPartitionBuilder (org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder)5 Test (org.junit.Test)5 NoOpBufferAvailablityListener (org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener)4 ResultPartition (org.apache.flink.runtime.io.network.partition.ResultPartition)4 ResultSubpartitionView (org.apache.flink.runtime.io.network.partition.ResultSubpartitionView)4 TaskStateSnapshot (org.apache.flink.runtime.checkpoint.TaskStateSnapshot)3 InputGate (org.apache.flink.runtime.io.network.partition.consumer.InputGate)3 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)3 Closer (org.apache.flink.shaded.guava30.com.google.common.io.Closer)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2