tillrohrmann commented on a change in pull request #10946: 
[FLINK-15763][Runtime] Running TM checks only necessary resource cofig, set to 
default for local execution
URL: https://github.com/apache/flink/pull/10946#discussion_r370944521
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorResourceUtilsTest.java
 ##########
 @@ -0,0 +1,118 @@
+/*
+ * 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.taskexecutor;
+
+import org.apache.flink.api.common.resources.CPUResource;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.IllegalConfigurationException;
+import org.apache.flink.configuration.MemorySize;
+import org.apache.flink.configuration.TaskManagerOptions;
+import org.apache.flink.util.TestLogger;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
+
+/** Test suite for {@link TaskExecutorResourceUtils}. */
+public class TaskExecutorResourceUtilsTest extends TestLogger {
+       @Test
+       public void testResourceSpecFromConfig() {
+               double cpuCores = 1.0;
+               MemorySize taskHeap = MemorySize.ofMebiBytes(1);
+               MemorySize taskOffHeap = MemorySize.ofMebiBytes(2);
+               MemorySize network = MemorySize.ofMebiBytes(3);
+               MemorySize managed = MemorySize.ofMebiBytes(4);
+
+               Configuration configuration = new Configuration();
+               configuration.set(TaskManagerOptions.CPU_CORES, cpuCores);
+               configuration.set(TaskManagerOptions.TASK_HEAP_MEMORY, 
taskHeap);
+               configuration.set(TaskManagerOptions.TASK_OFF_HEAP_MEMORY, 
taskOffHeap);
+               configuration.set(TaskManagerOptions.NETWORK_MEMORY_MIN, 
network);
+               configuration.set(TaskManagerOptions.NETWORK_MEMORY_MAX, 
network);
+               configuration.set(TaskManagerOptions.MANAGED_MEMORY_SIZE, 
managed);
+
+               TaskExecutorResourceSpec resourceSpec = 
TaskExecutorResourceUtils.resourceSpecFromConfig(configuration);
+
+               assertThat(resourceSpec.getCpuCores(), is(new 
CPUResource(cpuCores)));
+               assertThat(resourceSpec.getTaskHeapSize(), is(taskHeap));
+               assertThat(resourceSpec.getTaskOffHeapSize(), is(taskOffHeap));
+               assertThat(resourceSpec.getNetworkMemSize(), is(network));
+               assertThat(resourceSpec.getManagedMemorySize(), is(managed));
+       }
+
+       @Test
+       public void testResourceSpecFromConfigFailsIfRequiredOptionIsNotSet() {
+               TaskExecutorResourceUtils.CONFIG_OPTIONS.forEach(option -> {
+                       try {
+                               
TaskExecutorResourceUtils.resourceSpecFromConfig(setAllRequiredOptionsExceptOne(option));
+                               fail("should fail with " + 
IllegalConfigurationException.class.getSimpleName());
+                       } catch (IllegalConfigurationException e) {
+                               // expected
+                       }
+               });
+       }
+
+       private static Configuration 
setAllRequiredOptionsExceptOne(ConfigOption<?> optionToNotSet) {
+               Configuration configuration = new Configuration();
+               if (!TaskManagerOptions.CPU_CORES.equals(optionToNotSet)) {
+                       configuration.set(TaskManagerOptions.CPU_CORES, 1.0);
+               }
+
+               //noinspection unchecked
+               TaskExecutorResourceUtils.CONFIG_OPTIONS
+                       .stream()
+                       .filter(option -> 
option.equals(TaskManagerOptions.CPU_CORES))
+                       .filter(option -> option.equals(optionToNotSet))
 
 Review comment:
   same here. The negation 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