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