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;
}
}
Aggregations