You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2007/05/29 09:53:55 UTC

svn commit: r542449 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/derbynet/SecureServerTest.java junit/NetworkServerTestSetup.java

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 <code>Process</code> object for the server process.
+     *
+     * @param a <code>Process</code> object, or <code>null</code> 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 <code>null</code>)
+     * @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);
     }
 }