Search in sources :

Example 1 with OperatorFinishedEvent

use of org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent 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())));
}
Also used : CheckpointStartedEvent(org.apache.flink.runtime.operators.lifecycle.event.CheckpointStartedEvent) CheckpointStartedEvent(org.apache.flink.runtime.operators.lifecycle.event.CheckpointStartedEvent) TestJobWithDescription(org.apache.flink.runtime.operators.lifecycle.TestJobWithDescription) WatermarkReceivedEvent(org.apache.flink.runtime.operators.lifecycle.event.WatermarkReceivedEvent) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) String.format(java.lang.String.format) TestEvent(org.apache.flink.runtime.operators.lifecycle.event.TestEvent) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) HashSet(java.util.HashSet) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) OperatorFinishedEvent(org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent) CheckpointCompletedEvent(org.apache.flink.runtime.operators.lifecycle.event.CheckpointCompletedEvent) Assert.fail(org.junit.Assert.fail) OperatorFinishedEvent(org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent) TestEvent(org.apache.flink.runtime.operators.lifecycle.event.TestEvent) WatermarkReceivedEvent(org.apache.flink.runtime.operators.lifecycle.event.WatermarkReceivedEvent) CheckpointCompletedEvent(org.apache.flink.runtime.operators.lifecycle.event.CheckpointCompletedEvent) HashSet(java.util.HashSet)

Example 2 with OperatorFinishedEvent

use of org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent in project flink by apache.

the class OneInputTestStreamOperator method finish.

@Override
public void finish() throws Exception {
    eventQueue.add(new OperatorFinishedEvent(operatorID, getRuntimeContext().getIndexOfThisSubtask(), getRuntimeContext().getAttemptNumber(), lastDataSent, new OperatorFinishedEvent.LastReceivedVertexDataInfo(lastDataReceived)));
    super.finish();
}
Also used : OperatorFinishedEvent(org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent)

Example 3 with OperatorFinishedEvent

use of org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent in project flink by apache.

the class TwoInputTestStreamOperator method finish.

@Override
public void finish() throws Exception {
    collectEvent(new OperatorFinishedEvent(operatorID, getRuntimeContext().getIndexOfThisSubtask(), getRuntimeContext().getAttemptNumber(), lastDataSent, new LastReceivedVertexDataInfo(lastDataReceived)));
    super.finish();
}
Also used : OperatorFinishedEvent(org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent) LastReceivedVertexDataInfo(org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent.LastReceivedVertexDataInfo)

Example 4 with OperatorFinishedEvent

use of org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent in project flink by apache.

the class TestJobDataFlowValidator method checkDataFlow.

public static void checkDataFlow(TestJobWithDescription testJob, boolean withDrain) {
    Map<String, Map<Integer, OperatorFinishedEvent>> finishEvents = new HashMap<>();
    for (TestEvent ev : testJob.eventQueue.getAll()) {
        if (ev instanceof OperatorFinishedEvent) {
            finishEvents.computeIfAbsent(ev.operatorId, ign -> new HashMap<>()).put(ev.subtaskIndex, ((OperatorFinishedEvent) ev));
        }
    }
    for (JobVertex upstream : testJob.jobGraph.getVertices()) {
        for (IntermediateDataSet produced : upstream.getProducedDataSets()) {
            JobEdge edge = produced.getConsumer();
            Optional<String> upstreamIDOptional = getTrackedOperatorID(upstream, true, testJob);
            Optional<String> downstreamIDOptional = getTrackedOperatorID(edge.getTarget(), false, testJob);
            if (upstreamIDOptional.isPresent() && downstreamIDOptional.isPresent()) {
                final String upstreamID = upstreamIDOptional.get();
                final String downstreamID = downstreamIDOptional.get();
                if (testJob.sources.contains(upstreamID)) {
                    // TODO: if we add tests for FLIP-27 sources we might need to adjust
                    // this condition
                    LOG.debug("Legacy sources do not have the finish() method and thus do not" + " emit FinishEvent");
                } else {
                    checkDataFlow(upstreamID, downstreamID, edge, finishEvents, withDrain);
                }
            } else {
                LOG.debug("Ignoring edge (untracked operator): {}", edge);
            }
        }
    }
}
Also used : Logger(org.slf4j.Logger) JobEdge(org.apache.flink.runtime.jobgraph.JobEdge) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) ListIterator(java.util.ListIterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) TestJobWithDescription(org.apache.flink.runtime.operators.lifecycle.TestJobWithDescription) LoggerFactory(org.slf4j.LoggerFactory) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) OperatorIDPair(org.apache.flink.runtime.OperatorIDPair) String.format(java.lang.String.format) TestEvent(org.apache.flink.runtime.operators.lifecycle.event.TestEvent) IntermediateDataSet(org.apache.flink.runtime.jobgraph.IntermediateDataSet) Assert.assertNull(org.junit.Assert.assertNull) OperatorFinishedEvent(org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent) Map(java.util.Map) Optional(java.util.Optional) OperatorFinishedEvent(org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) IntermediateDataSet(org.apache.flink.runtime.jobgraph.IntermediateDataSet) HashMap(java.util.HashMap) TestEvent(org.apache.flink.runtime.operators.lifecycle.event.TestEvent) JobEdge(org.apache.flink.runtime.jobgraph.JobEdge) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with OperatorFinishedEvent

use of org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent in project flink by apache.

the class MultiInputTestOperator method finish.

@Override
public void finish() throws Exception {
    eventQueue.add(new OperatorFinishedEvent(operatorId, getRuntimeContext().getIndexOfThisSubtask(), getRuntimeContext().getAttemptNumber(), lastDataSent.get(), new LastReceivedVertexDataInfo(lastDataReceived)));
    super.finish();
}
Also used : OperatorFinishedEvent(org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent) LastReceivedVertexDataInfo(org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent.LastReceivedVertexDataInfo)

Aggregations

OperatorFinishedEvent (org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent)5 String.format (java.lang.String.format)2 TestJobWithDescription (org.apache.flink.runtime.operators.lifecycle.TestJobWithDescription)2 LastReceivedVertexDataInfo (org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent.LastReceivedVertexDataInfo)2 TestEvent (org.apache.flink.runtime.operators.lifecycle.event.TestEvent)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors.toList (java.util.stream.Collectors.toList)1 OperatorIDPair (org.apache.flink.runtime.OperatorIDPair)1 IntermediateDataSet (org.apache.flink.runtime.jobgraph.IntermediateDataSet)1 JobEdge (org.apache.flink.runtime.jobgraph.JobEdge)1 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)1 CheckpointCompletedEvent (org.apache.flink.runtime.operators.lifecycle.event.CheckpointCompletedEvent)1