hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snem...@apache.org
Subject [hadoop] branch trunk updated: YARN-9356. Add more tests to ratio method in TestResourceCalculator. Contributed by Zoltan Siegl
Date Wed, 09 Oct 2019 11:16:45 GMT
This is an automated email from the ASF dual-hosted git repository.

snemeth pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 35f093f  YARN-9356. Add more tests to ratio method in TestResourceCalculator. Contributed
by Zoltan Siegl
35f093f is described below

commit 35f093f5b3f310af49a8bb476e62173862f5af51
Author: Szilard Nemeth <snemeth@apache.org>
AuthorDate: Wed Oct 9 13:09:09 2019 +0200

    YARN-9356. Add more tests to ratio method in TestResourceCalculator. Contributed by Zoltan
Siegl
---
 .../yarn/util/resource/TestResourceCalculator.java | 47 ++++++++++++++++++++--
 1 file changed, 44 insertions(+), 3 deletions(-)

diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceCalculator.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceCalculator.java
index df4a9b8..f1c8c89 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceCalculator.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceCalculator.java
@@ -36,6 +36,8 @@ import static org.junit.Assert.assertEquals;
 
 @RunWith(Parameterized.class)
 public class TestResourceCalculator {
+  private static final String EXTRA_RESOURCE_NAME = "test";
+
   private final ResourceCalculator resourceCalculator;
 
   @Parameterized.Parameters(name = "{0}")
@@ -55,7 +57,7 @@ public class TestResourceCalculator {
   private static void setupExtraResource() {
     Configuration conf = new Configuration();
 
-    conf.set(YarnConfiguration.RESOURCE_TYPES, "test");
+    conf.set(YarnConfiguration.RESOURCE_TYPES, EXTRA_RESOURCE_NAME);
     ResourceUtils.resetResourceTypes(conf);
   }
 
@@ -97,10 +99,10 @@ public class TestResourceCalculator {
     return res;
   }
 
-  private Resource newResource(long memory, int cpu, int test) {
+  private Resource newResource(long memory, int cpu, int extraResource) {
     Resource res = newResource(memory, cpu);
 
-    res.setResourceValue("test", test);
+    res.setResourceValue(EXTRA_RESOURCE_NAME, extraResource);
 
     return res;
   }
@@ -548,4 +550,43 @@ public class TestResourceCalculator {
               newResource(1, 1)));
     }
   }
+
+  @Test
+  public void testRatioWithNoExtraResource() {
+    //setup
+    Resource resource1 = newResource(1, 1);
+    Resource resource2 = newResource(2, 1);
+
+    //act
+    float ratio = resourceCalculator.ratio(resource1, resource2);
+
+    //assert
+    if (resourceCalculator instanceof DefaultResourceCalculator) {
+      double ratioOfMemories = 0.5;
+      assertEquals(ratioOfMemories, ratio, 0.00001);
+    } else if (resourceCalculator instanceof DominantResourceCalculator) {
+      double ratioOfCPUs = 1.0;
+      assertEquals(ratioOfCPUs, ratio, 0.00001);
+    }
+  }
+
+  @Test
+  public void testRatioWithExtraResource() {
+    //setup
+    setupExtraResource();
+    Resource resource1 = newResource(1, 1, 2);
+    Resource resource2 = newResource(2, 1, 1);
+
+    //act
+    float ratio = resourceCalculator.ratio(resource1, resource2);
+
+    //assert
+    if (resourceCalculator instanceof DefaultResourceCalculator) {
+      double ratioOfMemories = 0.5;
+      assertEquals(ratioOfMemories, ratio, 0.00001);
+    } else if (resourceCalculator instanceof DominantResourceCalculator) {
+      double ratioOfExtraResources = 2.0;
+      assertEquals(ratioOfExtraResources, ratio, 0.00001);
+    }
+  }
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message