Search in sources :

Example 21 with StreamElement

use of org.apache.flink.streaming.runtime.streamrecord.StreamElement in project flink by apache.

the class DemultiplexingRecordDeserializerTest method write.

private Buffer write(BufferBuilder bufferBuilder, StreamElement... elements) throws IOException {
    try (BufferConsumer bufferConsumer = bufferBuilder.createBufferConsumer()) {
        DataOutputSerializer output = new DataOutputSerializer(128);
        final SerializationDelegate<StreamElement> delegate = new SerializationDelegate<>(new StreamElementSerializer<>(LongSerializer.INSTANCE));
        for (StreamElement element : elements) {
            delegate.setInstance(element);
            bufferBuilder.appendAndCommit(RecordWriter.serializeRecord(output, delegate));
        }
        return bufferConsumer.build();
    }
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) SerializationDelegate(org.apache.flink.runtime.plugable.SerializationDelegate) BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer)

Example 22 with StreamElement

use of org.apache.flink.streaming.runtime.streamrecord.StreamElement in project flink by apache.

the class CommitterOperatorTest method testStateRestore.

@Test
void testStateRestore() throws Exception {
    final OneInputStreamOperatorTestHarness<CommittableMessage<String>, CommittableMessage<String>> testHarness = createTestHarness(new TestSink.RetryOnceCommitter());
    testHarness.open();
    final CommittableSummary<String> committableSummary = new CommittableSummary<>(1, 1, 0L, 1, 1, 0);
    testHarness.processElement(new StreamRecord<>(committableSummary));
    final CommittableWithLineage<String> first = new CommittableWithLineage<>("1", 0L, 1);
    testHarness.processElement(new StreamRecord<>(first));
    final OperatorSubtaskState snapshot = testHarness.snapshot(0L, 2L);
    // Trigger first checkpoint but committer needs retry
    testHarness.notifyOfCompletedCheckpoint(0);
    assertThat(testHarness.getOutput()).isEmpty();
    testHarness.close();
    final ForwardingCommitter committer = new ForwardingCommitter();
    final OneInputStreamOperatorTestHarness<CommittableMessage<String>, CommittableMessage<String>> restored = createTestHarness(committer);
    restored.initializeState(snapshot);
    restored.open();
    // Previous committables are immediately committed if possible
    final List<StreamElement> output = fromOutput(restored.getOutput());
    assertThat(output).hasSize(2);
    assertThat(committer.getSuccessfulCommits()).isEqualTo(1);
    SinkV2Assertions.assertThat(toCommittableSummary(output.get(0))).hasFailedCommittables(committableSummary.getNumberOfFailedCommittables()).hasOverallCommittables(committableSummary.getNumberOfCommittables()).hasPendingCommittables(0);
    SinkV2Assertions.assertThat(toCommittableWithLinage(output.get(1))).isEqualTo(new CommittableWithLineage<>(first.getCommittable(), 1L, 0));
    restored.close();
}
Also used : CommittableMessage(org.apache.flink.streaming.api.connector.sink2.CommittableMessage) CommittableSummary(org.apache.flink.streaming.api.connector.sink2.CommittableSummary) SinkTestUtil.toCommittableSummary(org.apache.flink.streaming.runtime.operators.sink.SinkTestUtil.toCommittableSummary) CommittableWithLineage(org.apache.flink.streaming.api.connector.sink2.CommittableWithLineage) StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with StreamElement

use of org.apache.flink.streaming.runtime.streamrecord.StreamElement in project flink by apache.

the class AsyncWaitOperator method snapshotState.

@Override
public void snapshotState(StateSnapshotContext context) throws Exception {
    super.snapshotState(context);
    ListState<StreamElement> partitionableState = getOperatorStateBackend().getListState(new ListStateDescriptor<>(STATE_NAME, inStreamElementSerializer));
    partitionableState.clear();
    try {
        partitionableState.addAll(queue.values());
    } catch (Exception e) {
        partitionableState.clear();
        throw new Exception("Could not add stream element queue entries to operator state " + "backend of operator " + getOperatorName() + '.', e);
    }
}
Also used : StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 24 with StreamElement

use of org.apache.flink.streaming.runtime.streamrecord.StreamElement in project flink by apache.

the class OrderedStreamElementQueueTest method testCompletionOrder.

/**
 * Tests that only the head element is pulled from the ordered queue if it has been completed.
 */
@Test
public void testCompletionOrder() {
    final OrderedStreamElementQueue<Integer> queue = new OrderedStreamElementQueue<>(4);
    ResultFuture<Integer> entry1 = putSuccessfully(queue, new StreamRecord<>(1, 0L));
    ResultFuture<Integer> entry2 = putSuccessfully(queue, new StreamRecord<>(2, 1L));
    putSuccessfully(queue, new Watermark(2L));
    ResultFuture<Integer> entry4 = putSuccessfully(queue, new StreamRecord<>(3, 3L));
    Assert.assertEquals(Collections.emptyList(), popCompleted(queue));
    Assert.assertEquals(4, queue.size());
    Assert.assertFalse(queue.isEmpty());
    entry2.complete(Collections.singleton(11));
    entry4.complete(Collections.singleton(13));
    Assert.assertEquals(Collections.emptyList(), popCompleted(queue));
    Assert.assertEquals(4, queue.size());
    Assert.assertFalse(queue.isEmpty());
    entry1.complete(Collections.singleton(10));
    List<StreamElement> expected = Arrays.asList(new StreamRecord<>(10, 0L), new StreamRecord<>(11, 1L), new Watermark(2L), new StreamRecord<>(13, 3L));
    Assert.assertEquals(expected, popCompleted(queue));
    Assert.assertEquals(0, queue.size());
    Assert.assertTrue(queue.isEmpty());
}
Also used : StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Test(org.junit.Test)

Example 25 with StreamElement

use of org.apache.flink.streaming.runtime.streamrecord.StreamElement in project flink by apache.

the class BatchMultipleInputStreamOperatorTest method createMultipleInputStreamOperator.

/**
 * Create a BatchMultipleInputStreamOperator which contains the following sub-graph.
 *
 * <pre>
 *
 * source1  source2
 *   |        |
 *  agg1     agg2
 * (b) \     / (p)
 *      join1   source3
 *     (p) \     / (b)
 *         join2
 * (b) is the build side of the join, (p) is the probe side of the join.
 * </pre>
 */
private TestingBatchMultipleInputStreamOperator createMultipleInputStreamOperator() throws Exception {
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    Transformation<RowData> source1 = createSource(env, "source1");
    Transformation<RowData> source2 = createSource(env, "source2");
    Transformation<RowData> source3 = createSource(env, "source3");
    OneInputTransformation<RowData, RowData> agg1 = createOneInputTransform(source1, "agg1", new TestingOneInputStreamOperator(true), InternalTypeInfo.of(RowType.of(DataTypes.STRING().getLogicalType())));
    OneInputTransformation<RowData, RowData> agg2 = createOneInputTransform(source2, "agg2", new TestingOneInputStreamOperator(true), InternalTypeInfo.of(RowType.of(DataTypes.STRING().getLogicalType())));
    TwoInputTransformation<RowData, RowData, RowData> join1 = createTwoInputTransform(agg1, agg2, "join1", new TestingTwoInputStreamOperator(true), InternalTypeInfo.of(RowType.of(DataTypes.STRING().getLogicalType())));
    TwoInputTransformation<RowData, RowData, RowData> join2 = createTwoInputTransform(join1, source3, "join2", new TestingTwoInputStreamOperator(true), InternalTypeInfo.of(RowType.of(DataTypes.STRING().getLogicalType())));
    TableOperatorWrapperGenerator generator = new TableOperatorWrapperGenerator(Arrays.asList(source1, source2, source3), join2, new int[] { 1, 2, 0 });
    generator.generate();
    List<Pair<Transformation<?>, InputSpec>> inputTransformAndInputSpecPairs = generator.getInputTransformAndInputSpecPairs();
    List<StreamElement> outputData = new ArrayList<>();
    return new TestingBatchMultipleInputStreamOperator(createStreamOperatorParameters(new TestingOutput(outputData)), inputTransformAndInputSpecPairs.stream().map(Pair::getValue).collect(Collectors.toList()), generator.getHeadWrappers(), generator.getTailWrapper(), outputData);
}
Also used : ArrayList(java.util.ArrayList) StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

StreamElement (org.apache.flink.streaming.runtime.streamrecord.StreamElement)25 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)10 Watermark (org.apache.flink.streaming.api.watermark.Watermark)9 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)7 TestProcessingTimeService (org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService)6 IOException (java.io.IOException)3 Arrays (java.util.Arrays)3 List (java.util.List)3 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)3 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)3 IntSerializer (org.apache.flink.api.common.typeutils.base.IntSerializer)3 KeySelector (org.apache.flink.api.java.functions.KeySelector)3 Configuration (org.apache.flink.configuration.Configuration)3 DataOutputSerializer (org.apache.flink.core.memory.DataOutputSerializer)3 AbstractEvent (org.apache.flink.runtime.event.AbstractEvent)3 DummyInvokable (org.apache.flink.runtime.operators.testutils.DummyInvokable)3 MockEnvironment (org.apache.flink.runtime.operators.testutils.MockEnvironment)3 SerializationDelegate (org.apache.flink.runtime.plugable.SerializationDelegate)3 BoundedMultiInput (org.apache.flink.streaming.api.operators.BoundedMultiInput)3