GJL commented on a change in pull request #8309: [FLINK-12229] [runtime] Implement LazyFromSourcesScheduling Strategy URL: https://github.com/apache/flink/pull/8309#discussion_r284881460
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/strategy/LazyFromSourcesSchedulingStrategyTest.java ########## @@ -0,0 +1,230 @@ +/* + * 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.scheduler.strategy; + +import org.apache.flink.runtime.execution.ExecutionState; +import org.apache.flink.runtime.executiongraph.ExecutionAttemptID; +import org.apache.flink.runtime.io.network.partition.ResultPartitionID; +import org.apache.flink.util.TestLogger; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeDiagnosingMatcher; +import org.junit.Test; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.apache.flink.api.common.InputDependencyConstraint.ALL; +import static org.apache.flink.runtime.io.network.partition.ResultPartitionType.PIPELINED; +import static org.apache.flink.runtime.scheduler.strategy.StrategyTestUtil.getExecutionVertexIdsFromDeployOptions; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.junit.Assert.assertThat; + +/** + * Unit tests for {@link LazyFromSourcesSchedulingStrategy}. + */ +public class LazyFromSourcesSchedulingStrategyTest extends TestLogger { + + private TestingSchedulerOperations testingSchedulerOperation = new TestingSchedulerOperations(); + + /** + * Tests that when start scheduling lazy from sources scheduling strategy will start input vertices in scheduling topology. + */ + @Test + public void testStartScheduling() { + final TestingSchedulingTopology testingSchedulingTopology = new TestingSchedulingTopology(); + + final List<TestingSchedulingExecutionVertex> producers = testingSchedulingTopology.addExecutionVertices().finish(); + final List<TestingSchedulingExecutionVertex> consumers = testingSchedulingTopology.addExecutionVertices().finish(); + testingSchedulingTopology.connectAllToAll(producers, consumers).finish(); + + startScheduling(testingSchedulingTopology); + + assertThat(testingSchedulerOperation, hasScheduledVertices(producers)); + } + + /** + * Tests that when restart tasks will only schedule input ready vertices in given ones. + */ + @Test + public void testRestartTasks() { + final TestingSchedulingTopology testingSchedulingTopology = new TestingSchedulingTopology(); + + final List<TestingSchedulingExecutionVertex> producers = testingSchedulingTopology.addExecutionVertices().finish(); + final List<TestingSchedulingExecutionVertex> consumers = testingSchedulingTopology.addExecutionVertices().finish(); + testingSchedulingTopology.connectAllToAll(producers, consumers).finish(); + + LazyFromSourcesSchedulingStrategy schedulingStrategy = startScheduling(testingSchedulingTopology); + + assertThat(testingSchedulerOperation, hasScheduledVertices(producers)); + + Set<ExecutionVertexID> verticesToRestart = producers.stream().map(TestingSchedulingExecutionVertex::getId) + .collect(Collectors.toSet()); + verticesToRestart.addAll(consumers.stream().map( + TestingSchedulingExecutionVertex::getId).collect(Collectors.toSet())); + + schedulingStrategy.restartTasks(verticesToRestart); + assertThat(testingSchedulerOperation, hasScheduledVertices(producers)); + } + Review comment: Strictly speaking we are missing some tests for `restartTasks()`. For example, we are not testing that a vertex should be scheduled if the partition is `PIPELINED` and in status `PRODUCING`. I think testing all combinations/branches from within `LazyFromSourcesSchedulingStrategyTest` will be difficult. I thought about extracting the `InputDependencyConstraint` checking into an extra class, which then can be tested in isolation. Find below an outline of what I mean: ``` class InputDependencyConstraintTester { private final SchedulingIntermediateDataSetManager schedulingIntermediateDataSetManager; public boolean test(final SchedulingExecutionVertex schedulingExecutionVertex) { if (schedulingExecutionVertex.getInputDependencyConstraint() == InputDependencyConstraint.ALL) { return testAll(schedulingExecutionVertex); } else if (schedulingExecutionVertex.getInputDependencyConstraint() == InputDependencyConstraint.ANY) { return testAny(schedulingExecutionVertex); } else { throw new IllegalArgumentException(); } } private static boolean testAll(final SchedulingExecutionVertex schedulingExecutionVertex) { return schedulingExecutionVertex.getConsumedResultPartitions() .stream() .allMatch(this::partitionConsumable); } private static boolean testAny(final SchedulingExecutionVertex schedulingExecutionVertex) { return schedulingExecutionVertex.getConsumedResultPartitions() .stream() .anyMatch(this::partitionConsumable); } private boolean partitionConsumable(SchedulingResultPartition partition) { // ... } } class SchedulingIntermediateDataSetManager { private final Map<IntermediateDataSetID, SchedulingIntermediateDataSet> intermediateDataSets = new HashMap<>(); // throws exception if dataset does not exist public SchedulingIntermediateDataSet getSchedulingIntermediateDataSet(final IntermediateDataSetID intermediateDataSetID); } ``` I haven't tried whether this actually works. Let me know what you think. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services