Efrat19 commented on code in PR #29954:
URL: https://github.com/apache/flink/pull/29954#discussion_r4657293675
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -1564,6 +1575,146 @@ void
testTaskAvoidHangingAfterSnapshotStateThrownException() throws Exception {
}
}
+ /** Aligned-checkpoint timeout used by the {@code alignedWithTimeout}
checkpoint options. */
+ private static final long ALIGNED_CHECKPOINT_TIMEOUT_MS = 10_000L;
+
+ /** Upper bound of mailbox steps to wait for the checkpoint trigger to
complete. */
+ private static final int MAX_MAILBOX_STEPS = 100;
+
+ static Stream<Named<CheckpointOptions>>
provideCheckpointOptionsForOperatorEventOrdering() {
+ return Stream.of(
+ Named.of(
+ "alignedNoTimeout",
+ CheckpointOptions.alignedNoTimeout(
+ CheckpointType.CHECKPOINT, getDefault())),
+ Named.of(
+ "alignedWithTimeout",
+ CheckpointOptions.alignedWithTimeout(
+ CheckpointType.CHECKPOINT,
+ getDefault(),
+ ALIGNED_CHECKPOINT_TIMEOUT_MS)),
+ Named.of(
+ "unaligned",
+ CheckpointOptions.unaligned(CheckpointType.CHECKPOINT,
getDefault())));
+ }
+
+ /**
+ * Operator events dispatched before a checkpoint trigger must be applied
before the operator is
+ * snapshotted, including the case of an urgent (unaligned) trigger.
Events are urgent mails too
+ * so that they keep FIFO order with the urgent trigger.
+ */
+ @ParameterizedTest
+ @MethodSource("provideCheckpointOptionsForOperatorEventOrdering")
+ void testOperatorEventsAreAppliedBeforeCheckpointTrigger(CheckpointOptions
checkpointOptions)
+ throws Exception {
+ final OperatorID operatorId = new OperatorID();
+ final List<String> invocations = EventRecordingOperator.INVOCATIONS;
+ invocations.clear();
+ try (StreamTaskMailboxTestHarness<String> harness =
+ new
StreamTaskMailboxTestHarnessBuilder<>(OneInputStreamTask::new, STRING_TYPE_INFO)
+ .addInput(STRING_TYPE_INFO)
+ .setupOutputForSingletonOperatorChain(
+ new EventRecordingOperatorFactory(),
operatorId)
+ .build()) {
+ harness.setAutoProcess(false);
+ harness.processAll();
+
+ harness.streamTask.dispatchOperatorEvent(operatorId,
serializedEvent("event-1"));
+ // A normal mail interleaved between urgent events must not
reorder them.
+ harness.streamTask.notifyCheckpointCompleteAsync(100);
+ harness.streamTask.dispatchOperatorEvent(operatorId,
serializedEvent("event-2"));
+ CompletableFuture<Boolean> triggered =
+ harness.streamTask.triggerCheckpointAsync(
+ new CheckpointMetaData(1L, 1L), checkpointOptions);
+ harness.streamTask.dispatchOperatorEvent(operatorId,
serializedEvent("event-3"));
+
+ // The ordering relies on events and triggers having the same
priority: an operator
+ // yielding at a priority in between must not run the trigger
before the events.
+ for (int priority : new int[] {MAX_PRIORITY, 1, 0}) {
+ MailboxExecutor executor =
+
harness.streamTask.getMailboxExecutorFactory().createExecutor(priority);
+ while (executor.tryYield()) {
+ if (invocations.contains("snapshot")) {
Review Comment:
Nit?
```suggestion
assertThat(invocations).doesNotContain("snapshot");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]