Search in sources :

Example 1 with RegularOperatorChain

use of org.apache.flink.streaming.runtime.tasks.RegularOperatorChain in project flink by apache.

the class StreamSourceOperatorLatencyMetricsTest method testLatencyMarkEmission.

private void testLatencyMarkEmission(int numberLatencyMarkers, OperatorSetupOperation operatorSetup) throws Exception {
    final List<StreamElement> output = new ArrayList<>();
    final TestProcessingTimeService testProcessingTimeService = new TestProcessingTimeService();
    testProcessingTimeService.setCurrentTime(0L);
    final List<Long> processingTimes = Arrays.asList(1L, 10L, 11L, 21L, maxProcessingTime);
    // regular stream source operator
    final StreamSource<Long, ProcessingTimeServiceSource> operator = new StreamSource<>(new ProcessingTimeServiceSource(testProcessingTimeService, processingTimes));
    operatorSetup.setupSourceOperator(operator, testProcessingTimeService);
    // run and wait to be stopped
    OperatorChain<?, ?> operatorChain = new RegularOperatorChain<>(operator.getContainingTask(), StreamTask.createRecordWriterDelegate(operator.getOperatorConfig(), new MockEnvironmentBuilder().build()));
    try {
        operator.run(new Object(), new CollectorOutput<>(output), operatorChain);
        operator.finish();
    } finally {
        operatorChain.close();
    }
    assertEquals(numberLatencyMarkers, output.size());
    long timestamp = 0L;
    int expectedLatencyIndex = 0;
    int i = 0;
    // verify that its only latency markers
    for (; i < numberLatencyMarkers; i++) {
        StreamElement se = output.get(i);
        Assert.assertTrue(se.isLatencyMarker());
        Assert.assertEquals(operator.getOperatorID(), se.asLatencyMarker().getOperatorId());
        Assert.assertEquals(0, se.asLatencyMarker().getSubtaskIndex());
        // as a result of which we never emit both 10 and 11
        while (timestamp > processingTimes.get(expectedLatencyIndex)) {
            expectedLatencyIndex++;
        }
        Assert.assertEquals(processingTimes.get(expectedLatencyIndex).longValue(), se.asLatencyMarker().getMarkedTime());
        timestamp += latencyMarkInterval;
    }
}
Also used : MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) StreamSource(org.apache.flink.streaming.api.operators.StreamSource) ArrayList(java.util.ArrayList) StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) TestProcessingTimeService(org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService) RegularOperatorChain(org.apache.flink.streaming.runtime.tasks.RegularOperatorChain)

Aggregations

ArrayList (java.util.ArrayList)1 MockEnvironmentBuilder (org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder)1 StreamSource (org.apache.flink.streaming.api.operators.StreamSource)1 StreamElement (org.apache.flink.streaming.runtime.streamrecord.StreamElement)1 RegularOperatorChain (org.apache.flink.streaming.runtime.tasks.RegularOperatorChain)1 TestProcessingTimeService (org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService)1