tillrohrmann commented on a change in pull request #9760: 
[FLINK-13982][runtime] Implement memory calculation logics
URL: https://github.com/apache/flink/pull/9760#discussion_r329067007
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/clusterframework/TaskExecutorResourceUtilsTest.java
 ##########
 @@ -0,0 +1,323 @@
+package org.apache.flink.runtime.clusterframework;
+
+/*
+ * 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.
+ */
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.MemorySize;
+import org.apache.flink.configuration.TaskManagerOptions;
+import org.apache.flink.util.ConfigurationException;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
+
+import static org.hamcrest.Matchers.anyOf;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.lessThanOrEqualTo;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link TaskExecutorResourceUtils}.
+ */
+public class TaskExecutorResourceUtilsTest extends TestLogger {
+
+       static final MemorySize TASK_HEAP_SIZE = MemorySize.parse("100m");
+       static final MemorySize MANAGED_MEM_SIZE = MemorySize.parse("200m");
+       static final MemorySize TOTAL_FLINK_MEM_SIZE = MemorySize.parse("800m");
+       static final MemorySize TOTAL_PROCESS_MEM_SIZE = MemorySize.parse("1g");
+
+       static final TaskExecutorResourceSpec TM_RESOURCE_SPEC = new 
TaskExecutorResourceSpec(
+               MemorySize.parse("1m"),
+               MemorySize.parse("2m"),
+               MemorySize.parse("3m"),
+               MemorySize.parse("4m"),
+               MemorySize.parse("5m"),
+               MemorySize.parse("6m"),
+               MemorySize.parse("7m"),
+               MemorySize.parse("8m"));
+
+       @Test
+       public void testGenerateDynamicConfigurations() {
+               String dynamicConfigsStr = 
TaskExecutorResourceUtils.generateDynamicConfigsStr(TM_RESOURCE_SPEC);
+               Map<String, String> configs = new HashMap<>();
+               for (String configStr : dynamicConfigsStr.split(" ")) {
+                       assertThat(configStr, startsWith("-D"));
+                       String[] configKV = configStr.substring(2).split("=");
+                       assertThat(configKV.length, is(2));
+                       configs.put(configKV[0], configKV[1]);
+               }
+
+               
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.FRAMEWORK_HEAP_MEMORY.key())),
 is(TM_RESOURCE_SPEC.getFrameworkHeapSize()));
+               
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.TASK_HEAP_MEMORY.key())),
 is(TM_RESOURCE_SPEC.getTaskHeapSize()));
+               
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.TASK_OFF_HEAP_MEMORY.key())),
 is(TM_RESOURCE_SPEC.getTaskOffHeapSize()));
+               
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.SHUFFLE_MEMORY_MAX.key())),
 is(TM_RESOURCE_SPEC.getShuffleMemSize()));
+               
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.SHUFFLE_MEMORY_MIN.key())),
 is(TM_RESOURCE_SPEC.getShuffleMemSize()));
+               
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.MANAGED_MEMORY_SIZE.key())),
 is(TM_RESOURCE_SPEC.getManagedMemorySize()));
+               
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.MANAGED_MEMORY_OFFHEAP_SIZE.key())),
 is(TM_RESOURCE_SPEC.getOffHeapManagedMemorySize()));
+       }
+
+       @Test
+       public void testGenerateJvmParameters() throws Exception {
+               String jvmParamsStr = 
TaskExecutorResourceUtils.generateJvmParametersStr(TM_RESOURCE_SPEC);
+               MemorySize heapSizeMax = null;
+               MemorySize heapSizeMin = null;
+               MemorySize directSize = null;
+               MemorySize metaspaceSize = null;
+               for (String paramStr : jvmParamsStr.split(" ")) {
+                       if (paramStr.startsWith("-Xmx")) {
+                               heapSizeMax = 
MemorySize.parse(paramStr.substring("-Xmx".length()));
+                       } else if (paramStr.startsWith("-Xms")) {
+                               heapSizeMin = 
MemorySize.parse(paramStr.substring("-Xms".length()));
+                       } else if 
(paramStr.startsWith("-XX:MaxDirectMemorySize=")) {
+                               directSize = 
MemorySize.parse(paramStr.substring("-XX:MaxDirectMemorySize=".length()));
+                       } else if (paramStr.startsWith("-XX:MetaspaceSize=")) {
+                               metaspaceSize = 
MemorySize.parse(paramStr.substring("-XX:MetaspaceSize=".length()));
+                       } else {
+                               throw new Exception("Unknown JVM parameter: " + 
paramStr);
+                       }
+               }
+
+               assertThat(heapSizeMax, 
is(TM_RESOURCE_SPEC.getFrameworkHeapSize().add(TM_RESOURCE_SPEC.getTaskHeapSize()).add(TM_RESOURCE_SPEC.getOnHeapManagedMemorySize())));
+               assertThat(heapSizeMin, is(heapSizeMax));
+               assertThat(directSize, 
is(TM_RESOURCE_SPEC.getTaskOffHeapSize().add(TM_RESOURCE_SPEC.getShuffleMemSize())));
 
 Review comment:
   off heap managed memory is missing

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