Search in sources :

Example 6 with TestEvent

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

the class SameCheckpointValidator method validateOperatorLifecycle.

@Override
public void validateOperatorLifecycle(TestJobWithDescription job, String operatorId, int subtaskIndex, List<TestEvent> operatorEvents) {
    boolean started = false;
    boolean finished = false;
    for (TestEvent ev : operatorEvents) {
        if (ev instanceof CheckpointStartedEvent) {
            if (lastCheckpointID == ((CheckpointStartedEvent) ev).checkpointID) {
                assertFalse(format("Operator %s[%d] started checkpoint %d twice", operatorId, subtaskIndex, lastCheckpointID), started);
                started = true;
            }
        } else if (ev instanceof CheckpointCompletedEvent) {
            if (lastCheckpointID == ((CheckpointCompletedEvent) ev).checkpointID) {
                assertTrue(format("Operator %s[%d] finished checkpoint %d before starting", operatorId, subtaskIndex, lastCheckpointID), started);
                assertFalse(format("Operator %s[%d] finished checkpoint %d twice", operatorId, subtaskIndex, lastCheckpointID), finished);
                finished = true;
            }
        }
    }
    assertTrue(format("Operator %s[%d] didn't finish checkpoint %d (events: %s)", operatorId, subtaskIndex, lastCheckpointID, operatorEvents), finished);
}
Also used : CheckpointStartedEvent(org.apache.flink.runtime.operators.lifecycle.event.CheckpointStartedEvent) TestEvent(org.apache.flink.runtime.operators.lifecycle.event.TestEvent) CheckpointCompletedEvent(org.apache.flink.runtime.operators.lifecycle.event.CheckpointCompletedEvent)

Example 7 with TestEvent

use of org.apache.flink.runtime.operators.lifecycle.event.TestEvent 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)

Aggregations

TestEvent (org.apache.flink.runtime.operators.lifecycle.event.TestEvent)7 TestJobWithDescription (org.apache.flink.runtime.operators.lifecycle.TestJobWithDescription)4 String.format (java.lang.String.format)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 WatermarkReceivedEvent (org.apache.flink.runtime.operators.lifecycle.event.WatermarkReceivedEvent)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 OperatorIDPair (org.apache.flink.runtime.OperatorIDPair)2 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)2 CheckpointCompletedEvent (org.apache.flink.runtime.operators.lifecycle.event.CheckpointCompletedEvent)2 CheckpointStartedEvent (org.apache.flink.runtime.operators.lifecycle.event.CheckpointStartedEvent)2 InputEndedEvent (org.apache.flink.runtime.operators.lifecycle.event.InputEndedEvent)2 OperatorFinishedEvent (org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent)2 TestCommandAckEvent (org.apache.flink.runtime.operators.lifecycle.event.TestCommandAckEvent)2 Collection (java.util.Collection)1