Search in sources :

Example 1 with SystemClock

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();
        }
    }
}
Also used : MockStreamTaskBuilder(org.apache.flink.streaming.util.MockStreamTaskBuilder) RunnableWithException(org.apache.flink.util.function.RunnableWithException) SystemClock(org.apache.flink.util.clock.SystemClock) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) MailboxExecutor(org.apache.flink.api.common.operators.MailboxExecutor) TaskIOMetricGroup(org.apache.flink.runtime.metrics.groups.TaskIOMetricGroup) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Aggregations

Nullable (javax.annotation.Nullable)1 MailboxExecutor (org.apache.flink.api.common.operators.MailboxExecutor)1 TaskIOMetricGroup (org.apache.flink.runtime.metrics.groups.TaskIOMetricGroup)1 MockEnvironment (org.apache.flink.runtime.operators.testutils.MockEnvironment)1 MockStreamTaskBuilder (org.apache.flink.streaming.util.MockStreamTaskBuilder)1 SystemClock (org.apache.flink.util.clock.SystemClock)1 RunnableWithException (org.apache.flink.util.function.RunnableWithException)1 Test (org.junit.Test)1