Author: sgoeschl Date: Thu Sep 2 20:42:42 2010 New Revision: 992112 URL: http://svn.apache.org/viewvc?rev=992112&view=rev Log: [EXEC-41] Reverting patch since it does not fix the problem under Windows
Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteStreamHandler.java commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteStreamHandler.java URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteStreamHandler.java?rev=992112&r1=992111&r2=992112&view=diff ============================================================================== --- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteStreamHandler.java (original) +++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteStreamHandler.java Thu Sep 2 20:42:42 2010 @@ -63,10 +63,4 @@ public interface ExecuteStreamHandler { * Will wait for pump threads to complete. */ void stop(); - - /** - * Stop handling of the streams - will not be restarted. - * @param join if true, wait for the pump threads to complete - */ - void stop(boolean join); } Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java?rev=992112&r1=992111&r2=992112&view=diff ============================================================================== --- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java (original) +++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java Thu Sep 2 20:42:42 2010 @@ -45,8 +45,6 @@ public class PumpStreamHandler implement private InputStreamPumper inputStreamPumper; - private boolean alwaysWaitForStreamThreads = true; - /** * Construct a new <CODE>PumpStreamHandler</CODE>. */ @@ -143,30 +141,7 @@ public class PumpStreamHandler implement } } } - - - /** - * Whether to always wait for (join) stream threads, even if the process - * is was "killed" by a Watchdog. - * @return true, to wait always (original behavior); false, to NOT wait if killed - */ - public boolean isAlwaysWaitForStreamThreads() { - return alwaysWaitForStreamThreads; - } - - /** - * Whether to always wait for (join) stream threads, even if the process - * is was "killed" by a Watchdog. Please note that skipping the wait might - * leave up to three threads behind so and cause severe problems in a - * production environment. - * - * @param alwaysWaitForStreamThreads if true, wait always (original behavior); if false, do NOT wait when killed - */ - public void setAlwaysWaitForStreamThreads(boolean alwaysWaitForStreamThreads) { - this.alwaysWaitForStreamThreads = alwaysWaitForStreamThreads; - } - - + /** * Start the <CODE>Thread</CODE>s. */ @@ -186,60 +161,35 @@ public class PumpStreamHandler implement * Stop pumping the streams. */ public void stop() { - stop(this.alwaysWaitForStreamThreads); - } - - /** - * Stop pumping the streams. - * @param join if true, wait for the pump threads to complete, if false don't wait - */ - public void stop(boolean join) { if (inputStreamPumper != null) { inputStreamPumper.stopProcessing(); } - if (join) { - if (outputThread != null) { - try { - outputThread.join(); - outputThread = null; - } catch (InterruptedException e) { - // ignore - } - } - - if (errorThread != null) { - try { - errorThread.join(); - errorThread = null; - } catch (InterruptedException e) { - // ignore - } - } - - if (inputThread != null) { - try { - inputThread.join(); - inputThread = null; - } catch (InterruptedException e) { - // ignore - } + if (outputThread != null) { + try { + outputThread.join(); + outputThread = null; + } catch (InterruptedException e) { + // ignore } } - else { - // well, give each thread a chance to terminate itself before - // we leave them alone - if (outputThread != null) { - outputThread.interrupt(); - } - if (errorThread != null) { - errorThread.interrupt(); + if (errorThread != null) { + try { + errorThread.join(); + errorThread = null; + } catch (InterruptedException e) { + // ignore } + } - if (inputThread != null) { - inputThread.interrupt(); + if (inputThread != null) { + try { + inputThread.join(); + inputThread = null; + } catch (InterruptedException e) { + // ignore } } 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=992112&r1=992111&r2=992112&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 Sep 2 20:42:42 2010 @@ -426,7 +426,7 @@ public class DefaultExecutorTest extends fis.close(); String result = baos.toString().trim(); System.out.println(result); - assertTrue(result.endsWith("Finished reading from stdin")); + assertTrue(result.indexOf("Finished reading from stdin") > 0); assertFalse(exec.isFailure(exitValue)); } else if(OS.isFamilyWindows()) { @@ -701,14 +701,6 @@ public class DefaultExecutorTest extends * Problem is, that sometimes the native process doesn't die and thus * streams aren't closed and the stream threads do not complete. * - * The patch provides setAlwaysWaitForStreamThreads(boolean) method - * in PumpStreamHandler. By default, alwaysWaitForStreamThreads is set - * to true to preserve the current behavior. If set to false, and - * process is killed by watchdog, DefaultExecutor's call into - * ErrorStreamHandler.stop will NOT join the stream threads and - * DefaultExecutor will NOT attempt to close the streams, so the - * executor's thread won't get stuck. - * * @throws Exception the test failed */ public void testExec41WithStreams() throws Exception { @@ -729,7 +721,8 @@ public class DefaultExecutorTest extends 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); + // this method was part of the patch I reverted + // pumpStreamHandler.setAlwaysWaitForStreamThreads(false); executor.setWatchdog(watchdog); executor.setStreamHandler(pumpStreamHandler); @@ -842,7 +835,7 @@ public class DefaultExecutorTest extends public void testExecuteStability() throws Exception { // make a plain-vanilla test - for(int i=0; i<1000; i++) { + for(int i=0; i<100; i++) { Map env = new HashMap(); env.put("TEST_ENV_VAR", new Integer(i)); CommandLine cl = new CommandLine(testScript);