pnowojski commented on a change in pull request #16773: URL: https://github.com/apache/flink/pull/16773#discussion_r688602701
########## File path: flink-tests/src/test/java/org/apache/flink/runtime/operators/lifecycle/validation/TestJobDataFlowValidator.java ########## @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.runtime.operators.lifecycle.validation; + +import org.apache.flink.runtime.OperatorIDPair; +import org.apache.flink.runtime.jobgraph.IntermediateDataSet; +import org.apache.flink.runtime.jobgraph.JobEdge; +import org.apache.flink.runtime.jobgraph.JobVertex; +import org.apache.flink.runtime.operators.lifecycle.TestJobWithDescription; +import org.apache.flink.runtime.operators.lifecycle.event.OperatorFinishedEvent; +import org.apache.flink.runtime.operators.lifecycle.event.TestEvent; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collection; +import java.util.HashMap; +import java.util.ListIterator; +import java.util.Map; +import java.util.Optional; + +import static java.lang.String.format; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** Check that all data from the upstream reached the respective downstreams. */ +public class TestJobDataFlowValidator { + private static final Logger LOG = LoggerFactory.getLogger(TestJobDataFlowValidator.class); + + public static void checkDataFlow(TestJobWithDescription testJob) { + 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()) { + for (JobEdge edge : produced.getConsumers()) { + Optional<String> upstreamID = getTrackedOperatorID(upstream, true, testJob); + Optional<String> downstreamID = + getTrackedOperatorID(edge.getTarget(), false, testJob); + if (upstreamID.isPresent() && downstreamID.isPresent()) { + checkDataFlow(upstreamID.get(), downstreamID.get(), edge, finishEvents); + } else { + LOG.debug("Ignoring edge (untracked operator): {}", edge); + } + } + } + } + } + + /** + * Check that for each upstream subtask there exists a downstream subtask that received it's + * latest emitted element. + */ + private static void checkDataFlow( + String upstreamID, + String downstreamID, + JobEdge edge, + Map<String, Map<Integer, OperatorFinishedEvent>> finishEvents) { + LOG.debug( + "Checking {} edge\n from {} ({})\n to {} ({})", + edge.getDistributionPattern(), + edge.getSource().getProducer().getName(), + upstreamID, + edge.getTarget().getName(), + downstreamID); + + Map<Integer, OperatorFinishedEvent> downstreamFinishInfo = + getForOperator(downstreamID, finishEvents); + + Map<Integer, OperatorFinishedEvent> upstreamFinishInfo = + getForOperator(upstreamID, finishEvents); + + upstreamFinishInfo.forEach( + (upstreamIndex, upstreamInfo) -> + assertTrue( + anySubtaskReceived( + upstreamID, + upstreamIndex, + upstreamInfo.lastSent, + downstreamFinishInfo.values()))); Review comment: can you expand the error message a bit? I had a failure from this error message and I had no idea what has failed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
