diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/RMTestBase.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/RMTestBase.java new file mode 100644 index 0000000..43cea08 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/RMTestBase.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.yarn.server.resourcemanager; + +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerConfiguration; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo.FifoScheduler; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Collection; + +@RunWith(Parameterized.class) +public class RMTestBase { + protected final static String TEST_DIR = + new File(System.getProperty("test.build.data", "/tmp")).getAbsolutePath(); + private final static String FS_ALLOC_FILE = + new File(TEST_DIR, "test-fs-queues.xml").getAbsolutePath(); + + protected SchedulerType schedulerType; + + public enum SchedulerType { + FIFO, CAPACITY, FAIR + } + + public RMTestBase(SchedulerType type) { + schedulerType = type; + } + + @Parameterized.Parameters + public static Collection configSchedulerTypes() { + return Arrays.asList(new SchedulerType[][]{ + {SchedulerType.FIFO}, {SchedulerType.CAPACITY}, {SchedulerType.FAIR}}); + } + + protected void configScheduler(YarnConfiguration conf) throws IOException { + // Configure scheduler + switch (schedulerType) { + case FIFO: + configFifoScheduler(conf); + break; + case CAPACITY: + configCapacityScheduler(conf); + break; + case FAIR: + configFairScheduler(conf); + break; + } + } + + private void configFifoScheduler(YarnConfiguration conf) { + conf.set(YarnConfiguration.RM_SCHEDULER, FifoScheduler.class.getName()); + } + + private void configCapacityScheduler(YarnConfiguration conf) { + conf.set(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class.getName()); + } + + private void configFairScheduler(YarnConfiguration conf) throws IOException { + // Disable queueMaxAMShare limitation for fair scheduler + PrintWriter out = new PrintWriter(new FileWriter(FS_ALLOC_FILE)); + out.println(""); + out.println(""); + out.println("-1.0"); + out.println(""); + out.close(); + + conf.set(YarnConfiguration.RM_SCHEDULER, FairScheduler.class.getName()); + conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, FS_ALLOC_FILE); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java index cd67ebc..237c4d8 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.spy; +import java.io.IOException; import java.util.ArrayList; import java.util.EnumSet; import java.util.HashMap; @@ -65,23 +66,34 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptEventType; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState; import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; -import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; import org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM; import org.apache.log4j.Level; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; +import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatcher; @SuppressWarnings({"unchecked", "rawtypes"}) -public class TestRM { - +public class TestRM extends RMTestBase { private static final Log LOG = LogFactory.getLog(TestRM.class); // Milliseconds to sleep for when waiting for something to happen private final static int WAIT_SLEEP_MS = 100; + private YarnConfiguration conf = null; + + public TestRM(SchedulerType type) { + super(type); + } + + @Before + public void setup() throws IOException { + conf = new YarnConfiguration(); + configScheduler(conf); + } + @After public void tearDown() { ClusterMetrics.destroy(); @@ -93,7 +105,7 @@ public void tearDown() { public void testGetNewAppId() throws Exception { Logger rootLogger = LogManager.getRootLogger(); rootLogger.setLevel(Level.DEBUG); - MockRM rm = new MockRM(); + MockRM rm = new MockRM(conf); rm.start(); GetNewApplicationResponse resp = rm.getNewAppId(); @@ -106,7 +118,7 @@ public void testGetNewAppId() throws Exception { public void testAppWithNoContainers() throws Exception { Logger rootLogger = LogManager.getRootLogger(); rootLogger.setLevel(Level.DEBUG); - MockRM rm = new MockRM(); + MockRM rm = new MockRM(conf); rm.start(); MockNM nm1 = rm.registerNode("h1:1234", 5120); @@ -128,7 +140,6 @@ public void testAppWithNoContainers() throws Exception { public void testAppOnMultiNode() throws Exception { Logger rootLogger = LogManager.getRootLogger(); rootLogger.setLevel(Level.DEBUG); - YarnConfiguration conf = new YarnConfiguration(); conf.set("yarn.scheduler.capacity.node-locality-delay", "-1"); MockRM rm = new MockRM(conf); rm.start(); @@ -188,7 +199,6 @@ public void testAppOnMultiNode() throws Exception { // corresponding NM Token. @Test (timeout = 20000) public void testNMTokenSentForNormalContainer() throws Exception { - YarnConfiguration conf = new YarnConfiguration(); conf.set(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class.getCanonicalName()); MockRM rm = new MockRM(conf); @@ -240,7 +250,7 @@ public void testNMTokenSentForNormalContainer() throws Exception { @Test (timeout = 40000) public void testNMToken() throws Exception { - MockRM rm = new MockRM(); + MockRM rm = new MockRM(conf); try { rm.start(); MockNM nm1 = rm.registerNode("h1:1234", 10000); @@ -422,7 +432,12 @@ protected void allocateContainersAndValidateNMTokens(MockAM am, @Test (timeout = 300000) public void testActivatingApplicationAfterAddingNM() throws Exception { - YarnConfiguration conf = new YarnConfiguration(); + // This test doesn't work for FifoScheduler, as FifoScheduler doesn't + // support ASSIGN_MULTIPLE setting; that is, FifoScheduler tries to assign + // as many as possible containers per node heartbeat. + if (schedulerType == SchedulerType.FIFO) { + return; + } MockRM rm1 = new MockRM(conf); @@ -469,7 +484,6 @@ public void testActivatingApplicationAfterAddingNM() throws Exception { // is killed or failed, so that client doesn't get the wrong information. @Test (timeout = 80000) public void testInvalidateAMHostPortWhenAMFailedOrKilled() throws Exception { - YarnConfiguration conf = new YarnConfiguration(); conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); MockRM rm1 = new MockRM(conf); rm1.start(); @@ -522,7 +536,6 @@ public void testInvalidateAMHostPortWhenAMFailedOrKilled() throws Exception { @Test (timeout = 60000) public void testInvalidatedAMHostPortOnAMRestart() throws Exception { - YarnConfiguration conf = new YarnConfiguration(); MockRM rm1 = new MockRM(conf); rm1.start(); MockNM nm1 = @@ -555,7 +568,6 @@ public void testInvalidatedAMHostPortOnAMRestart() throws Exception { @Test (timeout = 60000) public void testApplicationKillAtAcceptedState() throws Exception { - YarnConfiguration conf = new YarnConfiguration(); final Dispatcher dispatcher = new AsyncDispatcher() { @Override public EventHandler getEventHandler() { @@ -632,15 +644,4 @@ protected Dispatcher createDispatcher() { Assert.assertEquals(appsSubmitted + 1, metrics.getAppsSubmitted()); } - public static void main(String[] args) throws Exception { - TestRM t = new TestRM(); - t.testGetNewAppId(); - t.testAppWithNoContainers(); - t.testAppOnMultiNode(); - t.testNMToken(); - t.testActivatingApplicationAfterAddingNM(); - t.testInvalidateAMHostPortWhenAMFailedOrKilled(); - t.testInvalidatedAMHostPortOnAMRestart(); - t.testApplicationKillAtAcceptedState(); - } } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java index 0b3a364..6872844 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java @@ -29,7 +29,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.net.InetSocketAddress; -import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; @@ -109,7 +108,7 @@ import org.junit.Before; import org.junit.Test; -public class TestRMRestart { +public class TestRMRestart extends RMTestBase { private final static File TEMP_DIR = new File(System.getProperty( "test.build.data", "/tmp"), "decommision"); private File hostFile = new File(TEMP_DIR + File.separator + "hostFile.txt"); @@ -118,11 +117,16 @@ // Fake rmAddr for token-renewal private static InetSocketAddress rmAddr; + public TestRMRestart(SchedulerType type) { + super(type); + } + @Before - public void setup() throws UnknownHostException { + public void setup() throws IOException { + conf = new YarnConfiguration(); + configScheduler(conf); Logger rootLogger = LogManager.getRootLogger(); rootLogger.setLevel(Level.DEBUG); - conf = new YarnConfiguration(); UserGroupInformation.setConfiguration(conf); conf.set(YarnConfiguration.RECOVERY_ENABLED, "true"); conf.set(YarnConfiguration.RM_STORE, MemoryRMStateStore.class.getName()); @@ -605,6 +609,11 @@ public void testRMRestartWaitForPreviousAMToFinish() throws Exception { RMAppAttemptState.SCHEDULED); Assert.assertEquals(RMAppAttemptState.SCHEDULED, app2 .getCurrentAppAttempt().getAppAttemptState()); + + rm1.stop(); + rm2.stop(); + rm3.stop(); + rm4.stop(); } // Test RM restarts after previous attempt succeeded and was saved into state @@ -662,6 +671,9 @@ public void updateApplicationStateInternal(ApplicationId appId, // app final state is saved via the finish event from attempt. Assert.assertEquals(RMAppState.FINISHED, rmAppState.get(app0.getApplicationId()).getState()); + + rm1.stop(); + rm2.stop(); } @Test (timeout = 60000) @@ -799,6 +811,9 @@ public synchronized void updateApplicationAttemptStateInternal( rm2.getRMContext().getRMApps().get(app0.getApplicationId()); rm2.waitForState(loadedApp0.getApplicationId(), RMAppState.KILLED); Assert.assertTrue(loadedApp0.getAppAttempts().size() == 0); + + rm1.stop(); + rm2.stop(); } @Test (timeout = 60000) @@ -1443,6 +1458,10 @@ public void testAppSubmissionWithOldDelegationTokenAfterRMRestart() RMApp app = rm2.submitApp(200, "name", "user", new HashMap(), false, "default", 1, ts); rm2.waitForState(app.getApplicationId(), RMAppState.ACCEPTED); + + // stop RM + rm1.stop(); + rm2.stop(); } @Test (timeout = 60000) @@ -1611,6 +1630,8 @@ public void testClientRetryOnKillingApplication() throws Exception { rm1.waitForState(app1.getApplicationId(), RMAppState.KILLED); Assert.assertEquals(1, ((TestMemoryRMStateStore) memStore).updateAttempt); Assert.assertEquals(2, ((TestMemoryRMStateStore) memStore).updateApp); + + rm1.stop(); } // Test Application that fails on submission is saved in state store. @@ -1658,6 +1679,9 @@ protected Credentials parseCredentials( rm2.start(); // Restarted RM has the failed app info too. rm2.waitForState(app1.getApplicationId(), RMAppState.FAILED); + + rm1.stop(); + rm2.stop(); } @Test (timeout = 20000) @@ -1928,6 +1952,9 @@ protected void serviceStart() throws Exception { } MockAM am1 = MockRM.launchAndRegisterAM(loadedApp0, rm2, nm1); MockRM.finishAMAndVerifyAppState(loadedApp0, rm2, nm1, am1); + + rm1.stop(); + rm2.stop(); } private void writeToHostsFile(String... hosts) throws IOException { diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java index 0dcd228..7f2925d 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java @@ -31,6 +31,8 @@ import javax.security.sasl.SaslException; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.server.resourcemanager.RMTestBase; import org.junit.Assert; import org.apache.hadoop.conf.Configuration; @@ -72,9 +74,21 @@ import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.ConverterUtils; import org.apache.hadoop.yarn.util.Records; +import org.junit.Before; import org.junit.Test; -public class TestClientToAMTokens { +public class TestClientToAMTokens extends RMTestBase { + private YarnConfiguration conf = null; + + public TestClientToAMTokens(SchedulerType type) { + super(type); + } + + @Before + public void setup() throws IOException { + conf = new YarnConfiguration(); + configScheduler(conf); + } private interface CustomProtocol { @SuppressWarnings("unused") @@ -151,8 +165,6 @@ protected void serviceStart() throws Exception { @Test public void testClientToAMTokens() throws Exception { - - final Configuration conf = new Configuration(); conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); UserGroupInformation.setConfiguration(conf); @@ -267,6 +279,8 @@ public RegisterApplicationMasterResponse run() { // Now for an authenticated user verifyValidToken(conf, am, token); + + rm.stop(); } private void verifyTokenWithTamperedID(final Configuration conf,