use of org.apache.flink.util.clock.SystemClock in project flink by apache.
the class StreamTaskTest method testProcessWithUnAvailableInput.
@Test
public void testProcessWithUnAvailableInput() throws Exception {
final long sleepTimeOutsideMail = 42;
final long sleepTimeInsideMail = 44;
@Nullable WaitingThread waitingThread = null;
try (final MockEnvironment environment = setupEnvironment(true, true)) {
final UnAvailableTestInputProcessor inputProcessor = new UnAvailableTestInputProcessor();
final StreamTask task = new MockStreamTaskBuilder(environment).setStreamInputProcessor(inputProcessor).build();
TaskIOMetricGroup ioMetricGroup = task.getEnvironment().getMetricGroup().getIOMetricGroup();
final MailboxExecutor executor = task.mailboxProcessor.getMainMailboxExecutor();
final RunnableWithException completeFutureTask = () -> {
inputProcessor.availabilityProvider.getUnavailableToResetAvailable().complete(null);
};
waitingThread = new WaitingThread(executor, completeFutureTask, sleepTimeInsideMail, sleepTimeOutsideMail, ioMetricGroup.getIdleTimeMsPerSecond());
// Make sure WaitingThread is started after Task starts processing.
executor.submit(waitingThread::start, "Start WaitingThread after Task starts processing input.");
SystemClock clock = SystemClock.getInstance();
long startTs = clock.absoluteTimeMillis();
task.invoke();
long totalDuration = clock.absoluteTimeMillis() - startTs;
assertThat(ioMetricGroup.getIdleTimeMsPerSecond().getCount(), greaterThanOrEqualTo(sleepTimeOutsideMail));
assertThat(ioMetricGroup.getIdleTimeMsPerSecond().getCount(), Matchers.lessThanOrEqualTo(totalDuration - sleepTimeInsideMail));
assertThat(ioMetricGroup.getSoftBackPressuredTimePerSecond().getCount(), is(0L));
assertThat(ioMetricGroup.getHardBackPressuredTimePerSecond().getCount(), is(0L));
} finally {
if (waitingThread != null) {
waitingThread.join();
}
}
}
Aggregations