Code review comment: I was thinking after `task.invoke()` but I guess this is working as well.

Code before review:
public void testProcessWithUnAvailableOutput() throws Exception {
final long sleepTimeOutsideMail = 42;
final long sleepTimeInsideMail = 44;
@Nullable WaitingThread waitingThread = null;
try (final MockEnvironment environment = setupEnvironment(true, false)) {
final int numberOfProcessCalls = 10;
final AvailabilityTestInputProcessor inputProcessor =
new AvailabilityTestInputProcessor(numberOfProcessCalls);
final StreamTask task =
new MockStreamTaskBuilder(environment)
.setStreamInputProcessor(inputProcessor)
.build();
final MailboxExecutor executor = task.mailboxProcessor.getMainMailboxExecutor();
final RunnableWithException completeFutureTask =
() -> {
assertEquals(1, inputProcessor.currentNumProcessCalls);
assertTrue(task.mailboxProcessor.isDefaultActionUnavailable());
environment.getWriter(1).getAvailableFuture().complete(null);
};
waitingThread =
new WaitingThread(
executor,
completeFutureTask,
sleepTimeInsideMail,
sleepTimeOutsideMail);
executor.submit(
waitingThread::start,
"This task will submit another task to execute after processing input once.");
long startTs = System.currentTimeMillis();
TaskIOMetricGroup ioMetricGroup =
task.getEnvironment().getMetricGroup().getIOMetricGroup();
task.invoke();
long totalDuration = System.currentTimeMillis() - startTs;
assertThat(
ioMetricGroup.getBackPressuredTimePerSecond().getCount(),
Matchers.greaterThanOrEqualTo(sleepTimeOutsideMail));
assertThat(
ioMetricGroup.getBackPressuredTimePerSecond().getCount(),
Matchers.lessThanOrEqualTo(totalDuration - sleepTimeInsideMail));
assertThat(ioMetricGroup.getIdleTimeMsPerSecond().getCount(), is(0L));
assertEquals(numberOfProcessCalls, inputProcessor.currentNumProcessCalls);
} finally {
if (waitingThread != null) {
waitingThread.join();
}
}
}

Line under review: if (waitingThread != null) {

Code after addressing the review:
public void testProcessWithUnAvailableOutput() throws Exception {
final long sleepTimeOutsideMail = 42;
final long sleepTimeInsideMail = 44;
@Nullable WaitingThread waitingThread = null;
try (final MockEnvironment environment = setupEnvironment(true, false)) {
final int numberOfProcessCalls = 10;
final AvailabilityTestInputProcessor inputProcessor =
new AvailabilityTestInputProcessor(numberOfProcessCalls);
final StreamTask task =
new MockStreamTaskBuilder(environment)
.setStreamInputProcessor(inputProcessor)
.build();
final MailboxExecutor executor = task.mailboxProcessor.getMainMailboxExecutor();
final RunnableWithException completeFutureTask =
() -> {
assertEquals(1, inputProcessor.currentNumProcessCalls);
assertTrue(task.mailboxProcessor.isDefaultActionUnavailable());
environment.getWriter(1).getAvailableFuture().complete(null);
};
waitingThread =
new WaitingThread(
executor,
completeFutureTask,
sleepTimeInsideMail,
sleepTimeOutsideMail);
executor.submit(
waitingThread::start,
"This task will submit another task to execute after processing input once.");
long startTs = System.currentTimeMillis();
TaskIOMetricGroup ioMetricGroup =
task.getEnvironment().getMetricGroup().getIOMetricGroup();
task.invoke();
long totalDuration = System.currentTimeMillis() - startTs;
assertThat(
ioMetricGroup.getBackPressuredTimePerSecond().getCount(),
Matchers.greaterThanOrEqualTo(sleepTimeOutsideMail));
assertThat(
ioMetricGroup.getBackPressuredTimePerSecond().getCount(),
Matchers.lessThanOrEqualTo(totalDuration - sleepTimeInsideMail));
assertThat(ioMetricGroup.getIdleTimeMsPerSecond().getCount(), is(0L));
assertEquals(numberOfProcessCalls, inputProcessor.currentNumProcessCalls);
} finally {
if (waitingThread != null) {
waitingThread.join();
}
}
}