tillrohrmann commented on a change in pull request #11353: [FLINK-16438][yarn] 
Make YarnResourceManager starts workers using WorkerResourceSpec requested by 
SlotManager
URL: https://github.com/apache/flink/pull/11353#discussion_r409595126
 
 

 ##########
 File path: 
flink-yarn/src/test/java/org/apache/flink/yarn/WorkerSpecContainerResourceAdapterTest.java
 ##########
 @@ -0,0 +1,213 @@
+/*
+ * 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.yarn;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.MemorySize;
+import org.apache.flink.configuration.TaskManagerOptions;
+import org.apache.flink.runtime.resourcemanager.WorkerResourceSpec;
+import org.apache.flink.util.TestLogger;
+
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link WorkerSpecContainerResourceAdapter}.
+ */
+public class WorkerSpecContainerResourceAdapterTest extends TestLogger {
+
+       @Test
+       public void testMatchVcores() {
+               final int minMemMB = 100;
+               final int minVcore = 10;
+               final WorkerSpecContainerResourceAdapter adapter =
+                       new WorkerSpecContainerResourceAdapter(
+                               getConfigProcessSpecEqualsWorkerSpec(),
+                               minMemMB,
+                               minVcore,
+                               Integer.MAX_VALUE,
+                               Integer.MAX_VALUE,
+                               
WorkerSpecContainerResourceAdapter.MatchingStrategy.MATCH_VCORE);
+
+               final WorkerResourceSpec workerSpec1 = new 
WorkerResourceSpec.Builder()
+                       .setCpuCores(1.0)
+                       .setTaskHeapMemoryMB(10)
+                       .setTaskOffHeapMemoryMB(10)
+                       .setNetworkMemoryMB(10)
+                       .setManagedMemoryMB(10)
+                       .build();
+               final WorkerResourceSpec workerSpec2 = new 
WorkerResourceSpec.Builder()
+                       .setCpuCores(10.0)
+                       .setTaskHeapMemoryMB(25)
+                       .setTaskOffHeapMemoryMB(25)
+                       .setNetworkMemoryMB(25)
+                       .setManagedMemoryMB(25)
+                       .build();
+               final WorkerResourceSpec workerSpec3 = new 
WorkerResourceSpec.Builder()
+                       .setCpuCores(5.0)
+                       .setTaskHeapMemoryMB(30)
+                       .setTaskOffHeapMemoryMB(30)
+                       .setNetworkMemoryMB(30)
+                       .setManagedMemoryMB(30)
+                       .build();
+               final WorkerResourceSpec workerSpec4 = new 
WorkerResourceSpec.Builder()
+                       .setCpuCores(15.0)
+                       .setTaskHeapMemoryMB(10)
+                       .setTaskOffHeapMemoryMB(10)
+                       .setNetworkMemoryMB(10)
+                       .setManagedMemoryMB(10)
+                       .build();
+
+               final Resource containerResource1 = Resource.newInstance(100, 
10);
+               final Resource containerResource2 = Resource.newInstance(200, 
10);
+               final Resource containerResource3 = Resource.newInstance(100, 
20);
+
+               assertThat(adapter.getWorkerSpecs(containerResource1), empty());
+               assertThat(adapter.getWorkerSpecs(containerResource2), empty());
+
+               assertThat(adapter.getContainerResource(workerSpec1).get(), 
is(containerResource1));
+               assertThat(adapter.getContainerResource(workerSpec2).get(), 
is(containerResource1));
+               assertThat(adapter.getContainerResource(workerSpec3).get(), 
is(containerResource2));
+               assertThat(adapter.getContainerResource(workerSpec4).get(), 
is(containerResource3));
+
+               assertThat(adapter.getWorkerSpecs(containerResource1), 
hasSize(2));
+               assertThat(adapter.getWorkerSpecs(containerResource2), 
hasSize(1));
+               assertThat(adapter.getWorkerSpecs(containerResource3), 
hasSize(1));
 
 Review comment:
   I think `contains` and `containsInAnyOrder` already do the size check 
meaning the that list must contain exactly as many items as matchers are 
specified.

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