Search in sources :

Example 1 with StreamTestSingleInputGate

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

the class StreamTaskNetworkInputTest method testInputStatusAfterEndOfRecovery.

@Test
public void testInputStatusAfterEndOfRecovery() throws Exception {
    int numInputChannels = 2;
    LongSerializer inSerializer = LongSerializer.INSTANCE;
    StreamTestSingleInputGate<Long> inputGate = new StreamTestSingleInputGate<>(numInputChannels, 0, inSerializer, 1024);
    DataOutput<Long> output = new NoOpDataOutput<>();
    Map<InputChannelInfo, TestRecordDeserializer> deserializers = createDeserializers(inputGate.getInputGate());
    StreamTaskInput<Long> input = new TestStreamTaskNetworkInput(inputGate, inSerializer, numInputChannels, deserializers);
    inputGate.sendElement(new StreamRecord<>(42L), 0);
    assertThat(input.emitNext(output), equalTo(DataInputStatus.MORE_AVAILABLE));
    inputGate.sendEvent(EndOfChannelStateEvent.INSTANCE, 0);
    assertThat(input.emitNext(output), equalTo(DataInputStatus.MORE_AVAILABLE));
    inputGate.sendEvent(EndOfChannelStateEvent.INSTANCE, 1);
    assertThat(input.emitNext(output), equalTo(DataInputStatus.END_OF_RECOVERY));
}
Also used : LongSerializer(org.apache.flink.api.common.typeutils.base.LongSerializer) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) StreamTestSingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.StreamTestSingleInputGate) Test(org.junit.Test)

Example 2 with StreamTestSingleInputGate

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

the class TwoInputStreamTaskTestHarness method initializeInputs.

@Override
protected void initializeInputs() {
    inputGates = new StreamTestSingleInputGate[numInputGates];
    List<StreamEdge> inPhysicalEdges = new LinkedList<>();
    StreamOperator<IN1> dummyOperator = new AbstractStreamOperator<IN1>() {

        private static final long serialVersionUID = 1L;
    };
    StreamNode sourceVertexDummy = new StreamNode(0, "default group", null, dummyOperator, "source dummy", SourceStreamTask.class);
    StreamNode targetVertexDummy = new StreamNode(1, "default group", null, dummyOperator, "target dummy", SourceStreamTask.class);
    for (int i = 0; i < numInputGates; i++) {
        switch(inputGateAssignment[i]) {
            case 1:
                {
                    inputGates[i] = new StreamTestSingleInputGate<>(numInputChannelsPerGate, i, inputSerializer1, bufferSize);
                    StreamEdge streamEdge = new StreamEdge(sourceVertexDummy, targetVertexDummy, 1, new BroadcastPartitioner<>(), null);
                    inPhysicalEdges.add(streamEdge);
                    break;
                }
            case 2:
                {
                    inputGates[i] = new StreamTestSingleInputGate<>(numInputChannelsPerGate, i, inputSerializer2, bufferSize);
                    StreamEdge streamEdge = new StreamEdge(sourceVertexDummy, targetVertexDummy, 2, new BroadcastPartitioner<>(), null);
                    inPhysicalEdges.add(streamEdge);
                    break;
                }
            default:
                throw new IllegalStateException("Wrong input gate assignment.");
        }
        this.mockEnv.addInputGate(inputGates[i].getInputGate());
    }
    streamConfig.setInPhysicalEdges(inPhysicalEdges);
    streamConfig.setNumberOfNetworkInputs(numInputGates);
    streamConfig.setupNetworkInputs(inputSerializer1, inputSerializer2);
}
Also used : StreamEdge(org.apache.flink.streaming.api.graph.StreamEdge) StreamTestSingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.StreamTestSingleInputGate) StreamNode(org.apache.flink.streaming.api.graph.StreamNode) AbstractStreamOperator(org.apache.flink.streaming.api.operators.AbstractStreamOperator) LinkedList(java.util.LinkedList) BroadcastPartitioner(org.apache.flink.streaming.runtime.partitioner.BroadcastPartitioner)

Example 3 with StreamTestSingleInputGate

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

the class StreamTaskNetworkInputTest method testSnapshotAfterEndOfPartition.

@Test
public void testSnapshotAfterEndOfPartition() throws Exception {
    int numInputChannels = 1;
    int channelId = 0;
    int checkpointId = 0;
    VerifyRecordsDataOutput<Long> output = new VerifyRecordsDataOutput<>();
    LongSerializer inSerializer = LongSerializer.INSTANCE;
    StreamTestSingleInputGate<Long> inputGate = new StreamTestSingleInputGate<>(numInputChannels, 0, inSerializer, 1024);
    StreamTaskInput<Long> input = new StreamTaskNetworkInput<>(new CheckpointedInputGate(inputGate.getInputGate(), SingleCheckpointBarrierHandler.createUnalignedCheckpointBarrierHandler(TestSubtaskCheckpointCoordinator.INSTANCE, "test", new DummyCheckpointInvokable(), SystemClock.getInstance(), false, inputGate.getInputGate()), new SyncMailboxExecutor()), inSerializer, ioManager, new StatusWatermarkValve(numInputChannels), 0);
    inputGate.sendEvent(new CheckpointBarrier(checkpointId, 0L, CheckpointOptions.forCheckpointWithDefaultLocation().toUnaligned()), channelId);
    inputGate.sendElement(new StreamRecord<>(42L), channelId);
    assertHasNextElement(input, output);
    assertHasNextElement(input, output);
    assertEquals(1, output.getNumberOfEmittedRecords());
    // send EndOfPartitionEvent and ensure that deserializer has been released
    inputGate.sendEvent(EndOfPartitionEvent.INSTANCE, channelId);
    input.emitNext(output);
    // now snapshot all inflight buffers
    CompletableFuture<Void> completableFuture = input.prepareSnapshot(ChannelStateWriter.NO_OP, checkpointId);
    completableFuture.join();
}
Also used : LongSerializer(org.apache.flink.api.common.typeutils.base.LongSerializer) SyncMailboxExecutor(org.apache.flink.runtime.mailbox.SyncMailboxExecutor) StreamTestSingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.StreamTestSingleInputGate) StatusWatermarkValve(org.apache.flink.streaming.runtime.watermarkstatus.StatusWatermarkValve) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) DummyCheckpointInvokable(org.apache.flink.runtime.operators.testutils.DummyCheckpointInvokable) CheckpointedInputGate(org.apache.flink.streaming.runtime.io.checkpointing.CheckpointedInputGate) Test(org.junit.Test)

Example 4 with StreamTestSingleInputGate

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

the class StreamTaskNetworkInputTest method testReleasingDeserializerTimely.

@Test
public void testReleasingDeserializerTimely() throws Exception {
    int numInputChannels = 2;
    LongSerializer inSerializer = LongSerializer.INSTANCE;
    StreamTestSingleInputGate<Long> inputGate = new StreamTestSingleInputGate<>(numInputChannels, 0, inSerializer, 1024);
    DataOutput<Long> output = new NoOpDataOutput<>();
    Map<InputChannelInfo, TestRecordDeserializer> deserializers = createDeserializers(inputGate.getInputGate());
    Map<InputChannelInfo, TestRecordDeserializer> copiedDeserializers = new HashMap<>(deserializers);
    StreamTaskInput<Long> input = new TestStreamTaskNetworkInput(inputGate, inSerializer, numInputChannels, deserializers);
    for (InputChannelInfo channelInfo : inputGate.getInputGate().getChannelInfos()) {
        assertNotNull(deserializers.get(channelInfo));
        inputGate.sendEvent(EndOfPartitionEvent.INSTANCE, channelInfo.getInputChannelIdx());
        input.emitNext(output);
        assertTrue(copiedDeserializers.get(channelInfo).isCleared());
        assertNull(deserializers.get(channelInfo));
    }
}
Also used : LongSerializer(org.apache.flink.api.common.typeutils.base.LongSerializer) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) HashMap(java.util.HashMap) StreamTestSingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.StreamTestSingleInputGate) Test(org.junit.Test)

Aggregations

StreamTestSingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.StreamTestSingleInputGate)4 LongSerializer (org.apache.flink.api.common.typeutils.base.LongSerializer)3 Test (org.junit.Test)3 InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)1 SyncMailboxExecutor (org.apache.flink.runtime.mailbox.SyncMailboxExecutor)1 DummyCheckpointInvokable (org.apache.flink.runtime.operators.testutils.DummyCheckpointInvokable)1 StreamEdge (org.apache.flink.streaming.api.graph.StreamEdge)1 StreamNode (org.apache.flink.streaming.api.graph.StreamNode)1 AbstractStreamOperator (org.apache.flink.streaming.api.operators.AbstractStreamOperator)1 CheckpointedInputGate (org.apache.flink.streaming.runtime.io.checkpointing.CheckpointedInputGate)1 BroadcastPartitioner (org.apache.flink.streaming.runtime.partitioner.BroadcastPartitioner)1 StatusWatermarkValve (org.apache.flink.streaming.runtime.watermarkstatus.StatusWatermarkValve)1