Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4DDC51790F for ; Sat, 9 Jan 2016 16:56:55 +0000 (UTC) Received: (qmail 83616 invoked by uid 500); 9 Jan 2016 16:56:55 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 83459 invoked by uid 500); 9 Jan 2016 16:56:54 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 83447 invoked by uid 99); 9 Jan 2016 16:56:54 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Jan 2016 16:56:54 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 2F98B180296 for ; Sat, 9 Jan 2016 16:56:54 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.101 X-Spam-Level: X-Spam-Status: No, score=-0.101 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id GawpB0rjBRr1 for ; Sat, 9 Jan 2016 16:56:46 +0000 (UTC) Received: from mail-yk0-f172.google.com (mail-yk0-f172.google.com [209.85.160.172]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 7DC8420D47 for ; Sat, 9 Jan 2016 16:56:46 +0000 (UTC) Received: by mail-yk0-f172.google.com with SMTP id k129so370733308yke.0 for ; Sat, 09 Jan 2016 08:56:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=dGVowR7kFtZ2yC0F9HvBY4ey3za/7Dcwd9XtTBvk4AE=; b=b3QeR7JWsn8yvEcXV1ik+L+91Y484KUaWlsqNwDvkGX5aYEQ4zHowipuArYCsW36r9 95eKbhzilQQpt4c5+MqXTO45ER82HlrHmrXTNmGO34g8SiJkVOQyOYV3cdE6xb1KImS1 Y+KheTS8ZKdv3lZIAX4egrvr6ayZ8emBJgXWkawkFudmBHKFOxOp0me9rM9HIS3EUWaf Io7NB/12DRSp49Fy1k9tPqzisq1SH4DFujqBjocWrhZHHTdrG7sn4Q/6Esj8HweIJN2P 3m8uQtxRBT4fB2gf/RHMyuXngkDcxQnTp8vvzG1mpUch81UxLFk2m/ehZsbj4ytb8D22 zveQ== MIME-Version: 1.0 X-Received: by 10.13.247.70 with SMTP id h67mr83936281ywf.3.1452358605734; Sat, 09 Jan 2016 08:56:45 -0800 (PST) Received: by 10.13.210.66 with HTTP; Sat, 9 Jan 2016 08:56:45 -0800 (PST) In-Reply-To: <20160108202133.568553A00E7@svn01-us-west.apache.org> References: <20160108202133.568553A00E7@svn01-us-west.apache.org> Date: Sat, 9 Jan 2016 16:56:45 +0000 Message-ID: Subject: Re: svn commit: r1723790 - /commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec65Test.java From: sebb To: dev@commons.apache.org Content-Type: text/plain; charset=UTF-8 On 8 January 2016 at 20:21, wrote: > Author: sgoeschl > Date: Fri Jan 8 20:21:33 2016 > New Revision: 1723790 > > URL: http://svn.apache.org/viewvc?rev=1723790&view=rev > Log: > [EXEC-65] Fixing test execution for Windows platform > > Modified: > commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec65Test.java > > Modified: commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec65Test.java > URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec65Test.java?rev=1723790&r1=1723789&r2=1723790&view=diff > ============================================================================== > --- commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec65Test.java (original) > +++ commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec65Test.java Fri Jan 8 20:21:33 2016 > @@ -24,8 +24,9 @@ import org.apache.commons.exec.ExecuteWa > import org.apache.commons.exec.OS; > import org.apache.commons.exec.PumpStreamHandler; > import org.apache.commons.exec.TestUtil; > -import org.junit.Ignore; > +import org.junit.Rule; > import org.junit.Test; > +import org.junit.rules.TestName; > > import java.io.File; > > @@ -38,67 +39,82 @@ import static org.junit.Assert.assertTru > */ > public class Exec65Test { > > - private static final int TIMEOUT = 3000; > + private static final int TEST_TIMEOUT = 15000; > + private static final int WATCHDOG_TIMEOUT = 3000; > + private static final String OS_NAME = System.getProperty("os.name"); > + > private final File testDir = new File("src/test/scripts"); > > - @Test(expected = ExecuteException.class, timeout = 15000) > - public void testExec65WitSleepUsingCommandLine() throws Exception > - { > - if(OS.isFamilyUnix()) > - { > + @Rule public TestName name = new TestName(); > + > + @Test(expected = ExecuteException.class, timeout = TEST_TIMEOUT) > + public void testExec65WitSleepUsingSleepCommandDirectly() throws Exception { > + > + if (OS.isFamilyUnix()) { > + final ExecuteWatchdog watchdog = new ExecuteWatchdog(WATCHDOG_TIMEOUT); > final DefaultExecutor executor = new DefaultExecutor(); > - executor.setStreamHandler(new PumpStreamHandler(System.out, System.err)); > - final ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT); > - executor.setWatchdog(watchdog); > final CommandLine command = new CommandLine("sleep"); > command.addArgument("60"); > + executor.setStreamHandler(new PumpStreamHandler(System.out, System.err)); > + executor.setWatchdog(watchdog); > > executor.execute(command); > + } else { > + String msg = String.format("The test '%s' does not support the following OS : %s", name.getMethodName(), OS_NAME); > + System.out.println(msg); > + throw new ExecuteException(msg, 0); > } > } > > - @Test(expected = ExecuteException.class, timeout = 15000) > - public void testExec65WithSleepUsingShellScript() throws Exception > - { > + @Test(expected = ExecuteException.class, timeout = TEST_TIMEOUT) > + public void testExec65WithSleepUsingShellScript() throws Exception { > + > final DefaultExecutor executor = new DefaultExecutor(); > executor.setStreamHandler(new PumpStreamHandler(System.out, System.err)); > - final ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT); > - executor.setWatchdog(watchdog); > + executor.setWatchdog(new ExecuteWatchdog(WATCHDOG_TIMEOUT)); > final CommandLine command = new CommandLine(TestUtil.resolveScriptForOS(testDir + "/sleep")); > > executor.execute(command); > } > > - @Ignore("This test does not work under Linux but nicely on Mac OS X") > - @Test(timeout = 15000) > - public void testExec65WithSleepUsingShellScriptAndRuntimeDirectly() throws Exception > - { > + /** > + * This is the original code snippet from the JIRA to show that > + * killing the process actually works with JDK only but it does > + * not re-direct any streams. > + */ > + @Test(timeout = TEST_TIMEOUT) > + public void testExec65WithSleepUsingShellScriptAndJDKOnly() throws Exception { > + > Process process = Runtime.getRuntime().exec(TestUtil.resolveScriptForOS(testDir + "/sleep").getAbsolutePath()); > - Thread.sleep(3000); > + Thread.sleep(WATCHDOG_TIMEOUT); > > process.destroy(); > - > - process.waitFor(); > + while (process.isAlive()) { > + Thread.sleep(100); > + } This requires Java 1.8 Besides, it's unnecessary. I've reverted to the previous fix I made. > assertTrue(process.exitValue() != 0); > } > > /** > * Please note that this tests make assumptions about the environment. It assumes > - * that user "root" exists and that the current user is not a "sudoer" already. > + * that user "root" exists and that the current user is not a "sudoer" already > + * (thereby requiring a password). > */ > - @Test(expected = ExecuteException.class, timeout = 15000) > - public void testExec65WithSudoUsingShellScript() throws Exception > - { > - if(OS.isFamilyUnix()) > - { > + @Test(expected = ExecuteException.class, timeout = TEST_TIMEOUT) > + public void testExec65WithSudoUsingShellScript() throws Exception { > + > + if (OS.isFamilyUnix()) { > final DefaultExecutor executor = new DefaultExecutor(); > executor.setStreamHandler(new PumpStreamHandler(System.out, System.err, System.in)); > - final ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT); > - executor.setWatchdog(watchdog); > + executor.setWatchdog(new ExecuteWatchdog(WATCHDOG_TIMEOUT)); > final CommandLine command = new CommandLine(TestUtil.resolveScriptForOS(testDir + "/issues/exec-65")); > > executor.execute(command); > + } else { > + String msg = String.format("The test '%s' does not support the following OS : %s", name.getMethodName(), OS_NAME); > + System.out.println(msg); > + throw new ExecuteException(msg, 0); > } > } > } > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org