diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index e90155f675..6ff60447e1 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -37,6 +37,8 @@ Release 2.2.0 - UNRELEASED IMPROVEMENTS + YARN-866. Add test for class ResourceWeights. (ywskycn via tucu) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceWeights.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceWeights.java new file mode 100644 index 0000000000..c80e256d54 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceWeights.java @@ -0,0 +1,55 @@ +/** + * 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.server.resourcemanager.resource; + +import junit.framework.Assert; + +import org.junit.Test; + +public class TestResourceWeights { + + @Test(timeout=3000) + public void testWeights() { + ResourceWeights rw1 = new ResourceWeights(); + Assert.assertEquals("Default CPU weight should be 0.0f.", 0.0f, + rw1.getWeight(ResourceType.CPU), 0.00001f); + Assert.assertEquals("Default memory weight should be 0.0f", 0.0f, + rw1.getWeight(ResourceType.MEMORY), 0.00001f); + + ResourceWeights rw2 = new ResourceWeights(2.0f); + Assert.assertEquals("The CPU weight should be 2.0f.", 2.0f, + rw2.getWeight(ResourceType.CPU), 0.00001f); + Assert.assertEquals("The memory weight should be 2.0f", 2.0f, + rw2.getWeight(ResourceType.MEMORY), 0.00001f); + + // set each individually + ResourceWeights rw3 = new ResourceWeights(1.5f, 2.0f); + Assert.assertEquals("The CPU weight should be 2.0f", 2.0f, + rw3.getWeight(ResourceType.CPU), 0.00001f); + Assert.assertEquals("The memory weight should be 1.5f", 1.5f, + rw3.getWeight(ResourceType.MEMORY), 0.00001f); + + // reset weights + rw3.setWeight(ResourceType.CPU, 2.5f); + Assert.assertEquals("The CPU weight should be set to 2.5f.", 2.5f, + rw3.getWeight(ResourceType.CPU), 0.00001f); + rw3.setWeight(ResourceType.MEMORY, 4.0f); + Assert.assertEquals("The memory weight should be set to 4.0f.", 4.0f, + rw3.getWeight(ResourceType.MEMORY), 0.00001f); + } +} \ No newline at end of file