1818
1919package org .apache .hadoop .yarn .server .resourcemanager ;
2020
21+ import org .junit .Before ;
2122import static org .mockito .Matchers .argThat ;
2223import static org .mockito .Mockito .doNothing ;
2324import static org .mockito .Mockito .spy ;
6566import org .apache .hadoop .yarn .server .resourcemanager .rmapp .attempt .RMAppAttemptEventType ;
6667import org .apache .hadoop .yarn .server .resourcemanager .rmapp .attempt .RMAppAttemptState ;
6768import org .apache .hadoop .yarn .server .resourcemanager .rmnode .RMNode ;
68- import org .apache .hadoop .yarn .server .resourcemanager .scheduler .QueueMetrics ;
6969import org .apache .hadoop .yarn .server .resourcemanager .scheduler .capacity .CapacityScheduler ;
7070import org .apache .hadoop .yarn .server .resourcemanager .security .NMTokenSecretManagerInRM ;
7171import org .apache .log4j .Level ;
7575import 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