use of org.apache.flink.runtime.operators.lifecycle.command.TestCommand in project flink by apache.
the class TestEventSource method run.
@Override
public void run(SourceContext<TestDataElement> ctx) {
long lastSent = 0;
while (isRunning) {
// Don't finish the source if it has not sent at least one value.
TestCommand cmd = lastSent == 0 ? null : scheduledCommands.poll();
if (cmd == FINISH_SOURCES) {
ack(cmd);
isRunning = false;
} else if (cmd == FAIL) {
ack(cmd);
throw new RuntimeException("requested to fail");
} else if (cmd == null) {
synchronized (ctx.getCheckpointLock()) {
ctx.collect(new TestDataElement(operatorID, getRuntimeContext().getIndexOfThisSubtask(), ++lastSent));
}
} else {
throw new RuntimeException("unknown command " + cmd);
}
}
}
Aggregations