Search in sources :

Example 1 with TestJobWithDescription

use of org.apache.flink.runtime.operators.lifecycle.TestJobWithDescription 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);
            }
        }
    });
}
Also used : List(java.util.List) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Map(java.util.Map) TestJobWithDescription(org.apache.flink.runtime.operators.lifecycle.TestJobWithDescription) HashMap(java.util.HashMap) TestEvent(org.apache.flink.runtime.operators.lifecycle.event.TestEvent) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) TestEvent(org.apache.flink.runtime.operators.lifecycle.event.TestEvent) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with TestJobWithDescription

use of org.apache.flink.runtime.operators.lifecycle.TestJobWithDescription 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 3 with TestJobWithDescription

use of org.apache.flink.runtime.operators.lifecycle.TestJobWithDescription 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());
        }
    }
}
Also used : TestCommand(org.apache.flink.runtime.operators.lifecycle.command.TestCommand) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) TestJobWithDescription(org.apache.flink.runtime.operators.lifecycle.TestJobWithDescription) WatermarkReceivedEvent(org.apache.flink.runtime.operators.lifecycle.event.WatermarkReceivedEvent) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) OperatorIDPair(org.apache.flink.runtime.OperatorIDPair) String.format(java.lang.String.format) InputEndedEvent(org.apache.flink.runtime.operators.lifecycle.event.InputEndedEvent) TestEvent(org.apache.flink.runtime.operators.lifecycle.event.TestEvent) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) BitSet(java.util.BitSet) NoSuchElementException(java.util.NoSuchElementException) TestCommandAckEvent(org.apache.flink.runtime.operators.lifecycle.event.TestCommandAckEvent) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) TestEvent(org.apache.flink.runtime.operators.lifecycle.event.TestEvent) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with TestJobWithDescription

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

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

the class IncrementalStateReuseAfterFailureITCase method createJob.

private TestJobWithDescription createJob() {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.enableCheckpointing(200);
    // reliably fails Changelog with FLINK-25395, but might affect any incremental backend
    env.enableChangelogStateBackend(true);
    env.setRestartStrategy(RestartStrategies.fixedDelayRestart(1, 1));
    // simplify debugging
    env.setMaxParallelism(1);
    // simplify debugging
    env.setParallelism(1);
    TestEventQueue evQueue = TestEventQueue.createShared(sharedObjects);
    TestCommandDispatcher cmdQueue = TestCommandDispatcher.createShared(sharedObjects);
    DataStream<TestDataElement> src = env.addSource(new TestEventSource(UID_SRC, evQueue, cmdQueue)).setUidHash(UID_SRC);
    SingleOutputStreamOperator<TestDataElement> transform1 = src.keyBy(x -> x).transform("transform-1", TypeInformation.of(TestDataElement.class), new OneInputTestStreamOperatorFactory(UID_OP1, evQueue, cmdQueue)).setUidHash(UID_OP1);
    SingleOutputStreamOperator<TestDataElement> transform2 = // chain two keyed operators, so that one is checkpointed and the other one fails
    DataStreamUtils.reinterpretAsKeyedStream(transform1, x -> x).transform("transform-2", TypeInformation.of(TestDataElement.class), new OneInputTestStreamOperatorFactory(UID_OP2, evQueue, cmdQueue)).setUidHash(UID_OP2);
    transform2.addSink(new DiscardingSink<>());
    return new TestJobWithDescription(env.getStreamGraph().getJobGraph(), emptySet(), emptySet(), emptySet(), emptyMap(), evQueue, cmdQueue);
}
Also used : TestEventSource(org.apache.flink.runtime.operators.lifecycle.graph.TestEventSource) TestEventQueue(org.apache.flink.runtime.operators.lifecycle.event.TestEventQueue) TestJobWithDescription(org.apache.flink.runtime.operators.lifecycle.TestJobWithDescription) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) TestCommandDispatcher(org.apache.flink.runtime.operators.lifecycle.command.TestCommandDispatcher) OneInputTestStreamOperatorFactory(org.apache.flink.runtime.operators.lifecycle.graph.OneInputTestStreamOperatorFactory) TestDataElement(org.apache.flink.runtime.operators.lifecycle.graph.TestDataElement)

Aggregations

TestJobWithDescription (org.apache.flink.runtime.operators.lifecycle.TestJobWithDescription)5 TestEvent (org.apache.flink.runtime.operators.lifecycle.event.TestEvent)4 String.format (java.lang.String.format)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 ArrayList (java.util.ArrayList)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 OperatorFinishedEvent (org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent)2 WatermarkReceivedEvent (org.apache.flink.runtime.operators.lifecycle.event.WatermarkReceivedEvent)2 BitSet (java.util.BitSet)1 Collection (java.util.Collection)1 ListIterator (java.util.ListIterator)1 NoSuchElementException (java.util.NoSuchElementException)1 Optional (java.util.Optional)1 Collectors.toList (java.util.stream.Collectors.toList)1