eaglewatcherwb commented on a change in pull request #8309: [FLINK-12229] 
[runtime] Implement LazyFromSourcesScheduling Strategy
URL: https://github.com/apache/flink/pull/8309#discussion_r283082955
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/strategy/LazyFromSourcesSchedulingStrategyTest.java
 ##########
 @@ -0,0 +1,342 @@
+/*
+ * 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.api.common.InputDependencyConstraint;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionID;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.runtime.scheduler.ExecutionVertexDeploymentOption;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.api.common.InputDependencyConstraint.ANY;
+import static 
org.apache.flink.runtime.io.network.partition.ResultPartitionType.BLOCKING;
+import static 
org.apache.flink.runtime.io.network.partition.ResultPartitionType.PIPELINED;
+import static 
org.apache.flink.runtime.scheduler.strategy.StrategyTestUtil.connectVerticesToPartition;
+import static 
org.apache.flink.runtime.scheduler.strategy.StrategyTestUtil.getExecutionVertexIdsFromDeployOptions;
+import static 
org.apache.flink.runtime.scheduler.strategy.StrategyTestUtil.initVerticesAndPartitions;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit tests for {@link LazyFromSourcesSchedulingStrategy}.
+ */
+public class LazyFromSourcesSchedulingStrategyTest extends TestLogger {
+
+       /**
+        * Tests that when start scheduling lazy from sources scheduling 
strategy will start input vertices in scheduling topology.
+        */
+       @Test
+       public void testStartScheduling() {
+               final int jobVertexCnt = 2;
+               final int taskCnt = 3;
+               TestingSchedulingTopology schedulingTopology = new 
TestingSchedulingTopology();
+               TestingSchedulingExecutionVertex[][] vertices = new 
TestingSchedulingExecutionVertex[jobVertexCnt][taskCnt];
+               TestingSchedulingResultPartition[][] partitions = new 
TestingSchedulingResultPartition[jobVertexCnt - 1][taskCnt];
+
+               ResultPartitionType[] partitionTypes = new 
ResultPartitionType[jobVertexCnt - 1];
+               InputDependencyConstraint[] inputDependencyConstraints = new 
InputDependencyConstraint[jobVertexCnt];
+               partitionTypes[0] = BLOCKING;
+               inputDependencyConstraints[0] = ANY;
+               inputDependencyConstraints[1] = ANY;
+
+               initVerticesAndPartitions(schedulingTopology, partitionTypes, 
inputDependencyConstraints, vertices, partitions);
+
+               for (int i = 0; i < taskCnt; i++) {
+                       for (int j = 0; j < taskCnt; j++) {
+                               connectVerticesToPartition(vertices[0][i], 
vertices[1][i], partitions[0][j]);
+                       }
+               }
+
+               TestingSchedulerOperations testingSchedulerOperation = new 
TestingSchedulerOperations();
+               LazyFromSourcesSchedulingStrategy schedulingStrategy = new 
LazyFromSourcesSchedulingStrategy(
+                       testingSchedulerOperation,
+                       schedulingTopology);
+
+               schedulingStrategy.startScheduling();
+
+               Set<ExecutionVertexID> toBeScheduledVertices = 
Arrays.stream(vertices[0])
+                       
.map(TestingSchedulingExecutionVertex::getId).collect(Collectors.toSet());
+               Collection<ExecutionVertexDeploymentOption> scheduledVertices = 
testingSchedulerOperation.getScheduledVertices().get(0);
+
+               
assertThat(getExecutionVertexIdsFromDeployOptions(scheduledVertices),
+                       containsInAnyOrder(toBeScheduledVertices.toArray()));
+       }
+
+       /**
+        * Tests that when restart tasks will only schedule input ready 
vertices in given ones.
+        */
+       @Test
+       public void testRestartTasks() {
+               final int jobVertexCnt = 2;
+               final int taskCnt = 3;
+               TestingSchedulingTopology schedulingTopology = new 
TestingSchedulingTopology();
+               TestingSchedulingExecutionVertex[][] vertices = new 
TestingSchedulingExecutionVertex[jobVertexCnt][taskCnt];
+               TestingSchedulingResultPartition[][] partitions = new 
TestingSchedulingResultPartition[jobVertexCnt - 1][taskCnt];
+
+               ResultPartitionType[] partitionTypes = new 
ResultPartitionType[jobVertexCnt - 1];
+               InputDependencyConstraint[] inputDependencyConstraints = new 
InputDependencyConstraint[jobVertexCnt];
+               partitionTypes[0] = BLOCKING;
+               inputDependencyConstraints[0] = ANY;
+               inputDependencyConstraints[1] = ANY;
+
+               initVerticesAndPartitions(schedulingTopology, partitionTypes, 
inputDependencyConstraints, vertices, partitions);
+
+               for (int i = 0; i < taskCnt; i++) {
+                       for (int j = 0; j < taskCnt; j++) {
+                               connectVerticesToPartition(vertices[0][i], 
vertices[1][i], partitions[0][j]);
+                       }
+               }
+
+               TestingSchedulerOperations testingSchedulerOperation = new 
TestingSchedulerOperations();
+               LazyFromSourcesSchedulingStrategy schedulingStrategy = new 
LazyFromSourcesSchedulingStrategy(
+                       testingSchedulerOperation,
+                       schedulingTopology);
+
+               schedulingStrategy.startScheduling();
+
+               Set<ExecutionVertexID> toBeScheduledVertices = 
Arrays.stream(vertices[0])
+                       
.map(TestingSchedulingExecutionVertex::getId).collect(Collectors.toSet());
+               Collection<ExecutionVertexDeploymentOption> scheduledVertices = 
testingSchedulerOperation.getScheduledVertices().get(0);
+               
assertThat(getExecutionVertexIdsFromDeployOptions(scheduledVertices),
+                       containsInAnyOrder(toBeScheduledVertices.toArray()));
+
+               Set<ExecutionVertexID> verticesToRestart = new HashSet<>();
+               for (TestingSchedulingExecutionVertex[] vArray : vertices) {
+                       for (TestingSchedulingExecutionVertex v : vArray) {
+                               verticesToRestart.add(v.getId());
+                       }
+               }
+               schedulingStrategy.restartTasks(verticesToRestart);
+               scheduledVertices = 
testingSchedulerOperation.getScheduledVertices().get(1);
+               
assertThat(getExecutionVertexIdsFromDeployOptions(scheduledVertices),
+                       containsInAnyOrder(toBeScheduledVertices.toArray()));
+       }
+
+       /**
+        * Tests that when partition consumable notified will start available 
{@link PIPELINED} downstream vertices.
+        */
+       @Test
+       public void testPIPELINEDPartitionConsumable() {
+               final int jobVertexCnt = 2;
+               final int taskCnt = 3;
+               TestingSchedulingTopology schedulingTopology = new 
TestingSchedulingTopology();
+               TestingSchedulingExecutionVertex[][] vertices = new 
TestingSchedulingExecutionVertex[jobVertexCnt][taskCnt];
+               TestingSchedulingResultPartition[][] partitions = new 
TestingSchedulingResultPartition[jobVertexCnt - 1][taskCnt];
+               ResultPartitionID[][] resultPartitionIds = new 
ResultPartitionID[jobVertexCnt - 1][taskCnt];
+               ResultPartitionType[] partitionTypes = new 
ResultPartitionType[jobVertexCnt - 1];
+               InputDependencyConstraint[] inputDependencyConstraints = new 
InputDependencyConstraint[jobVertexCnt];
+               partitionTypes[0] = PIPELINED;
+               inputDependencyConstraints[0] = ANY;
+               inputDependencyConstraints[1] = ANY;
+
+               initVerticesAndPartitions(schedulingTopology, partitionTypes, 
inputDependencyConstraints, vertices,
+                       resultPartitionIds, partitions);
+
+               for (int i = 0; i < taskCnt; i++) {
+                       for (int j = 0; j < taskCnt; j++) {
+                               connectVerticesToPartition(vertices[0][i], 
vertices[1][i], partitions[0][j]);
+                       }
+               }
+
+               TestingSchedulerOperations testingSchedulerOperation = new 
TestingSchedulerOperations();
+               LazyFromSourcesSchedulingStrategy schedulingStrategy = new 
LazyFromSourcesSchedulingStrategy(
+                       testingSchedulerOperation,
+                       schedulingTopology);
+
+               schedulingStrategy.startScheduling();
+
+               
schedulingStrategy.onExecutionStateChange(vertices[0][0].getId(), 
ExecutionState.RUNNING);
+               
schedulingStrategy.onExecutionStateChange(vertices[0][1].getId(), 
ExecutionState.RUNNING);
+               
schedulingStrategy.onExecutionStateChange(vertices[0][2].getId(), 
ExecutionState.RUNNING);
+
+               
schedulingStrategy.onPartitionConsumable(vertices[0][0].getId(), 
resultPartitionIds[0][0]);
+               Collection<ExecutionVertexDeploymentOption> scheduledVertices = 
testingSchedulerOperation.getScheduledVertices().get(1);
+               Set<ExecutionVertexID> toBeScheduledVertices = 
Arrays.stream(vertices[1])
+                       
.map(TestingSchedulingExecutionVertex::getId).collect(Collectors.toSet());
+               
assertThat(getExecutionVertexIdsFromDeployOptions(scheduledVertices),
+                       containsInAnyOrder(toBeScheduledVertices.toArray()));
+       }
+
+       /**
+        * Tests that when partition consumable notified will start available 
{@link BLOCKING} downstream vertices.
+        */
+       @Test
+       public void testBLOCKINGPointwiseExecutionStateChange() {
+               final int jobVertexCnt = 2;
+               final int taskCnt = 3;
+               TestingSchedulingTopology schedulingTopology = new 
TestingSchedulingTopology();
+               TestingSchedulingExecutionVertex[][] vertices = new 
TestingSchedulingExecutionVertex[jobVertexCnt][taskCnt];
+               TestingSchedulingResultPartition[][] partitions = new 
TestingSchedulingResultPartition[jobVertexCnt - 1][taskCnt];
+
+               ResultPartitionType[] partitionTypes = new 
ResultPartitionType[jobVertexCnt - 1];
+               InputDependencyConstraint[] inputDependencyConstraints = new 
InputDependencyConstraint[jobVertexCnt];
+               partitionTypes[0] = BLOCKING;
+               inputDependencyConstraints[0] = ANY;
+               inputDependencyConstraints[1] = ANY;
+
+               initVerticesAndPartitions(schedulingTopology, partitionTypes, 
inputDependencyConstraints, vertices, partitions);
+
+               for (int i = 0; i < taskCnt; i++) {
+                       connectVerticesToPartition(vertices[0][i], 
vertices[1][i], partitions[0][i]);
+               }
+
+               TestingSchedulerOperations testingSchedulerOperation = new 
TestingSchedulerOperations();
+               LazyFromSourcesSchedulingStrategy schedulingStrategy = new 
LazyFromSourcesSchedulingStrategy(
+                       testingSchedulerOperation,
+                       schedulingTopology);
+
+               schedulingStrategy.startScheduling();
+
+               
schedulingStrategy.onExecutionStateChange(vertices[0][0].getId(), 
ExecutionState.FINISHED);
+               
schedulingStrategy.onExecutionStateChange(vertices[0][1].getId(), 
ExecutionState.FINISHED);
+               
schedulingStrategy.onExecutionStateChange(vertices[0][2].getId(), 
ExecutionState.FINISHED);
+               Collection<ExecutionVertexDeploymentOption> scheduledVertices = 
testingSchedulerOperation.getScheduledVertices().get(1);
+               Set<ExecutionVertexID> toBeScheduledVertices = 
Arrays.stream(vertices[1])
+                       
.map(TestingSchedulingExecutionVertex::getId).collect(Collectors.toSet());
+               
assertThat(getExecutionVertexIdsFromDeployOptions(scheduledVertices),
+                       containsInAnyOrder(toBeScheduledVertices.toArray()));
+       }
+
+       /**
+        * Tests that when all the input partitions are ready will start 
available downstream {@link BLOCKING} vertices.
+        * vertex#0    vertex#1
+        *       \     /
+        *        \   /
+        *         \ /
+        *  (BLOCKING, ALL)
+        *     vertex#2
+        */
+       @Test
+       public void testBLOCKINGALLExecutionStateChange() {
+               final int jobVertexCnt = 3;
+               final int taskCnt = 2;
+               TestingSchedulingTopology schedulingTopology = new 
TestingSchedulingTopology();
+               TestingSchedulingExecutionVertex[][] vertices = new 
TestingSchedulingExecutionVertex[jobVertexCnt][taskCnt];
+               TestingSchedulingResultPartition[][] partitions = new 
TestingSchedulingResultPartition[jobVertexCnt - 1][taskCnt];
+
+               ResultPartitionType[] partitionTypes = new 
ResultPartitionType[jobVertexCnt - 1];
+               InputDependencyConstraint[] inputDependencyConstraints = new 
InputDependencyConstraint[jobVertexCnt];
+               partitionTypes[0] = BLOCKING;
+               partitionTypes[1] = BLOCKING;
+               inputDependencyConstraints[0] = ANY;
+               inputDependencyConstraints[1] = ANY;
+               inputDependencyConstraints[2] = InputDependencyConstraint.ALL;
+
+               initVerticesAndPartitions(schedulingTopology, partitionTypes, 
inputDependencyConstraints, vertices, partitions);
+
+               for (int i = 0; i < taskCnt; i++) {
+                       for (int j = 0; j < taskCnt; j++) {
+                               connectVerticesToPartition(vertices[0][i], 
vertices[2][i], partitions[0][j]);
 
 Review comment:
   OK

----------------------------------------------------------------
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

Reply via email to