[EXEC-62] Add test case to ensure that we can indeed interrupt the process

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/exec/trunk@1723345 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/test/java/org/apache/commons/exec/issues/Exec62Test.java b/src/test/java/org/apache/commons/exec/issues/Exec62Test.java
new file mode 100644
index 0000000..26b89ff
--- /dev/null
+++ b/src/test/java/org/apache/commons/exec/issues/Exec62Test.java
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+package org.apache.commons.exec.issues;
+
+import org.apache.commons.exec.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * @see <a href="https://issues.apache.org/jira/browse/EXEC-62">EXEC-62</a>
+ */
+public class Exec62Test
+{
+    private File outputFile;
+
+    @Before
+    public void setUp() throws Exception {
+        outputFile = File.createTempFile("foo", ".log");
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        outputFile.delete();
+    }
+
+    @Test (expected = TimeoutException.class, timeout = 10000)
+    public void testMe() throws Exception {
+        if(OS.isFamilyUnix()) {
+            execute ("exec-62");
+        }
+    }
+
+    private void execute (String scriptName) throws Exception {
+        ExecuteWatchdog watchdog = new ExecuteWatchdog(4000);
+        CommandLine commandLine = new CommandLine("/bin/sh");
+        File testScript = TestUtil.resolveScriptForOS("./src/test/scripts/issues/" + scriptName);
+
+        commandLine.addArgument(testScript.getAbsolutePath());
+
+        DefaultExecutor executor = new DefaultExecutor();
+        executor.setExitValues(null); // ignore exit values
+        executor.setWatchdog(watchdog);
+
+        FileOutputStream fos = new FileOutputStream(outputFile);
+        PumpStreamHandler streamHandler = new PumpStreamHandler(fos);
+        executor.setStreamHandler(streamHandler);
+        executor.execute(commandLine);
+
+        if (watchdog.killedProcess()) {
+            throw new TimeoutException(String.format("Transcode process was killed on timeout %1$s ms, command line %2$s", 4000, commandLine.toString()));
+        }
+    }
+}
+
+
diff --git a/src/test/scripts/issues/exec-62.sh b/src/test/scripts/issues/exec-62.sh
new file mode 100644
index 0000000..fd3403a
--- /dev/null
+++ b/src/test/scripts/issues/exec-62.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+Echo simulate timeout
+cat /dev/urandom &
+cat /dev/urandom >&2 &
+sleep 15
\ No newline at end of file