Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupElasticMemoryController.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupElasticMemoryController.java (date 1527646822000) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupElasticMemoryController.java (date 1527655317000) @@ -18,6 +18,8 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources; import org.apache.commons.io.FileUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; @@ -41,6 +43,8 @@ * Test for elastic non-strict memory controller based on cgroups. */ public class TestCGroupElasticMemoryController { + protected static final Log LOG = LogFactory + .getLog(TestCGroupElasticMemoryController.class); private YarnConfiguration conf = new YarnConfiguration(); private File script = new File("target/" + TestCGroupElasticMemoryController.class.getName()); @@ -89,7 +93,7 @@ * Test that the handler is notified about multiple OOM events. * @throws Exception on exception */ - @Test + @Test(timeout = 20000) public void testMultipleOOMEvents() throws Exception { conf.set(YarnConfiguration.NM_ELASTIC_MEMORY_CONTROL_OOM_LISTENER_PATH, script.getAbsolutePath()); @@ -131,7 +135,7 @@ * the child process starts * @throws Exception one exception */ - @Test + @Test(timeout = 20000) public void testStopBeforeStart() throws Exception { conf.set(YarnConfiguration.NM_ELASTIC_MEMORY_CONTROL_OOM_LISTENER_PATH, script.getAbsolutePath()); @@ -173,7 +177,7 @@ * Test the edge case that OOM is never resolved. * @throws Exception on exception */ - @Test(expected = YarnRuntimeException.class) + @Test(timeout = 20000, expected = YarnRuntimeException.class) public void testInfiniteOOM() throws Exception { conf.set(YarnConfiguration.NM_ELASTIC_MEMORY_CONTROL_OOM_LISTENER_PATH, script.getAbsolutePath()); @@ -215,7 +219,7 @@ * containers. * @throws Exception on exception */ - @Test(expected = YarnRuntimeException.class) + @Test(timeout = 20000, expected = YarnRuntimeException.class) public void testNothingToKill() throws Exception { conf.set(YarnConfiguration.NM_ELASTIC_MEMORY_CONTROL_OOM_LISTENER_PATH, script.getAbsolutePath()); @@ -258,13 +262,14 @@ * Then we wait for 2 seconds and stop listening. * @throws Exception exception occurred */ - @Test + @Test(timeout = 20000) public void testNormalExit() throws Exception { conf.set(YarnConfiguration.NM_ELASTIC_MEMORY_CONTROL_OOM_LISTENER_PATH, script.getAbsolutePath()); + ExecutorService service = Executors.newFixedThreadPool(1); try { FileUtils.writeStringToFile(script, - "#!/bin/bash\nsleep 10000;\n", + "sleep 10000\n", Charset.defaultCharset(), false); assertTrue("Could not set executable", script.setExecutable(true)); @@ -287,17 +292,21 @@ 10000, handler ); - ExecutorService service = Executors.newFixedThreadPool(1); + long start = System.currentTimeMillis(); service.submit(() -> { try { Thread.sleep(2000); } catch (InterruptedException ex) { assertTrue("Wait interrupted.", false); } + LOG.info(String.format("Calling process destroy in %d ms", + System.currentTimeMillis() - start)); controller.stopListening(); + LOG.info("Called process destroy."); }); controller.run(); } finally { + service.shutdown(); assertTrue(String.format("Could not clean up script %s", script.getAbsolutePath()), script.delete()); }