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_r355133204
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/shuffle/NettyShuffleMasterTest.java ########## @@ -0,0 +1,65 @@ +/* + * 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.shuffle; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.configuration.MemorySize; +import org.apache.flink.configuration.NettyShuffleEnvironmentOptions; +import org.apache.flink.configuration.TaskManagerOptions; +import org.apache.flink.runtime.jobgraph.IntermediateDataSetID; +import org.apache.flink.util.TestLogger; + +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +/** + * Tests for {@link NettyShuffleMaster}. + */ +public class NettyShuffleMasterTest extends TestLogger { + + @Test + public void testGetShuffleMemoryForTask() { + final Configuration configuration = new Configuration(); + configuration.setInteger(NettyShuffleEnvironmentOptions.NETWORK_BUFFERS_PER_CHANNEL, 10); + configuration.setString(TaskManagerOptions.MEMORY_SEGMENT_SIZE, "4096"); + + final NettyShuffleMaster shuffleMaster = new NettyShuffleMaster(configuration); + + final Map<IntermediateDataSetID, Integer> numbersOfInputGateChannels = new HashMap<IntermediateDataSetID, Integer>() {{ + put(new IntermediateDataSetID(), 1); + put(new IntermediateDataSetID(), 2); + }}; + final Map<IntermediateDataSetID, Integer> numbersOfResultSubpartitions = new HashMap<IntermediateDataSetID, Integer>() {{ + put(new IntermediateDataSetID(), 3); + put(new IntermediateDataSetID(), 4); + }}; + + final TaskInputsOutputsDescriptor inputsOutputsDescriptor = TaskInputsOutputsDescriptor.from( + numbersOfInputGateChannels, + numbersOfResultSubpartitions); + + assertEquals( + new MemorySize(4096 * (10 * (1 + 2) + (3 + 1) + (4 + 1))), Review comment: done by introducing a common method `NettyShuffleUtils.computeRequiredNetworkBuffers` which can be used both for production and tests. `computeRequiredNetworkBuffers` itself is verified with `NettyShuffleUtilsTest#testComputeRequiredNetworkBuffers`, which ensures the shuffle master/envrionment contract is not broken. ---------------------------------------------------------------- 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
