Author: sgoeschl
Date: Tue Jul 14 15:23:55 2009
New Revision: 793939

URL: http://svn.apache.org/viewvc?rev=793939&view=rev
Log:
[EXEC-41] Added regression test for EXEC-41 but did not apply the patch since 
it does not pass the test

Added:
    commons/proper/exec/trunk/src/test/scripts/exec41.bat
    commons/proper/exec/trunk/src/test/scripts/exec41.sh   (with props)
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=793939&r1=793938&r2=793939&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
 Tue Jul 14 15:23:55 2009
@@ -38,6 +38,7 @@
     private File foreverTestScript = TestUtil.resolveScriptForOS(testDir + 
"/forever");
     private File nonExistingTestScript = TestUtil.resolveScriptForOS(testDir + 
"/grmpffffff");
     private File redirectScript = TestUtil.resolveScriptForOS(testDir + 
"/redirect");
+    private File exec41Script = TestUtil.resolveScriptForOS(testDir + 
"/exec41");
 
     // Get suitable exit codes for the OS
     private static final int SUCCESS_STATUS; // test script successful exit 
code
@@ -425,4 +426,51 @@
          assertFalse(exec.isFailure(exitValue));
          assertTrue(outfile.exists());
      }
+
+    /**
+     * Test the patch for EXEC-41 
(https://issues.apache.org/jira/browse/EXEC-41).
+     *
+     * When a process runs longer than allowed by a configured watchdog's
+     * timeout, the watchdog tries to destroy it and then DefaultExecutor
+     * tries to clean up by joining with all installed pump stream threads.
+     * 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.
+     */
+    public void testExec41() 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
+               executor.setWatchdog(watchdog);
+               //ByteArrayOutputStream baos = new ByteArrayOutputStream();
+               //executor.setStreamHandler(new PumpStreamHandler(baos));
+
+               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");
+               // System.out.println(baos);
+               if (watchdog.killedProcess()) {
+                       System.out.println("Process timed out and was killed.");
+               }
+
+        assertTrue("The process was not killed by the watchdog", 
watchdog.killedProcess());        
+        // assertTrue("The process was not properly killed because it took " + 
duration + " ms to execute", duration < 5*1000);
+    }
 }

Added: commons/proper/exec/trunk/src/test/scripts/exec41.bat
URL: 
http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/scripts/exec41.bat?rev=793939&view=auto
==============================================================================
--- commons/proper/exec/trunk/src/test/scripts/exec41.bat (added)
+++ commons/proper/exec/trunk/src/test/scripts/exec41.bat Tue Jul 14 15:23:55 
2009
@@ -0,0 +1,21 @@
+...@echo OFF
+
+REM Little batch file to run nearly foerver
+REM see http://malektips.com/dos0017.html
+REM
+REM Licensed to the Apache Software Foundation (ASF) under one or more
+REM contributor license agreements.  See the NOTICE file distributed with
+REM this work for additional information regarding copyright ownership.
+REM The ASF licenses this file to You under the Apache License, Version 2.0
+REM (the "License"); you may not use this file except in compliance with
+REM the License.  You may obtain a copy of the License at
+REM
+REM      http://www.apache.org/licenses/LICENSE-2.0
+REM
+REM Unless required by applicable law or agreed to in writing, software
+REM distributed under the License is distributed on an "AS IS" BASIS,
+REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+REM See the License for the specific language governing permissions and
+REM limitations under the License.
+
+ping -n %1 -w 1000 127.0.0.1
\ No newline at end of file

Added: commons/proper/exec/trunk/src/test/scripts/exec41.sh
URL: 
http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/scripts/exec41.sh?rev=793939&view=auto
==============================================================================
--- commons/proper/exec/trunk/src/test/scripts/exec41.sh (added)
+++ commons/proper/exec/trunk/src/test/scripts/exec41.sh Tue Jul 14 15:23:55 
2009
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+#
+# 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.
+#
+
+ping -c $1 127.0.0.1

Propchange: commons/proper/exec/trunk/src/test/scripts/exec41.sh
------------------------------------------------------------------------------
    svn:executable = *


Reply via email to