use of org.apache.flink.runtime.operators.lifecycle.event.TestEvent in project flink by apache.
the class DrainingValidator method validateSubtaskAttempt.
private void validateSubtaskAttempt(TestJobWithDescription job, String operatorId, int subtaskIndex, List<TestEvent> operatorEvents) {
BitSet endedInputs = new BitSet();
BitSet inputsWithMaxWatermark = new BitSet();
for (TestEvent ev : operatorEvents) {
if (ev instanceof WatermarkReceivedEvent) {
WatermarkReceivedEvent w = (WatermarkReceivedEvent) ev;
if (w.ts == Watermark.MAX_WATERMARK.getTimestamp()) {
assertFalse(String.format("Max Watermark received twice by %s/%d/%d", w.operatorId, w.subtaskIndex, w.inputId), inputsWithMaxWatermark.get(w.inputId));
inputsWithMaxWatermark.set(w.inputId);
}
} else if (ev instanceof InputEndedEvent) {
InputEndedEvent w = (InputEndedEvent) ev;
assertTrue(format("Input %d ended before receiving max watermark by %s[%d]#%d", w.inputId, operatorId, subtaskIndex, w.attemptNumber), inputsWithMaxWatermark.get(w.inputId));
assertFalse(endedInputs.get(w.inputId));
endedInputs.set(w.inputId);
}
}
assertEquals(format("Incorrect number of ended inputs for %s[%d]", operatorId, subtaskIndex), getNumInputs(job, operatorId), endedInputs.cardinality());
}
use of org.apache.flink.runtime.operators.lifecycle.event.TestEvent in project flink by apache.
the class TestOperatorLifecycleValidator method checkOperatorsLifecycle.
static void checkOperatorsLifecycle(TestJobWithDescription testJob, TestOperatorLifecycleValidator... validators) {
Map<Tuple2<String, Integer>, List<TestEvent>> eventsByOperator = new HashMap<>();
for (TestEvent ev : testJob.eventQueue.getAll()) {
eventsByOperator.computeIfAbsent(Tuple2.of(ev.operatorId, ev.subtaskIndex), ign -> new ArrayList<>()).add(ev);
}
eventsByOperator.forEach((operatorIdAndIndex, operatorEvents) -> {
String id = operatorIdAndIndex.f0;
if (testJob.operatorsWithLifecycleTracking.contains(id)) {
for (TestOperatorLifecycleValidator validator : validators) {
validator.validateOperatorLifecycle(testJob, id, operatorIdAndIndex.f1, operatorEvents);
}
}
});
}
use of org.apache.flink.runtime.operators.lifecycle.event.TestEvent in project flink by apache.
the class FinishingValidator method validateOperatorLifecycle.
@Override
public void validateOperatorLifecycle(TestJobWithDescription job, String operatorId, int subtaskIndex, List<TestEvent> operatorEvents) {
boolean opFinished = false;
Set<Long> finalCheckpointCandidates = new HashSet<>();
for (TestEvent ev : operatorEvents) {
if (ev instanceof OperatorFinishedEvent) {
opFinished = true;
} else if (ev instanceof CheckpointStartedEvent) {
if (opFinished) {
finalCheckpointCandidates.add(((CheckpointStartedEvent) ev).checkpointID);
}
} else if (ev instanceof CheckpointCompletedEvent) {
if (finalCheckpointCandidates.contains(((CheckpointCompletedEvent) ev).checkpointID)) {
return;
}
} else if (opFinished) {
fail(format("Unexpected event after operator %s[%d] finished: %s", operatorId, subtaskIndex, ev));
}
}
assertTrue(format("Operator %s[%d] wasn't finished (events: %s)", operatorId, subtaskIndex, operatorEvents), opFinished);
fail(format("Operator %s[%d] was finished but didn't finish the checkpoint after that;" + "checkpoints started after finish: %s (events (excluding watermarks): %s)", operatorId, subtaskIndex, finalCheckpointCandidates, operatorEvents.stream().filter(ev -> !(ev instanceof WatermarkReceivedEvent)).collect(toList())));
}
use of org.apache.flink.runtime.operators.lifecycle.event.TestEvent in project flink by apache.
the class TestJobExecutor method waitForFailover.
private void waitForFailover(BlockingQueue<TestEvent> queue) throws Exception {
int timeoutMs = 10_000;
Deadline deadline = Deadline.fromNow(Duration.ofMillis(timeoutMs));
String operatorId = null;
int subtaskId = -1;
int attemptNumber = -1;
while (deadline.hasTimeLeft()) {
TestEvent e = queue.poll(deadline.timeLeft().toMillis(), MILLISECONDS);
if (e instanceof TestCommandAckEvent) {
TestCommandAckEvent ack = (TestCommandAckEvent) e;
if (ack.getCommand() == FAIL) {
operatorId = ack.operatorId;
subtaskId = ack.subtaskIndex;
attemptNumber = ack.getAttemptNumber();
}
} else if (e instanceof OperatorStartedEvent && operatorId != null) {
OperatorStartedEvent started = (OperatorStartedEvent) e;
if (started.operatorId.equals(operatorId) && started.subtaskIndex == subtaskId && started.getAttemptNumber() >= attemptNumber) {
return;
}
}
}
throw new TimeoutException("No subtask restarted in " + timeoutMs + "ms");
}
use of org.apache.flink.runtime.operators.lifecycle.event.TestEvent in project flink by apache.
the class DrainingValidator method validateOperatorLifecycle.
@Override
public void validateOperatorLifecycle(TestJobWithDescription job, String operatorId, int subtaskIndex, List<TestEvent> operatorEvents) {
Map<Integer, List<TestEvent>> byAttempt = new HashMap<>();
Set<Integer> normallyFinishedAttempts = new HashSet<>();
int lastAttempt = Integer.MIN_VALUE;
for (TestEvent e : operatorEvents) {
byAttempt.computeIfAbsent(e.attemptNumber, ign -> new ArrayList<>()).add(e);
if (isFinishAck(e)) {
normallyFinishedAttempts.add(e.attemptNumber);
}
lastAttempt = Math.max(lastAttempt, e.attemptNumber);
}
for (Map.Entry<Integer, List<TestEvent>> entry : byAttempt.entrySet()) {
// Skip if this or other task from this attempt failed.
if (lastAttempt == entry.getKey() || normallyFinishedAttempts.contains(entry.getKey())) {
validateSubtaskAttempt(job, operatorId, subtaskIndex, entry.getValue());
}
}
}
Aggregations