use of org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder in project flink by apache.
the class ResultSubpartitionRecoveredStateHandlerTest method setUp.
@Before
public void setUp() throws IOException {
// given: Segment provider with defined number of allocated segments.
channelInfo = new ResultSubpartitionInfo(0, 0);
networkBufferPool = new NetworkBufferPool(preAllocatedSegments, 1024);
partition = new ResultPartitionBuilder().setNetworkBufferPool(networkBufferPool).build();
partition.setup();
rstHandler = buildResultStateHandler(partition);
}
use of org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder in project flink by apache.
the class SequentialChannelStateReaderImplTest method withResultPartitions.
private void withResultPartitions(ThrowingConsumer<BufferWritingResultPartition[], Exception> action) throws Exception {
int segmentsToAllocate = parLevel * parLevel * buffersPerChannel;
NetworkBufferPool networkBufferPool = new NetworkBufferPool(segmentsToAllocate, bufferSize);
BufferWritingResultPartition[] resultPartitions = range(0, parLevel).mapToObj(i -> new ResultPartitionBuilder().setResultPartitionIndex(i).setNumberOfSubpartitions(parLevel).setNetworkBufferPool(networkBufferPool).build()).toArray(BufferWritingResultPartition[]::new);
try {
for (ResultPartition resultPartition : resultPartitions) {
resultPartition.setup();
}
action.accept(resultPartitions);
} finally {
for (ResultPartition resultPartition : resultPartitions) {
resultPartition.close();
}
try {
assertEquals(segmentsToAllocate, networkBufferPool.getNumberOfAvailableMemorySegments());
} finally {
networkBufferPool.destroyAllBufferPools();
networkBufferPool.destroy();
}
}
}
use of org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder in project flink by apache.
the class SingleInputGateTest method testQueuedBuffers.
@Test
public void testQueuedBuffers() throws Exception {
final NettyShuffleEnvironment network = createNettyShuffleEnvironment();
final BufferWritingResultPartition resultPartition = (BufferWritingResultPartition) new ResultPartitionBuilder().setResultPartitionManager(network.getResultPartitionManager()).setupBufferPoolFactoryFromNettyShuffleEnvironment(network).build();
final SingleInputGate inputGate = createInputGate(network, 2, ResultPartitionType.PIPELINED);
final ResultPartitionID localResultPartitionId = resultPartition.getPartitionId();
final InputChannel[] inputChannels = new InputChannel[2];
final RemoteInputChannel remoteInputChannel = InputChannelBuilder.newBuilder().setChannelIndex(1).setupFromNettyShuffleEnvironment(network).setConnectionManager(new TestingConnectionManager()).buildRemoteChannel(inputGate);
inputChannels[0] = remoteInputChannel;
inputChannels[1] = InputChannelBuilder.newBuilder().setChannelIndex(0).setPartitionId(localResultPartitionId).setupFromNettyShuffleEnvironment(network).setConnectionManager(new TestingConnectionManager()).buildLocalChannel(inputGate);
try (Closer closer = Closer.create()) {
closer.register(network::close);
closer.register(inputGate::close);
closer.register(resultPartition::release);
resultPartition.setup();
setupInputGate(inputGate, inputChannels);
remoteInputChannel.onBuffer(createBuffer(1), 0, 0);
assertEquals(1, inputGate.getNumberOfQueuedBuffers());
resultPartition.emitRecord(ByteBuffer.allocate(1), 0);
assertEquals(2, inputGate.getNumberOfQueuedBuffers());
}
}
use of org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder in project flink by apache.
the class RecordWriterDelegateTest method createRecordWriter.
private RecordWriter createRecordWriter(NetworkBufferPool globalPool) throws Exception {
final BufferPool localPool = globalPool.createBufferPool(1, 1, 1, Integer.MAX_VALUE);
final ResultPartitionWriter partition = new ResultPartitionBuilder().setBufferPoolFactory(() -> localPool).build();
partition.setup();
return new RecordWriterBuilder().build(partition);
}
use of org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder in project flink by apache.
the class RecordWriterTest method testIsAvailableOrNot.
/**
* Tests that the RecordWriter is available iif the respective LocalBufferPool has at-least one
* available buffer.
*/
@Test
public void testIsAvailableOrNot() throws Exception {
// setup
final NetworkBufferPool globalPool = new NetworkBufferPool(10, 128);
final BufferPool localPool = globalPool.createBufferPool(1, 1, 1, Integer.MAX_VALUE);
final ResultPartitionWriter resultPartition = new ResultPartitionBuilder().setBufferPoolFactory(() -> localPool).build();
resultPartition.setup();
final RecordWriter<?> recordWriter = createRecordWriter(resultPartition);
try {
// record writer is available because of initial available global pool
assertTrue(recordWriter.getAvailableFuture().isDone());
// request one buffer from the local pool to make it unavailable afterwards
try (BufferBuilder bufferBuilder = localPool.requestBufferBuilder(0)) {
assertNotNull(bufferBuilder);
assertFalse(recordWriter.getAvailableFuture().isDone());
// recycle the buffer to make the local pool available again
final Buffer buffer = BufferBuilderTestUtils.buildSingleBuffer(bufferBuilder);
buffer.recycleBuffer();
}
assertTrue(recordWriter.getAvailableFuture().isDone());
assertEquals(recordWriter.AVAILABLE, recordWriter.getAvailableFuture());
} finally {
localPool.lazyDestroy();
globalPool.destroy();
}
}
Aggregations