use of org.apache.flink.runtime.io.network.NettyShuffleEnvironment in project flink by apache.
the class SingleInputGateTest method testInputGateRemovalFromNettyShuffleEnvironment.
@Test
public void testInputGateRemovalFromNettyShuffleEnvironment() throws Exception {
NettyShuffleEnvironment network = createNettyShuffleEnvironment();
try (Closer closer = Closer.create()) {
closer.register(network::close);
int numberOfGates = 10;
Map<InputGateID, SingleInputGate> createdInputGatesById = createInputGateWithLocalChannels(network, numberOfGates, 1);
assertEquals(numberOfGates, createdInputGatesById.size());
for (InputGateID id : createdInputGatesById.keySet()) {
assertThat(network.getInputGate(id).isPresent(), is(true));
createdInputGatesById.get(id).close();
assertThat(network.getInputGate(id).isPresent(), is(false));
}
}
}
use of org.apache.flink.runtime.io.network.NettyShuffleEnvironment in project flink by apache.
the class SingleInputGateTest method testBackwardsEventWithUninitializedChannel.
@Test
public void testBackwardsEventWithUninitializedChannel() throws Exception {
// Setup environment
TestingTaskEventPublisher taskEventPublisher = new TestingTaskEventPublisher();
TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(new NoOpResultSubpartitionView());
// Setup reader with one local and one unknown input channel
NettyShuffleEnvironment environment = createNettyShuffleEnvironment();
final SingleInputGate inputGate = createInputGate(environment, 2, ResultPartitionType.PIPELINED);
final InputChannel[] inputChannels = new InputChannel[2];
try (Closer closer = Closer.create()) {
closer.register(environment::close);
closer.register(inputGate::close);
// Local
ResultPartitionID localPartitionId = new ResultPartitionID();
inputChannels[0] = InputChannelBuilder.newBuilder().setPartitionId(localPartitionId).setPartitionManager(partitionManager).setTaskEventPublisher(taskEventPublisher).buildLocalChannel(inputGate);
// Unknown
ResultPartitionID unknownPartitionId = new ResultPartitionID();
inputChannels[1] = InputChannelBuilder.newBuilder().setChannelIndex(1).setPartitionId(unknownPartitionId).setPartitionManager(partitionManager).setTaskEventPublisher(taskEventPublisher).buildUnknownChannel(inputGate);
setupInputGate(inputGate, inputChannels);
// Only the local channel can request
assertEquals(1, partitionManager.counter);
// Send event backwards and initialize unknown channel afterwards
final TaskEvent event = new TestTaskEvent();
inputGate.sendTaskEvent(event);
// Only the local channel can send out the event
assertEquals(1, taskEventPublisher.counter);
// After the update, the pending event should be send to local channel
ResourceID location = ResourceID.generate();
inputGate.updateInputChannel(location, createRemoteWithIdAndLocation(unknownPartitionId.getPartitionId(), location));
assertEquals(2, partitionManager.counter);
assertEquals(2, taskEventPublisher.counter);
}
}
use of org.apache.flink.runtime.io.network.NettyShuffleEnvironment in project flink by apache.
the class SingleInputGateTest method testSingleInputGateWithSubpartitionIndexRange.
@Test
public void testSingleInputGateWithSubpartitionIndexRange() throws IOException, InterruptedException {
IntermediateResultPartitionID[] partitionIds = new IntermediateResultPartitionID[] { new IntermediateResultPartitionID(), new IntermediateResultPartitionID(), new IntermediateResultPartitionID() };
SubpartitionIndexRange subpartitionIndexRange = new SubpartitionIndexRange(0, 1);
final NettyShuffleEnvironment netEnv = new NettyShuffleEnvironmentBuilder().build();
ResourceID localLocation = ResourceID.generate();
SingleInputGate gate = createSingleInputGate(partitionIds, ResultPartitionType.BLOCKING, subpartitionIndexRange, netEnv, localLocation, new TestingConnectionManager(), new TestingResultPartitionManager(new NoOpResultSubpartitionView()));
for (InputChannel channel : gate.getInputChannels().values()) {
if (channel instanceof ChannelStateHolder) {
((ChannelStateHolder) channel).setChannelStateWriter(ChannelStateWriter.NO_OP);
}
}
SubpartitionInfo info1 = createSubpartitionInfo(partitionIds[0], 0);
SubpartitionInfo info2 = createSubpartitionInfo(partitionIds[0], 1);
SubpartitionInfo info3 = createSubpartitionInfo(partitionIds[1], 0);
SubpartitionInfo info4 = createSubpartitionInfo(partitionIds[1], 1);
SubpartitionInfo info5 = createSubpartitionInfo(partitionIds[2], 0);
SubpartitionInfo info6 = createSubpartitionInfo(partitionIds[2], 1);
assertThat(gate.getInputChannels().size(), is(6));
assertThat(gate.getInputChannels().get(info1).getConsumedSubpartitionIndex(), is(0));
assertThat(gate.getInputChannels().get(info2).getConsumedSubpartitionIndex(), is(1));
assertThat(gate.getInputChannels().get(info3).getConsumedSubpartitionIndex(), is(0));
assertThat(gate.getInputChannels().get(info4).getConsumedSubpartitionIndex(), is(1));
assertThat(gate.getInputChannels().get(info5).getConsumedSubpartitionIndex(), is(0));
assertThat(gate.getInputChannels().get(info6).getConsumedSubpartitionIndex(), is(1));
assertChannelsType(gate, LocalRecoveredInputChannel.class, Arrays.asList(info1, info2));
assertChannelsType(gate, RemoteRecoveredInputChannel.class, Arrays.asList(info3, info4));
assertChannelsType(gate, UnknownInputChannel.class, Arrays.asList(info5, info6));
// test setup
gate.setup();
assertNotNull(gate.getBufferPool());
assertEquals(1, gate.getBufferPool().getNumberOfRequiredMemorySegments());
gate.finishReadRecoveredState();
while (!gate.getStateConsumedFuture().isDone()) {
gate.pollNext();
}
// test request partitions
gate.requestPartitions();
gate.pollNext();
assertChannelsType(gate, LocalInputChannel.class, Arrays.asList(info1, info2));
assertChannelsType(gate, RemoteInputChannel.class, Arrays.asList(info3, info4));
assertChannelsType(gate, UnknownInputChannel.class, Arrays.asList(info5, info6));
for (InputChannel inputChannel : gate.getInputChannels().values()) {
if (inputChannel instanceof RemoteInputChannel) {
assertNotNull(((RemoteInputChannel) inputChannel).getPartitionRequestClient());
assertEquals(2, ((RemoteInputChannel) inputChannel).getInitialCredit());
} else if (inputChannel instanceof LocalInputChannel) {
assertNotNull(((LocalInputChannel) inputChannel).getSubpartitionView());
}
}
// test update channels
gate.updateInputChannel(localLocation, createRemoteWithIdAndLocation(partitionIds[2], localLocation));
assertChannelsType(gate, LocalInputChannel.class, Arrays.asList(info1, info2));
assertChannelsType(gate, RemoteInputChannel.class, Arrays.asList(info3, info4));
assertChannelsType(gate, LocalInputChannel.class, Arrays.asList(info5, info6));
}
use of org.apache.flink.runtime.io.network.NettyShuffleEnvironment 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.NettyShuffleEnvironment in project flink by apache.
the class PartitionRequestQueueTest method createResultPartition.
private static ResultPartition createResultPartition() throws IOException {
NettyShuffleEnvironment network = new NettyShuffleEnvironmentBuilder().setNumNetworkBuffers(10).setBufferSize(BUFFER_SIZE).build();
ResultPartition resultPartition = createPartition(network, NoOpFileChannelManager.INSTANCE, ResultPartitionType.PIPELINED, 2);
resultPartition.setup();
return resultPartition;
}
Aggregations