use of org.apache.flink.runtime.operators.testutils.MockEnvironment in project flink by apache.
the class InputProcessorUtilTest method testCreateCheckpointedMultipleInputGate.
@Test
public void testCreateCheckpointedMultipleInputGate() throws Exception {
try (CloseableRegistry registry = new CloseableRegistry()) {
MockEnvironment environment = new MockEnvironmentBuilder().build();
MockStreamTask streamTask = new MockStreamTaskBuilder(environment).build();
StreamConfig streamConfig = new StreamConfig(environment.getJobConfiguration());
streamConfig.setCheckpointMode(CheckpointingMode.EXACTLY_ONCE);
streamConfig.setUnalignedCheckpointsEnabled(true);
// First input gate has index larger than the second
List<IndexedInputGate>[] inputGates = new List[] { Collections.singletonList(getGate(1, 4)), Collections.singletonList(getGate(0, 2)) };
CheckpointBarrierHandler barrierHandler = InputProcessorUtil.createCheckpointBarrierHandler(streamTask, streamConfig, new TestSubtaskCheckpointCoordinator(new MockChannelStateWriter()), streamTask.getName(), inputGates, Collections.emptyList(), new SyncMailboxExecutor(), new TestProcessingTimeService());
CheckpointedInputGate[] checkpointedMultipleInputGate = InputProcessorUtil.createCheckpointedMultipleInputGate(new SyncMailboxExecutor(), inputGates, environment.getMetricGroup().getIOMetricGroup(), barrierHandler, streamConfig);
for (CheckpointedInputGate checkpointedInputGate : checkpointedMultipleInputGate) {
registry.registerCloseable(checkpointedInputGate);
}
List<IndexedInputGate> allInputGates = Arrays.stream(inputGates).flatMap(gates -> gates.stream()).collect(Collectors.toList());
for (IndexedInputGate inputGate : allInputGates) {
for (int channelId = 0; channelId < inputGate.getNumberOfInputChannels(); channelId++) {
barrierHandler.processBarrier(new CheckpointBarrier(1, 42, CheckpointOptions.unaligned(CheckpointType.CHECKPOINT, CheckpointStorageLocationReference.getDefault())), new InputChannelInfo(inputGate.getGateIndex(), channelId), false);
}
}
assertTrue(barrierHandler.getAllBarriersReceivedFuture(1).isDone());
}
}
use of org.apache.flink.runtime.operators.testutils.MockEnvironment in project flink by apache.
the class StreamTaskTest method testProcessWithAvailableOutput.
@Test
public void testProcessWithAvailableOutput() throws Exception {
try (final MockEnvironment environment = setupEnvironment(true, true)) {
final int numberOfProcessCalls = 10;
final AvailabilityTestInputProcessor inputProcessor = new AvailabilityTestInputProcessor(numberOfProcessCalls);
final StreamTask task = new MockStreamTaskBuilder(environment).setStreamInputProcessor(inputProcessor).build();
task.invoke();
assertEquals(numberOfProcessCalls, inputProcessor.currentNumProcessCalls);
}
}
use of org.apache.flink.runtime.operators.testutils.MockEnvironment in project flink by apache.
the class StreamTaskTest method testQuiesceOfMailboxRightBeforeSubmittingActionViaTimerService.
@Test
public void testQuiesceOfMailboxRightBeforeSubmittingActionViaTimerService() throws Exception {
// given: the stream task with configured handle async exception.
AtomicBoolean submitThroughputFail = new AtomicBoolean();
MockEnvironment mockEnvironment = new MockEnvironmentBuilder().build();
final UnAvailableTestInputProcessor inputProcessor = new UnAvailableTestInputProcessor();
RunningTask<StreamTask<?, ?>> task = runTask(() -> new MockStreamTaskBuilder(mockEnvironment).setHandleAsyncException((str, t) -> submitThroughputFail.set(true)).setStreamInputProcessor(inputProcessor).build());
waitTaskIsRunning(task.streamTask, task.invocationFuture);
TimerService timerService = task.streamTask.systemTimerService;
MailboxExecutor mainMailboxExecutor = task.streamTask.mailboxProcessor.getMainMailboxExecutor();
CountDownLatch stoppingMailboxLatch = new CountDownLatch(1);
timerService.registerTimer(timerService.getCurrentProcessingTime(), (time) -> {
stoppingMailboxLatch.await();
// The time to the start 'afterInvoke' inside of mailbox.
// 'afterInvoke' won't finish until this execution won't finish so it is
// impossible to wait on latch or something else.
Thread.sleep(5);
mainMailboxExecutor.submit(() -> {
}, "test");
});
// when: Calling the quiesce for mailbox and finishing the timer service.
mainMailboxExecutor.submit(() -> {
stoppingMailboxLatch.countDown();
task.streamTask.afterInvoke();
}, "test").get();
// then: the exception handle wasn't invoked because the such situation is expected.
assertFalse(submitThroughputFail.get());
// Correctly shutdown the stream task to avoid hanging.
inputProcessor.availabilityProvider.getUnavailableToResetAvailable().complete(null);
}
use of org.apache.flink.runtime.operators.testutils.MockEnvironment in project flink by apache.
the class StreamTaskTest method streamTaskAsyncExceptionHandler_handleException_forwardsMessageProperly.
/**
* This test checks the async exceptions handling wraps the message and cause as an
* AsynchronousException and propagates this to the environment.
*/
@Test
public void streamTaskAsyncExceptionHandler_handleException_forwardsMessageProperly() {
MockEnvironment mockEnvironment = MockEnvironment.builder().build();
RuntimeException expectedException = new RuntimeException("RUNTIME EXCEPTION");
final StreamTask.StreamTaskAsyncExceptionHandler asyncExceptionHandler = new StreamTask.StreamTaskAsyncExceptionHandler(mockEnvironment);
mockEnvironment.setExpectedExternalFailureCause(AsynchronousException.class);
final String expectedErrorMessage = "EXPECTED_ERROR MESSAGE";
asyncExceptionHandler.handleAsyncException(expectedErrorMessage, expectedException);
// expect an AsynchronousException containing the supplied error details
Optional<? extends Throwable> actualExternalFailureCause = mockEnvironment.getActualExternalFailureCause();
final Throwable actualException = actualExternalFailureCause.orElseThrow(() -> new AssertionError("Expected exceptional completion"));
assertThat(actualException, instanceOf(AsynchronousException.class));
assertThat(actualException.getMessage(), is("EXPECTED_ERROR MESSAGE"));
assertThat(actualException.getCause(), is(expectedException));
}
use of org.apache.flink.runtime.operators.testutils.MockEnvironment in project flink by apache.
the class StreamTaskTest method testExecuteMailboxActionsAfterLeavingInputProcessorMailboxLoop.
@Test
public void testExecuteMailboxActionsAfterLeavingInputProcessorMailboxLoop() throws Exception {
OneShotLatch latch = new OneShotLatch();
try (MockEnvironment mockEnvironment = new MockEnvironmentBuilder().build()) {
RunningTask<StreamTask<?, ?>> task = runTask(() -> new StreamTask<Object, StreamOperator<Object>>(mockEnvironment) {
@Override
protected void init() throws Exception {
}
@Override
protected void processInput(MailboxDefaultAction.Controller controller) throws Exception {
mailboxProcessor.getMailboxExecutor(0).execute(latch::trigger, "trigger");
controller.suspendDefaultAction();
mailboxProcessor.suspend();
}
});
latch.await();
task.waitForTaskCompletion(false);
}
}
Aggregations