Skip to content

Commit ec2547d

Browse files
committed
YARN-11036. Do not inherit from TestRMWebServicesCapacitySched
Change-Id: I48e5b1e020d5cc6fb5ae4a7edc38e9212f4f069b
1 parent a94e9fc commit ec2547d

File tree

3 files changed

+73
-70
lines changed

3 files changed

+73
-70
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesCapacitySched.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,42 +77,37 @@
7777

7878
public class TestRMWebServicesCapacitySched extends JerseyTestBase {
7979

80-
protected static MockRM rm;
80+
private MockRM rm;
81+
82+
public static class WebServletModule extends ServletModule {
83+
private final MockRM rm;
84+
85+
WebServletModule(MockRM rm) {
86+
this.rm = rm;
87+
}
8188

82-
private static class WebServletModule extends ServletModule {
8389
@Override
8490
protected void configureServlets() {
8591
bind(JAXBContextResolver.class);
8692
bind(RMWebServices.class);
8793
bind(GenericExceptionHandler.class);
88-
CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(
89-
new Configuration(false));
90-
setupQueueConfiguration(csConf);
91-
YarnConfiguration conf = new YarnConfiguration(csConf);
92-
conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
93-
ResourceScheduler.class);
94-
conf.set(YarnConfiguration.RM_PLACEMENT_CONSTRAINTS_HANDLER,
95-
YarnConfiguration.SCHEDULER_RM_PLACEMENT_CONSTRAINTS_HANDLER);
96-
rm = new MockRM(conf);
9794
bind(ResourceManager.class).toInstance(rm);
9895
serve("/*").with(GuiceContainer.class);
9996
}
10097
}
10198

10299
public TestRMWebServicesCapacitySched() {
103-
super(new WebAppDescriptor.Builder(
104-
"org.apache.hadoop.yarn.server.resourcemanager.webapp")
105-
.contextListenerClass(GuiceServletConfig.class)
106-
.filterClass(com.google.inject.servlet.GuiceFilter.class)
107-
.contextPath("jersey-guice-filter").servletPath("/").build());
100+
super(createWebAppDescriptor());
108101
}
109102

110103
@Before
111104
@Override
112105
public void setUp() throws Exception {
113106
super.setUp();
107+
rm = createMockRM(new CapacitySchedulerConfiguration(
108+
new Configuration(false)));
114109
GuiceServletConfig.setInjector(
115-
Guice.createInjector(new WebServletModule()));
110+
Guice.createInjector(new WebServletModule(rm)));
116111
}
117112

118113
public static void setupQueueConfiguration(
@@ -389,4 +384,22 @@ public static void updateTestDataAutomatically(String configFilename, String act
389384
Assert.fail("overwrite should not fail " + e.getMessage());
390385
}
391386
}
387+
388+
public static WebAppDescriptor createWebAppDescriptor() {
389+
return new WebAppDescriptor.Builder(
390+
"org.apache.hadoop.yarn.server.resourcemanager.webapp")
391+
.contextListenerClass(GuiceServletConfig.class)
392+
.filterClass(com.google.inject.servlet.GuiceFilter.class)
393+
.contextPath("jersey-guice-filter").servletPath("/").build();
394+
}
395+
396+
public static MockRM createMockRM(CapacitySchedulerConfiguration csConf) {
397+
setupQueueConfiguration(csConf);
398+
YarnConfiguration conf = new YarnConfiguration(csConf);
399+
conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
400+
ResourceScheduler.class);
401+
conf.set(YarnConfiguration.RM_PLACEMENT_CONSTRAINTS_HANDLER,
402+
YarnConfiguration.SCHEDULER_RM_PLACEMENT_CONSTRAINTS_HANDLER);
403+
return new MockRM(conf);
404+
}
392405
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesCapacitySchedDynamicConfig.java

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
package org.apache.hadoop.yarn.server.resourcemanager.webapp;
2020

2121
import com.google.inject.Guice;
22-
import com.google.inject.servlet.ServletModule;
2322
import com.sun.jersey.api.client.ClientResponse;
24-
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
25-
import com.sun.jersey.test.framework.WebAppDescriptor;
2623

2724
import java.io.IOException;
2825
import java.util.HashMap;
@@ -34,67 +31,28 @@
3431
import org.apache.hadoop.yarn.conf.YarnConfiguration;
3532
import org.apache.hadoop.yarn.exceptions.YarnException;
3633
import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
37-
import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
38-
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
3934
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
4035
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
4136
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
4237
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager;
4338
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
44-
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
4539
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
4640
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
4741
import org.junit.Test;
4842

43+
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.GB;
4944
import static org.apache.hadoop.yarn.server.resourcemanager.webapp.TestRMWebServicesCapacitySched.assertJsonResponse;
45+
import static org.apache.hadoop.yarn.server.resourcemanager.webapp.TestRMWebServicesCapacitySched.createMockRM;
46+
import static org.apache.hadoop.yarn.server.resourcemanager.webapp.TestRMWebServicesCapacitySched.createWebAppDescriptor;
5047

5148
public class TestRMWebServicesCapacitySchedDynamicConfig extends
5249
JerseyTestBase {
53-
private static final int GB = 1024;
54-
private static MockRM rm;
50+
private MockRM rm;
5551

5652
private CapacitySchedulerQueueManager autoQueueHandler;
5753

58-
private static class WebServletModule extends ServletModule {
59-
private final Configuration conf;
60-
61-
WebServletModule(Configuration conf) {
62-
this.conf = conf;
63-
}
64-
65-
@Override
66-
protected void configureServlets() {
67-
bind(JAXBContextResolver.class);
68-
bind(RMWebServices.class);
69-
bind(GenericExceptionHandler.class);
70-
conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
71-
ResourceScheduler.class);
72-
conf.set(YarnConfiguration.RM_PLACEMENT_CONSTRAINTS_HANDLER,
73-
YarnConfiguration.SCHEDULER_RM_PLACEMENT_CONSTRAINTS_HANDLER);
74-
rm = new MockRM(conf);
75-
bind(ResourceManager.class).toInstance(rm);
76-
serve("/*").with(GuiceContainer.class);
77-
}
78-
}
79-
80-
private void initResourceManager(Configuration conf) throws IOException {
81-
GuiceServletConfig.setInjector(
82-
Guice.createInjector(new WebServletModule(conf)));
83-
rm.start();
84-
//Need to call reinitialize as
85-
//MutableCSConfigurationProvider with InMemoryConfigurationStore
86-
//somehow does not load the queues properly and falls back to default config.
87-
//Therefore CS will think there's only the default queue there.
88-
((CapacityScheduler) rm.getResourceScheduler()).reinitialize(conf,
89-
rm.getRMContext(), true);
90-
}
91-
9254
public TestRMWebServicesCapacitySchedDynamicConfig() {
93-
super(new WebAppDescriptor.Builder(
94-
"org.apache.hadoop.yarn.server.resourcemanager.webapp")
95-
.contextListenerClass(GuiceServletConfig.class)
96-
.filterClass(com.google.inject.servlet.GuiceFilter.class)
97-
.contextPath("jersey-guice-filter").servletPath("/").build());
55+
super(createWebAppDescriptor());
9856
}
9957

10058
@Test
@@ -335,4 +293,17 @@ public static Configuration createConfiguration(
335293
return config;
336294
}
337295
}
296+
297+
private void initResourceManager(Configuration conf) throws IOException {
298+
rm = createMockRM(new CapacitySchedulerConfiguration(conf));
299+
GuiceServletConfig.setInjector(
300+
Guice.createInjector(new TestRMWebServicesCapacitySched.WebServletModule(rm)));
301+
rm.start();
302+
//Need to call reinitialize as
303+
//MutableCSConfigurationProvider with InMemoryConfigurationStore
304+
//somehow does not load the queues properly and falls back to default config.
305+
//Therefore CS will think there's only the default queue there.
306+
((CapacityScheduler) rm.getResourceScheduler()).reinitialize(conf,
307+
rm.getRMContext(), true);
308+
}
338309
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesSchedulerActivities.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,20 @@
1818

1919
package org.apache.hadoop.yarn.server.resourcemanager.webapp;
2020

21+
import com.google.inject.Guice;
2122
import com.sun.jersey.api.client.ClientResponse;
2223
import com.sun.jersey.api.client.WebResource;
2324
import com.sun.jersey.core.util.MultivaluedMapImpl;
25+
26+
import org.apache.hadoop.conf.Configuration;
2427
import org.apache.hadoop.test.GenericTestUtils;
2528
import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest;
2629
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.activities.ActivityDiagnosticConstant;
2730
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.activities.ActivityState;
28-
import org.slf4j.Logger;
29-
import org.slf4j.LoggerFactory;
31+
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
32+
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
33+
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
34+
import org.junit.Before;
3035
import org.apache.hadoop.http.JettyUtils;
3136
import org.apache.hadoop.yarn.api.records.ContainerId;
3237
import org.apache.hadoop.yarn.api.records.ContainerState;
@@ -83,6 +88,8 @@
8388
import static org.apache.hadoop.yarn.server.resourcemanager.webapp.ActivitiesTestUtils.verifyNumberOfNodes;
8489
import static org.apache.hadoop.yarn.server.resourcemanager.webapp.ActivitiesTestUtils.verifyQueueOrder;
8590
import static org.apache.hadoop.yarn.server.resourcemanager.webapp.ActivitiesTestUtils.verifyStateOfAllocations;
91+
import static org.apache.hadoop.yarn.server.resourcemanager.webapp.TestRMWebServicesCapacitySched.createMockRM;
92+
import static org.apache.hadoop.yarn.server.resourcemanager.webapp.TestRMWebServicesCapacitySched.createWebAppDescriptor;
8693
import static org.junit.Assert.assertEquals;
8794
import static org.junit.Assert.assertFalse;
8895
import static org.junit.Assert.assertNotNull;
@@ -91,11 +98,23 @@
9198
/**
9299
* Tests for scheduler/app activities.
93100
*/
94-
public class TestRMWebServicesSchedulerActivities
95-
extends TestRMWebServicesCapacitySched {
101+
public class TestRMWebServicesSchedulerActivities extends JerseyTestBase {
102+
103+
private MockRM rm;
96104

97-
private static final Logger LOG = LoggerFactory.getLogger(
98-
TestRMWebServicesSchedulerActivities.class);
105+
public TestRMWebServicesSchedulerActivities() {
106+
super(createWebAppDescriptor());
107+
}
108+
109+
@Before
110+
@Override
111+
public void setUp() throws Exception {
112+
super.setUp();
113+
rm = createMockRM(new CapacitySchedulerConfiguration(
114+
new Configuration(false)));
115+
GuiceServletConfig.setInjector(
116+
Guice.createInjector(new TestRMWebServicesCapacitySched.WebServletModule(rm)));
117+
}
99118

100119
@Test
101120
public void testAssignMultipleContainersPerNodeHeartbeat()

0 commit comments

Comments
 (0)