Search in sources :

Example 6 with RunnableWithException

use of org.apache.flink.util.function.RunnableWithException in project flink by apache.

the class TaskMailboxProcessorTest method testAvoidStarvation.

/**
 * FLINK-14304: Avoid newly spawned letters to prevent input processing from ever happening.
 */
@Test
public void testAvoidStarvation() throws Exception {
    final int expectedInvocations = 3;
    final AtomicInteger counter = new AtomicInteger(0);
    MailboxThread mailboxThread = new MailboxThread() {

        @Override
        public void runDefaultAction(Controller controller) {
            if (counter.incrementAndGet() == expectedInvocations) {
                controller.allActionsCompleted();
            }
        }
    };
    mailboxThread.start();
    final MailboxProcessor mailboxProcessor = mailboxThread.getMailboxProcessor();
    final MailboxExecutor mailboxExecutor = mailboxProcessor.getMailboxExecutor(DEFAULT_PRIORITY);
    AtomicInteger index = new AtomicInteger();
    mailboxExecutor.execute(new RunnableWithException() {

        @Override
        public void run() {
            mailboxExecutor.execute(this, "Blocking mail" + index.incrementAndGet());
        }
    }, "Blocking mail" + index.get());
    mailboxThread.signalStart();
    mailboxThread.join();
    Assert.assertEquals(expectedInvocations, counter.get());
    Assert.assertEquals(expectedInvocations, index.get());
}
Also used : RunnableWithException(org.apache.flink.util.function.RunnableWithException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MailboxExecutor(org.apache.flink.api.common.operators.MailboxExecutor) Test(org.junit.Test)

Example 7 with RunnableWithException

use of org.apache.flink.util.function.RunnableWithException in project flink by apache.

the class ChannelStateCheckpointWriter method doComplete.

private void doComplete(boolean precondition, RunnableWithException complete, RunnableWithException... callbacks) throws Exception {
    Preconditions.checkArgument(precondition);
    complete.run();
    if (allInputsReceived && allOutputsReceived) {
        for (RunnableWithException callback : callbacks) {
            callback.run();
        }
    }
}
Also used : RunnableWithException(org.apache.flink.util.function.RunnableWithException)

Aggregations

RunnableWithException (org.apache.flink.util.function.RunnableWithException)7 Test (org.junit.Test)4 MailboxExecutor (org.apache.flink.api.common.operators.MailboxExecutor)3 Nullable (javax.annotation.Nullable)2 TaskIOMetricGroup (org.apache.flink.runtime.metrics.groups.TaskIOMetricGroup)2 MockEnvironment (org.apache.flink.runtime.operators.testutils.MockEnvironment)2 MockStreamTaskBuilder (org.apache.flink.streaming.util.MockStreamTaskBuilder)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RichInputFormat (org.apache.flink.api.common.io.RichInputFormat)1 TextInputFormat (org.apache.flink.api.java.io.TextInputFormat)1 FileInputSplit (org.apache.flink.core.fs.FileInputSplit)1 Path (org.apache.flink.core.fs.Path)1 TimestampedFileInputSplit (org.apache.flink.streaming.api.functions.source.TimestampedFileInputSplit)1 Watermark (org.apache.flink.streaming.api.watermark.Watermark)1