Author: sgoeschl Date: Thu Aug 12 18:09:28 2010 New Revision: 984888 URL: http://svn.apache.org/viewvc?rev=984888&view=rev Log: [EXEC-42] Applied the patch and updated documentation
Modified: commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java Modified: commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java?rev=984888&r1=984887&r2=984888&view=diff ============================================================================== --- commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java (original) +++ commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java Thu Aug 12 18:09:28 2010 @@ -627,13 +627,17 @@ public class DefaultExecutorTest extends * * @throws Exception the test failed */ - public void testExec41() throws Exception { + public void testExec41WithStreams() throws Exception { CommandLine cmdLine = new CommandLine(exec41Script); cmdLine.addArgument("10"); // sleep 10 secs DefaultExecutor executor = new DefaultExecutor(); ExecuteWatchdog watchdog = new ExecuteWatchdog(2*1000); // allow process no more than 2 secs + PumpStreamHandler pumpStreamHandler = new PumpStreamHandler( System.out, System.err); + pumpStreamHandler.setAlwaysWaitForStreamThreads(false); + executor.setWatchdog(watchdog); + executor.setStreamHandler(pumpStreamHandler); long startTime = System.currentTimeMillis(); @@ -652,6 +656,46 @@ public class DefaultExecutorTest extends } assertTrue("The process was killed by the watchdog", watchdog.killedProcess()); + assertTrue("SKipping the Thread.join() did not work", duration < 9000); } + /** + * Test EXEC-41 with a disabled PumpStreamHandler to check if we could return + * immediately after killing the process (no streams implies no blocking + * stream pumper threads). + * + * @throws Exception the test failed + */ + public void testExec41WithoutStreams() throws Exception { + + CommandLine cmdLine = new CommandLine(exec41Script); + cmdLine.addArgument("10"); // sleep 10 secs + DefaultExecutor executor = new DefaultExecutor(); + ExecuteWatchdog watchdog = new ExecuteWatchdog(2*1000); // allow process no more than 2 secs + + // create a custom "PumpStreamHandler" doing no pumping at all + PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(null, null, null); + + executor.setWatchdog(watchdog); + executor.setStreamHandler(pumpStreamHandler); + + long startTime = System.currentTimeMillis(); + + try { + executor.execute(cmdLine); + } catch (ExecuteException e) { + System.out.println(e); + } + + long duration = System.currentTimeMillis() - startTime; + + System.out.println("Process completed in " + duration +" millis; below is its output"); + + if (watchdog.killedProcess()) { + System.out.println("Process timed out and was killed."); + } + + assertTrue("The process was killed by the watchdog", watchdog.killedProcess()); + assertTrue("SKipping the Thread.join() did not work", duration < 9000); + } }