diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/TestContainerManagerSecurity.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/TestContainerManagerSecurity.java index 98cb365..b138dd6 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/TestContainerManagerSecurity.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/TestContainerManagerSecurity.java @@ -68,6 +68,7 @@ import org.apache.hadoop.yarn.server.nodemanager.NodeManager; import org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManagerImpl; import org.apache.hadoop.yarn.server.nodemanager.security.NMTokenSecretManagerInNM; +import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.MockRMApp; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; import org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM; @@ -123,7 +124,13 @@ public void tearDown() { testRootDir.delete(); } - @Parameters + /* + * Run two tests: one with no security ("simple") and one with "Secure" + * The first parameter is just the test name to make it easier to debug + * and to give details in say an IDE. The second is the configuraiton + * object to use. + */ + @Parameters(name = "{0}") public static Collection configs() { Configuration configurationWithoutSecurity = new Configuration(); configurationWithoutSecurity.set( @@ -143,16 +150,18 @@ public void tearDown() { YarnConfiguration.NM_WEBAPP_SPNEGO_KEYTAB_FILE_KEY, httpSpnegoKeytabFile.getAbsolutePath()); - return Arrays.asList(new Object[][] { { configurationWithoutSecurity }, - { configurationWithSecurity } }); + return Arrays.asList(new Object[][] { + {"Simple", configurationWithoutSecurity}, + {"Secure", configurationWithSecurity}}); } - public TestContainerManagerSecurity(Configuration conf) { + public TestContainerManagerSecurity(String name, Configuration conf) { + LOG.info("RUNNING TEST " + name); conf.setLong(YarnConfiguration.RM_AM_EXPIRY_INTERVAL_MS, 100000L); this.conf = conf; } - @Test (timeout = 120000) + @Test public void testContainerManager() throws Exception { // TestNMTokens. @@ -391,13 +400,20 @@ private void testNMTokens(Configuration conf) throws Exception { } private void waitForContainerToFinishOnNM(ContainerId containerId) { - Context nmContet = yarnCluster.getNodeManager(0).getNMContext(); + Context nmContext = yarnCluster.getNodeManager(0).getNMContext(); int interval = 4 * 60; // Max time for container token to expire. - Assert.assertNotNull(nmContet.getContainers().containsKey(containerId)); + + Assert.assertNotNull(nmContext.getContainers().containsKey(containerId)); + + // Get the container first, as it may be removed from the Context + // by asynchronous calls. + // This was leading to a flakey test as otherwise the container could + // be removed and end up null. + Container waitContainer = nmContext.getContainers().get(containerId); + while ((interval-- > 0) - && !nmContet.getContainers().get(containerId) - .cloneAndGetContainerStatus().getState() - .equals(ContainerState.COMPLETE)) { + && !waitContainer.cloneAndGetContainerStatus() + .getState().equals(ContainerState.COMPLETE)) { try { LOG.info("Waiting for " + containerId + " to complete."); Thread.sleep(1000); @@ -408,7 +424,8 @@ private void waitForContainerToFinishOnNM(ContainerId containerId) { // explicitly acked by RM. Now, manually remove it for testing. yarnCluster.getNodeManager(0).getNodeStatusUpdater() .addCompletedContainer(containerId); - nmContet.getContainers().remove(containerId); + LOG.info("Removing container from NMContext, containerID = " + containerId); + nmContext.getContainers().remove(containerId); } protected void waitForNMToReceiveNMTokenKey(