diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservations.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservations.java index a9cee2ddcb..1168f64802 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservations.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservations.java @@ -105,7 +105,6 @@ public void setUp() throws Exception { CapacityScheduler spyCs = new CapacityScheduler(); cs = spy(spyCs); rmContext = TestUtils.getMockRMContext(); - } private void setup(CapacitySchedulerConfiguration csConf) throws Exception { @@ -114,6 +113,9 @@ private void setup(CapacitySchedulerConfiguration csConf) throws Exception { private void setup(CapacitySchedulerConfiguration csConf, boolean addUserLimits) throws Exception { + //All stub calls on the spy object of the 'cs' field should happen + //before cs.start() is invoked. See YARN-10672 for more details. + when(cs.getNumClusterNodes()).thenReturn(3); csConf.setBoolean(CapacitySchedulerConfiguration.ENABLE_USER_METRICS, true); final String newRoot = "root" + System.currentTimeMillis(); @@ -156,8 +158,6 @@ private void setup(CapacitySchedulerConfiguration csConf, cs.setRMContext(spyRMContext); cs.init(csConf); cs.start(); - - when(cs.getNumClusterNodes()).thenReturn(3); } private static final String A = "a";