Skip to content

Commit 80d11eb

Browse files
committed
YARN-2635. TestRM, TestRMRestart, TestClientToAMTokens should run with both CS and FS. (Wei Yan and kasha via kasha)
1 parent eb6ce5e commit 80d11eb

File tree

5 files changed

+258
-150
lines changed

5 files changed

+258
-150
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Release 2.7.0 - UNRELEASED
4141
YARN-1979. TestDirectoryCollection fails when the umask is unusual.
4242
(Vinod Kumar Vavilapalli and Tsuyoshi OZAWA via junping_du)
4343

44+
YARN-2635. TestRM, TestRMRestart, TestClientToAMTokens should run
45+
with both CS and FS. (Wei Yan and kasha via kasha)
46+
4447
OPTIMIZATIONS
4548

4649
BUG FIXES
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.yarn.server.resourcemanager;
20+
21+
import org.apache.hadoop.yarn.conf.YarnConfiguration;
22+
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
23+
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
24+
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerConfiguration;
25+
26+
27+
import org.junit.Before;
28+
import org.junit.runner.RunWith;
29+
import org.junit.runners.Parameterized;
30+
31+
import java.io.File;
32+
import java.io.FileWriter;
33+
import java.io.IOException;
34+
import java.io.PrintWriter;
35+
import java.util.Arrays;
36+
import java.util.Collection;
37+
38+
@RunWith(Parameterized.class)
39+
public abstract class ParameterizedSchedulerTestBase {
40+
protected final static String TEST_DIR =
41+
new File(System.getProperty("test.build.data", "/tmp")).getAbsolutePath();
42+
private final static String FS_ALLOC_FILE =
43+
new File(TEST_DIR, "test-fs-queues.xml").getAbsolutePath();
44+
45+
private SchedulerType schedulerType;
46+
private YarnConfiguration conf = null;
47+
48+
public enum SchedulerType {
49+
CAPACITY, FAIR
50+
}
51+
52+
public ParameterizedSchedulerTestBase(SchedulerType type) {
53+
schedulerType = type;
54+
}
55+
56+
public YarnConfiguration getConf() {
57+
return conf;
58+
}
59+
60+
@Parameterized.Parameters
61+
public static Collection<SchedulerType[]> getParameters() {
62+
return Arrays.asList(new SchedulerType[][]{
63+
{SchedulerType.CAPACITY}, {SchedulerType.FAIR}});
64+
}
65+
66+
@Before
67+
public void configureScheduler() throws IOException {
68+
conf = new YarnConfiguration();
69+
switch (schedulerType) {
70+
case CAPACITY:
71+
conf.set(YarnConfiguration.RM_SCHEDULER,
72+
CapacityScheduler.class.getName());
73+
break;
74+
case FAIR:
75+
configureFairScheduler(conf);
76+
break;
77+
}
78+
}
79+
80+
private void configureFairScheduler(YarnConfiguration conf) throws IOException {
81+
// Disable queueMaxAMShare limitation for fair scheduler
82+
PrintWriter out = new PrintWriter(new FileWriter(FS_ALLOC_FILE));
83+
out.println("<?xml version=\"1.0\"?>");
84+
out.println("<allocations>");
85+
out.println("<queueMaxAMShareDefault>-1.0</queueMaxAMShareDefault>");
86+
out.println("</allocations>");
87+
out.close();
88+
89+
conf.set(YarnConfiguration.RM_SCHEDULER, FairScheduler.class.getName());
90+
conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, FS_ALLOC_FILE);
91+
}
92+
}

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

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

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

21+
import org.junit.Before;
2122
import static org.mockito.Matchers.argThat;
2223
import static org.mockito.Mockito.doNothing;
2324
import static org.mockito.Mockito.spy;
@@ -65,7 +66,6 @@
6566
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptEventType;
6667
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState;
6768
import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode;
68-
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics;
6969
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
7070
import org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM;
7171
import org.apache.log4j.Level;
@@ -75,13 +75,23 @@
7575
import org.mockito.ArgumentMatcher;
7676

7777
@SuppressWarnings({"unchecked", "rawtypes"})
78-
public class TestRM {
79-
78+
public class TestRM extends ParameterizedSchedulerTestBase {
8079
private static final Log LOG = LogFactory.getLog(TestRM.class);
8180

8281
// Milliseconds to sleep for when waiting for something to happen
8382
private final static int WAIT_SLEEP_MS = 100;
8483

84+
private YarnConfiguration conf;
85+
86+
public TestRM(SchedulerType type) {
87+
super(type);
88+
}
89+
90+
@Before
91+
public void setup() {
92+
conf = getConf();
93+
}
94+
8595
@After
8696
public void tearDown() {
8797
ClusterMetrics.destroy();
@@ -93,7 +103,7 @@ public void tearDown() {
93103
public void testGetNewAppId() throws Exception {
94104
Logger rootLogger = LogManager.getRootLogger();
95105
rootLogger.setLevel(Level.DEBUG);
96-
MockRM rm = new MockRM();
106+
MockRM rm = new MockRM(conf);
97107
rm.start();
98108

99109
GetNewApplicationResponse resp = rm.getNewAppId();
@@ -106,7 +116,7 @@ public void testGetNewAppId() throws Exception {
106116
public void testAppWithNoContainers() throws Exception {
107117
Logger rootLogger = LogManager.getRootLogger();
108118
rootLogger.setLevel(Level.DEBUG);
109-
MockRM rm = new MockRM();
119+
MockRM rm = new MockRM(conf);
110120
rm.start();
111121
MockNM nm1 = rm.registerNode("h1:1234", 5120);
112122

@@ -128,7 +138,6 @@ public void testAppWithNoContainers() throws Exception {
128138
public void testAppOnMultiNode() throws Exception {
129139
Logger rootLogger = LogManager.getRootLogger();
130140
rootLogger.setLevel(Level.DEBUG);
131-
YarnConfiguration conf = new YarnConfiguration();
132141
conf.set("yarn.scheduler.capacity.node-locality-delay", "-1");
133142
MockRM rm = new MockRM(conf);
134143
rm.start();
@@ -188,7 +197,6 @@ public void testAppOnMultiNode() throws Exception {
188197
// corresponding NM Token.
189198
@Test (timeout = 20000)
190199
public void testNMTokenSentForNormalContainer() throws Exception {
191-
YarnConfiguration conf = new YarnConfiguration();
192200
conf.set(YarnConfiguration.RM_SCHEDULER,
193201
CapacityScheduler.class.getCanonicalName());
194202
MockRM rm = new MockRM(conf);
@@ -240,7 +248,7 @@ public void testNMTokenSentForNormalContainer() throws Exception {
240248

241249
@Test (timeout = 40000)
242250
public void testNMToken() throws Exception {
243-
MockRM rm = new MockRM();
251+
MockRM rm = new MockRM(conf);
244252
try {
245253
rm.start();
246254
MockNM nm1 = rm.registerNode("h1:1234", 10000);
@@ -422,8 +430,6 @@ protected void allocateContainersAndValidateNMTokens(MockAM am,
422430

423431
@Test (timeout = 300000)
424432
public void testActivatingApplicationAfterAddingNM() throws Exception {
425-
YarnConfiguration conf = new YarnConfiguration();
426-
427433
MockRM rm1 = new MockRM(conf);
428434

429435
// start like normal because state is empty
@@ -469,7 +475,6 @@ public void testActivatingApplicationAfterAddingNM() throws Exception {
469475
// is killed or failed, so that client doesn't get the wrong information.
470476
@Test (timeout = 80000)
471477
public void testInvalidateAMHostPortWhenAMFailedOrKilled() throws Exception {
472-
YarnConfiguration conf = new YarnConfiguration();
473478
conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1);
474479
MockRM rm1 = new MockRM(conf);
475480
rm1.start();
@@ -522,7 +527,6 @@ public void testInvalidateAMHostPortWhenAMFailedOrKilled() throws Exception {
522527

523528
@Test (timeout = 60000)
524529
public void testInvalidatedAMHostPortOnAMRestart() throws Exception {
525-
YarnConfiguration conf = new YarnConfiguration();
526530
MockRM rm1 = new MockRM(conf);
527531
rm1.start();
528532
MockNM nm1 =
@@ -555,7 +559,6 @@ public void testInvalidatedAMHostPortOnAMRestart() throws Exception {
555559
@Test (timeout = 60000)
556560
public void testApplicationKillAtAcceptedState() throws Exception {
557561

558-
YarnConfiguration conf = new YarnConfiguration();
559562
final Dispatcher dispatcher = new AsyncDispatcher() {
560563
@Override
561564
public EventHandler getEventHandler() {
@@ -632,15 +635,4 @@ protected Dispatcher createDispatcher() {
632635
Assert.assertEquals(appsSubmitted + 1, metrics.getAppsSubmitted());
633636
}
634637

635-
public static void main(String[] args) throws Exception {
636-
TestRM t = new TestRM();
637-
t.testGetNewAppId();
638-
t.testAppWithNoContainers();
639-
t.testAppOnMultiNode();
640-
t.testNMToken();
641-
t.testActivatingApplicationAfterAddingNM();
642-
t.testInvalidateAMHostPortWhenAMFailedOrKilled();
643-
t.testInvalidatedAMHostPortOnAMRestart();
644-
t.testApplicationKillAtAcceptedState();
645-
}
646638
}

0 commit comments

Comments
 (0)