YARN-10072: TestCSAllocateCustomResource failures. Contributed by Jim Brennan (Jim_Brennan)

(cherry picked from commit 6899be5a17)
This commit is contained in:
Eric E Payne 2020-01-08 17:29:56 +00:00
parent ee7c56c6de
commit b20ce118da
1 changed files with 9 additions and 25 deletions

View File

@ -19,17 +19,14 @@
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.hadoop.yarn.LocalConfigurationProvider;
import org.apache.hadoop.yarn.api.records.ContainerId; import org.apache.hadoop.yarn.api.records.ContainerId;
import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.Resource;
import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.server.resourcemanager.MockAM; import org.apache.hadoop.yarn.server.resourcemanager.MockAM;
import org.apache.hadoop.yarn.server.resourcemanager.MockNM; import org.apache.hadoop.yarn.server.resourcemanager.MockNM;
import org.apache.hadoop.yarn.server.resourcemanager.MockRM; import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
import org.apache.hadoop.yarn.server.resourcemanager.RMContext;
import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager; import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager;
import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
import org.apache.hadoop.yarn.server.resourcemanager.placement.PlacementManager;
import org.apache.hadoop.yarn.server.resourcemanager.resource.TestResourceProfiles; import org.apache.hadoop.yarn.server.resourcemanager.resource.TestResourceProfiles;
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode;
@ -50,9 +47,6 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.MAXIMUM_ALLOCATION_MB; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.MAXIMUM_ALLOCATION_MB;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
/** /**
* Test case for custom resource container allocation. * Test case for custom resource container allocation.
@ -157,37 +151,27 @@ public class TestCSAllocateCustomResource {
resourceTypesFile = new File(source.getParent(), "resource-types.xml"); resourceTypesFile = new File(source.getParent(), "resource-types.xml");
FileUtils.copyFile(source, resourceTypesFile); FileUtils.copyFile(source, resourceTypesFile);
CapacityScheduler cs = new CapacityScheduler(); CapacitySchedulerConfiguration newConf =
CapacityScheduler spyCS = spy(cs);
CapacitySchedulerConfiguration csConf =
(CapacitySchedulerConfiguration) TestUtils (CapacitySchedulerConfiguration) TestUtils
.getConfigurationWithMultipleQueues(conf); .getConfigurationWithMultipleQueues(conf);
csConf.setClass(CapacitySchedulerConfiguration.RESOURCE_CALCULATOR_CLASS, newConf.setClass(CapacitySchedulerConfiguration.RESOURCE_CALCULATOR_CLASS,
DominantResourceCalculator.class, ResourceCalculator.class); DominantResourceCalculator.class, ResourceCalculator.class);
spyCS.setConf(csConf); //start RM
MockRM rm = new MockRM(newConf);
rm.start();
RMNodeLabelsManager nodeLabelsManager = new NullRMNodeLabelsManager(); CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler();
nodeLabelsManager.init(csConf);
PlacementManager pm = new PlacementManager();
RMContext mockContext = mock(RMContext.class);
when(mockContext.getConfigurationProvider()).thenReturn(
new LocalConfigurationProvider());
mockContext.setNodeLabelManager(nodeLabelsManager);
when(mockContext.getNodeLabelManager()).thenReturn(nodeLabelsManager);
when(mockContext.getQueuePlacementManager()).thenReturn(pm);
spyCS.setRMContext(mockContext);
spyCS.init(csConf);
// Ensure the method can get custom resource type from // Ensure the method can get custom resource type from
// CapacitySchedulerConfiguration // CapacitySchedulerConfiguration
Assert.assertNotEquals(0, Assert.assertNotEquals(0,
ResourceUtils ResourceUtils
.fetchMaximumAllocationFromConfig(spyCS.getConfiguration()) .fetchMaximumAllocationFromConfig(cs.getConfiguration())
.getResourceValue("yarn.io/gpu")); .getResourceValue("yarn.io/gpu"));
// Ensure custom resource type exists in queue's maximumAllocation // Ensure custom resource type exists in queue's maximumAllocation
Assert.assertNotEquals(0, Assert.assertNotEquals(0,
spyCS.getMaximumResourceCapability("a") cs.getMaximumResourceCapability("a")
.getResourceValue("yarn.io/gpu")); .getResourceValue("yarn.io/gpu"));
rm.close();
} }
} }