From derby-commits-return-7460-apmail-db-derby-commits-archive=db.apache.org@db.apache.org Tue May 29 07:54:17 2007 Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 15517 invoked from network); 29 May 2007 07:54:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 May 2007 07:54:16 -0000 Received: (qmail 16092 invoked by uid 500); 29 May 2007 07:54:21 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 16061 invoked by uid 500); 29 May 2007 07:54:21 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 16047 invoked by uid 99); 29 May 2007 07:54:21 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 May 2007 00:54:21 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 May 2007 00:54:16 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 9EA1F1A981D; Tue, 29 May 2007 00:53:55 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r542449 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/derbynet/SecureServerTest.java junit/NetworkServerTestSetup.java Date: Tue, 29 May 2007 07:53:55 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070529075355.9EA1F1A981D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Tue May 29 00:53:54 2007 New Revision: 542449 URL: http://svn.apache.org/viewvc?view=rev&rev=542449 Log: DERBY-2714: SecureServerTest spends five minutes waiting for a server to start Abort waiting for the server to come up if the server process has terminated. Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java?view=diff&rev=542449&r1=542448&r2=542449 ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java Tue May 29 00:53:54 2007 @@ -95,6 +95,8 @@ private static final Outcome RUNNING_SECURITY_NOT_BOOTED = new Outcome( true, "" ); private static final Outcome RUNNING_SECURITY_BOOTED = new Outcome( true, serverBootedOK() ); + /** Reference to the enclosing NetworkServerTestSetup. */ + private NetworkServerTestSetup nsTestSetup; // startup state private boolean _unsecureSet; @@ -214,7 +216,7 @@ String[] startupProperties = getStartupProperties( authenticationRequired, useCustomDerbyProperties ); String[] startupArgs = getStartupArgs( unsecureSet ); - Test testSetup = SecurityManagerSetup.noSecurityManager( + NetworkServerTestSetup networkServerTestSetup = new NetworkServerTestSetup ( secureServerTest, @@ -223,7 +225,12 @@ true, secureServerTest._outcome.serverShouldComeUp(), secureServerTest._inputStreamHolder - )); + ); + + secureServerTest.nsTestSetup = networkServerTestSetup; + + Test testSetup = + SecurityManagerSetup.noSecurityManager(networkServerTestSetup); // if using the custom derby.properties, copy the custom properties to a visible place if ( useCustomDerbyProperties ) @@ -366,7 +373,9 @@ private boolean serverCameUp() throws Exception { - return NetworkServerTestSetup.pingForServerStart( NetworkServerTestSetup.getNetworkServerControl() ); + return NetworkServerTestSetup.pingForServerStart( + NetworkServerTestSetup.getNetworkServerControl(), + nsTestSetup.getServerProcess()); } } Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java?view=diff&rev=542449&r1=542448&r2=542449 ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java Tue May 29 00:53:54 2007 @@ -67,6 +67,7 @@ private final InputStream[] inputStreamHolder; private final String[] systemProperties; private final String[] startupArgs; + private Process serverProcess; /** * Decorator this test with the NetworkServerTestSetup @@ -115,7 +116,7 @@ networkServerController = getNetworkServerControl(); if (useSeparateProcess) - { startSeparateProcess(); } + { serverProcess = startSeparateProcess(); } else if (asCommand) { startWithCommand(); } else @@ -164,7 +165,7 @@ }, "NetworkServerTestSetup command").start(); } - private void startSeparateProcess() throws Exception + private Process startSeparateProcess() throws Exception { StringBuffer buffer = new StringBuffer(); String classpath = BaseTestCase.getSystemProperty( "java.class.path" ); @@ -219,6 +220,17 @@ ); inputStreamHolder[ 0 ] = serverProcess.getInputStream(); + return serverProcess; + } + + /** + * Returns the Process object for the server process. + * + * @param a Process object, or null if the + * network server does not run in a separate process + */ + public Process getServerProcess() { + return serverProcess; } /** @@ -241,6 +253,11 @@ if ( serverOutput != null ) { serverOutput.close(); } networkServerController = null; serverOutput = null; + + if (serverProcess != null) { + serverProcess.waitFor(); + serverProcess = null; + } } } @@ -303,8 +320,13 @@ * Ping server for upto sixty seconds. If the server responds * in that time then return true, otherwise return false. * + * @param networkServerController controller object for network server + * @param serverProcess the external process in which the server runs + * (could be null) + * @return true if server responds in time, false otherwise */ - public static boolean pingForServerStart(NetworkServerControl networkServerController) + public static boolean pingForServerStart( + NetworkServerControl networkServerController, Process serverProcess) throws InterruptedException { final long startTime = System.currentTimeMillis(); @@ -318,6 +340,26 @@ return false; } } + if (serverProcess != null) { + // if the server runs in a separate process, check whether the + // process is still alive + try { + int exitVal = serverProcess.exitValue(); + // When exitValue() returns successfully, the server + // process must have terminated. No point in pinging the + // server anymore. + return false; + } catch (IllegalThreadStateException e) { + // This exception is thrown by Process.exitValue() if the + // process has not terminated. Keep on pinging the server. + } + } } + } + + public static boolean pingForServerStart(NetworkServerControl control) + throws InterruptedException + { + return pingForServerStart(control, null); } }