hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zjs...@apache.org
Subject [33/50] hadoop git commit: Add missing test file of YARN-3733
Date Mon, 08 Jun 2015 17:19:31 GMT
Add missing test file of YARN-3733


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/eba031e1
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/eba031e1
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/eba031e1

Branch: refs/heads/YARN-2928
Commit: eba031e1d13508bb62723625828fae267b043de1
Parents: 96a8d01
Author: Wangda Tan <wangda@apache.org>
Authored: Thu Jun 4 13:18:25 2015 -0700
Committer: Zhijie Shen <zjshen@apache.org>
Committed: Mon Jun 8 09:56:58 2015 -0700

----------------------------------------------------------------------
 .../util/resource/TestResourceCalculator.java   | 125 +++++++++++++++++++
 1 file changed, 125 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/eba031e1/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceCalculator.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..6a0b62e
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceCalculator.java
@@ -0,0 +1,125 @@
+/*
+ * 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.hadoop.yarn.util.resource;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class TestResourceCalculator {
+  private ResourceCalculator resourceCalculator;
+
+  @Parameterized.Parameters
+  public static Collection<ResourceCalculator[]> getParameters() {
+    return Arrays.asList(new ResourceCalculator[][] {
+        { new DefaultResourceCalculator() },
+        { new DominantResourceCalculator() } });
+  }
+
+  public TestResourceCalculator(ResourceCalculator rs) {
+    this.resourceCalculator = rs;
+  }
+
+  @Test(timeout = 10000)
+  public void testResourceCalculatorCompareMethod() {
+    Resource clusterResource = Resource.newInstance(0, 0);
+
+    // For lhs == rhs
+    Resource lhs = Resource.newInstance(0, 0);
+    Resource rhs = Resource.newInstance(0, 0);
+    assertResourcesOperations(clusterResource, lhs, rhs, false, true, false,
+        true, lhs, lhs);
+
+    // lhs > rhs
+    lhs = Resource.newInstance(1, 1);
+    rhs = Resource.newInstance(0, 0);
+    assertResourcesOperations(clusterResource, lhs, rhs, false, false, true,
+        true, lhs, rhs);
+
+    // For lhs < rhs
+    lhs = Resource.newInstance(0, 0);
+    rhs = Resource.newInstance(1, 1);
+    assertResourcesOperations(clusterResource, lhs, rhs, true, true, false,
+        false, rhs, lhs);
+
+    if (!(resourceCalculator instanceof DominantResourceCalculator)) {
+      return;
+    }
+
+    // verify for 2 dimensional resources i.e memory and cpu
+    // dominant resource types
+    lhs = Resource.newInstance(1, 0);
+    rhs = Resource.newInstance(0, 1);
+    assertResourcesOperations(clusterResource, lhs, rhs, false, true, false,
+        true, lhs, lhs);
+
+    lhs = Resource.newInstance(0, 1);
+    rhs = Resource.newInstance(1, 0);
+    assertResourcesOperations(clusterResource, lhs, rhs, false, true, false,
+        true, lhs, lhs);
+
+    lhs = Resource.newInstance(1, 1);
+    rhs = Resource.newInstance(1, 0);
+    assertResourcesOperations(clusterResource, lhs, rhs, false, false, true,
+        true, lhs, rhs);
+
+    lhs = Resource.newInstance(0, 1);
+    rhs = Resource.newInstance(1, 1);
+    assertResourcesOperations(clusterResource, lhs, rhs, true, true, false,
+        false, rhs, lhs);
+
+  }
+
+
+  private void assertResourcesOperations(Resource clusterResource,
+      Resource lhs, Resource rhs, boolean lessThan, boolean lessThanOrEqual,
+      boolean greaterThan, boolean greaterThanOrEqual, Resource max,
+      Resource min) {
+
+    Assert.assertEquals("Less Than operation is wrongly calculated.", lessThan,
+        Resources.lessThan(resourceCalculator, clusterResource, lhs, rhs));
+
+    Assert.assertEquals(
+        "Less Than Or Equal To operation is wrongly calculated.",
+        lessThanOrEqual, Resources.lessThanOrEqual(resourceCalculator,
+            clusterResource, lhs, rhs));
+
+    Assert.assertEquals("Greater Than operation is wrongly calculated.",
+        greaterThan,
+        Resources.greaterThan(resourceCalculator, clusterResource, lhs, rhs));
+
+    Assert.assertEquals(
+        "Greater Than Or Equal To operation is wrongly calculated.",
+        greaterThanOrEqual, Resources.greaterThanOrEqual(resourceCalculator,
+            clusterResource, lhs, rhs));
+
+    Assert.assertEquals("Max(value) Operation wrongly calculated.", max,
+        Resources.max(resourceCalculator, clusterResource, lhs, rhs));
+
+    Assert.assertEquals("Min(value) operation is wrongly calculated.", min,
+        Resources.min(resourceCalculator, clusterResource, lhs, rhs));
+  }
+
+}
\ No newline at end of file


Mime
View raw message