commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgoes...@apache.org
Subject svn commit: r1723345 - in /commons/proper/exec/trunk/src/test: java/org/apache/commons/exec/issues/Exec62Test.java scripts/issues/exec-62.sh
Date Wed, 06 Jan 2016 15:12:26 GMT
Author: sgoeschl
Date: Wed Jan  6 15:12:26 2016
New Revision: 1723345

URL: http://svn.apache.org/viewvc?rev=1723345&view=rev
Log:
[EXEC-62] Add test case to ensure that we can indeed interrupt the process

Added:
    commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec62Test.java
    commons/proper/exec/trunk/src/test/scripts/issues/exec-62.sh

Added: commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec62Test.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec62Test.java?rev=1723345&view=auto
==============================================================================
--- commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec62Test.java
(added)
+++ commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec62Test.java
Wed Jan  6 15:12:26 2016
@@ -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()));
+        }
+    }
+}
+
+

Added: commons/proper/exec/trunk/src/test/scripts/issues/exec-62.sh
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/scripts/issues/exec-62.sh?rev=1723345&view=auto
==============================================================================
--- commons/proper/exec/trunk/src/test/scripts/issues/exec-62.sh (added)
+++ commons/proper/exec/trunk/src/test/scripts/issues/exec-62.sh Wed Jan  6 15:12:26 2016
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+Echo simulate timeout
+cat /dev/urandom &
+cat /dev/urandom >&2 &
+sleep 15
\ No newline at end of file



Mime
View raw message