zhuzhurk commented on a change in pull request #10462: [FLINK-15031][runtime] 
Calculate required shuffle memory before allocating slots if resources are 
specified
URL: https://github.com/apache/flink/pull/10462#discussion_r355131776
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/ResourceRequirementsRetrieverTest.java
 ##########
 @@ -0,0 +1,207 @@
+/*
+ * 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;
+
+import org.apache.flink.api.common.operators.ResourceSpec;
+import org.apache.flink.configuration.MemorySize;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.executiongraph.ExecutionGraph;
+import org.apache.flink.runtime.executiongraph.ExecutionJobVertex;
+import org.apache.flink.runtime.executiongraph.TestingExecutionGraphBuilder;
+import org.apache.flink.runtime.instance.SlotSharingGroupId;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.runtime.jobgraph.DistributionPattern;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobgraph.JobVertex;
+import org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup;
+import org.apache.flink.runtime.shuffle.PartitionDescriptor;
+import org.apache.flink.runtime.shuffle.ProducerDescriptor;
+import org.apache.flink.runtime.shuffle.ShuffleDescriptor;
+import org.apache.flink.runtime.shuffle.ShuffleMaster;
+import org.apache.flink.runtime.shuffle.TaskInputsOutputsDescriptor;
+import org.apache.flink.runtime.testtasks.NoOpInvokable;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for {@link ResourceRequirementsRetriever}.
+ */
+public class ResourceRequirementsRetrieverTest {
+
+       private static final int OFFSET = 1000;
+
+       private static final ResourceSpec DEFAULT_RESOURCES = 
ResourceSpec.newBuilder(1.0, 100).build();
+
+       private static final TestShuffleMaster SHUFFLE_MASTER = new 
TestShuffleMaster();
+
+       private JobGraph jobGraph;
+
+       private ExecutionGraph executionGraph;
+
+       private List<SlotSharingGroup> slotSharingGroups;
+
+       private ResourceRequirementsRetriever resourceRequirementsRetriever;
+
+       @Test
+       public void testJobVertexResourceRequirements() throws Exception {
+               setUp(DEFAULT_RESOURCES);
+
+               final List<JobVertex> jobVertices = 
jobGraph.getVerticesSortedTopologicallyFromSources();
+               final ExecutionJobVertex source = 
executionGraph.getJobVertex(jobVertices.get(0).getID());
+               final ExecutionJobVertex map = 
executionGraph.getJobVertex(jobVertices.get(1).getID());
+               final ExecutionJobVertex sink = 
executionGraph.getJobVertex(jobVertices.get(2).getID());
+
+               assertEquals(
+                       ResourceProfile.fromResourceSpec(DEFAULT_RESOURCES, new 
MemorySize(0 * OFFSET + 2)),
+                       
resourceRequirementsRetriever.getJobVertexResourceRequirement(source.getJobVertexId()));
+
+               assertEquals(
+                       ResourceProfile.fromResourceSpec(DEFAULT_RESOURCES, new 
MemorySize(1 * OFFSET + 6)),
+                       
resourceRequirementsRetriever.getJobVertexResourceRequirement(map.getJobVertexId()));
+
+               assertEquals(
+                       ResourceProfile.fromResourceSpec(DEFAULT_RESOURCES, new 
MemorySize(5 * OFFSET + 0)),
+                       
resourceRequirementsRetriever.getJobVertexResourceRequirement(sink.getJobVertexId()));
 
 Review comment:
   Will extract the memory computing into a method for tests to directly get 
expected result, so that we can hide the computing details (like the OFFSET).

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to