Search in sources :

Example 1 with SourceOperatorTestHarness

use of org.apache.flink.streaming.util.SourceOperatorTestHarness in project flink by apache.

the class SourceOperatorLatencyMetricsTest method testLatencyMarkEmission.

private void testLatencyMarkEmission(boolean shouldExpectLatencyMarkers, Configuration taskManagerConfig, ExecutionConfig executionConfig) throws Exception {
    try (SourceOperatorTestHarness testHarness = new SourceOperatorTestHarness(new SourceOperatorFactory(new MockSource(Boundedness.CONTINUOUS_UNBOUNDED, 1), WatermarkStrategy.noWatermarks()), new MockEnvironmentBuilder().setTaskManagerRuntimeInfo(new TestingTaskManagerRuntimeInfo(taskManagerConfig)).setExecutionConfig(executionConfig).build())) {
        testHarness.open();
        testHarness.setup();
        for (long processingTime = 0; processingTime <= MAX_PROCESSING_TIME; processingTime++) {
            testHarness.getProcessingTimeService().setCurrentTime(processingTime);
            testHarness.emitNext();
        }
        List<LatencyMarker> expectedOutput = new ArrayList<>();
        if (!shouldExpectLatencyMarkers) {
            assertTrue(testHarness.getOutput().isEmpty());
        } else {
            expectedOutput.add(new LatencyMarker(1, testHarness.getOperator().getOperatorID(), 0));
            for (long markedTime = LATENCY_MARK_INTERVAL; markedTime <= MAX_PROCESSING_TIME; markedTime += LATENCY_MARK_INTERVAL) {
                expectedOutput.add(new LatencyMarker(markedTime, testHarness.getOperator().getOperatorID(), 0));
            }
            assertThat((Collection<Object>) testHarness.getOutput(), contains(expectedOutput.toArray()));
        }
    }
}
Also used : MockSource(org.apache.flink.api.connector.source.mocks.MockSource) MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) SourceOperatorTestHarness(org.apache.flink.streaming.util.SourceOperatorTestHarness) LatencyMarker(org.apache.flink.streaming.runtime.streamrecord.LatencyMarker) ArrayList(java.util.ArrayList) SourceOperatorFactory(org.apache.flink.streaming.api.operators.SourceOperatorFactory)

Aggregations

ArrayList (java.util.ArrayList)1 MockSource (org.apache.flink.api.connector.source.mocks.MockSource)1 MockEnvironmentBuilder (org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder)1 TestingTaskManagerRuntimeInfo (org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo)1 SourceOperatorFactory (org.apache.flink.streaming.api.operators.SourceOperatorFactory)1 LatencyMarker (org.apache.flink.streaming.runtime.streamrecord.LatencyMarker)1 SourceOperatorTestHarness (org.apache.flink.streaming.util.SourceOperatorTestHarness)1