db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1300475 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/junitTests/compatibility/CompatibilityCombinations.java functionTests/tests/replicationTests/ReplicationRun.java junit/NetworkServerTestSetup.java
Date Wed, 14 Mar 2012 07:42:55 GMT
Author: kahatlen
Date: Wed Mar 14 07:42:55 2012
New Revision: 1300475

URL: http://svn.apache.org/viewvc?rev=1300475&view=rev
Log:
DERBY-5643: Occasional hangs in replication tests on Linux

Increase startup timeout to 4 minutes in NetworkServerTestSetup to work
around http://bugs.sun.com/view_bug.do?bug_id=6483406. Make replication
tests and compatibility tests use NetworkServerTestSetup's helper methods
to check if the server is up.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/CompatibilityCombinations.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.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/junitTests/compatibility/CompatibilityCombinations.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/CompatibilityCombinations.java?rev=1300475&r1=1300474&r2=1300475&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/CompatibilityCombinations.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/CompatibilityCombinations.java
Wed Mar 14 07:42:55 2012
@@ -30,6 +30,7 @@ import java.util.*;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
+import org.apache.derbyTesting.junit.NetworkServerTestSetup;
 
 
 
@@ -228,8 +229,6 @@ public class CompatibilityCombinations e
     private static boolean printDebug = false;
     private static boolean showSysinfo = false;
     private static boolean includeUpgrade = false;
-    
-    private static long SLEEP_TIME_MILLIS = 5000L;
 
     /** The process in which the network server is running. */
     private Process serverProc;
@@ -1018,31 +1017,12 @@ public class CompatibilityCombinations e
                     "proc = Runtime.getRuntime().exec(commandElements,envElements,workingDir);"
                  );
 
-            Thread serverThread = new Thread(
-                    new Runnable()
-            {
-                public void run()
-                {
-                    try
-                    {
-                        DEBUG("************** In run().");
-                        serverProc = Runtime.getRuntime().
-                                exec(fullCmd, envElements, workingDir);
-                        DEBUG("************** Done exec().");
-                    }
-                    catch (Exception ex)
-                    {
-                        ex.printStackTrace();
-                    }
-                    
-                }
-            }
-            );
-            DEBUG("************** Do .start().");
-            serverThread.start();
-            pingServer(1, envElements); // Wait for the server to come up in a reasonable
time....
-            serverThread.join();
-            DEBUG("************** Done .join().");
+            serverProc = Runtime.getRuntime().
+                    exec(fullCmd, envElements, workingDir);
+            DEBUG("************** Done exec().");
+
+            // Wait for the server to come up in a reasonable time.
+            pingServer();
         }
         else
         {
@@ -1163,59 +1143,18 @@ public class CompatibilityCombinations e
      * come up in a reasonable amount of time, (re-)throw the
      * final exception.
      * </p>
-     * @param iterations How many times to try pinging the server to see if it is running.
Sleeps <CODE>SLEEP_TIME_MILLIS</CODE> between tries.
-     * @param serverEnvironment Paths used in bringing up server
      * @throws java.lang.Exception .
      */
     // Copied from org.apache.derbyTesting.functionTests.tests.junitTests.compatibility.Pinger
-    private	void	pingServer( int iterations, String[] serverEnvironment )
+    private	void	pingServer( )
     throws Exception
     {
         DEBUG("+++ pingServer");
-        ping( new NetworkServerControl(), iterations, serverEnvironment );
+        NetworkServerControl controller = new NetworkServerControl();
+        NetworkServerTestSetup.pingForServerUp(controller, serverProc, true);
         DEBUG("--- pingServer");
     }
     
-    /**
-     * It used to be possible to ping down-rev servers using an up-rev NetworkServerControl.
-     * This is no longer possible. So we will just take it on faith that the server comes
up after
-     * a decent interval.
-     */
-    private	void	ping( NetworkServerControl controller, int iterations, String[] serverEnvironment
)
-    throws Exception
-    {
-        Exception	finalException = null;
-        
-        for ( int i = 0; i < iterations; i++ )
-        {
-            /*
-            try
-            {
-                controller.ping();
-                // DEBUG("Server came up in less than " + i*(SLEEP_TIME_MILLIS/1000) + "
secs.");
-                return;
-            }
-            catch (Exception e)
-          { finalException = e; }
-            */
-            
-            Thread.sleep( SLEEP_TIME_MILLIS );
-        }
-
-        /*
-        StringBuffer buffer = new StringBuffer();
-        buffer.append( "Server did not come up: " + finalException.getMessage() );
-        int pathCount = serverEnvironment.length;
-        for ( int i = 0; i < pathCount; i++ )
-        {
-            buffer.append( "\n\t" + serverEnvironment[ i ] );
-        }
-        System.out.println( buffer.toString() );
-        finalException.printStackTrace();
-        */
-        
-    }
-    
     
     private void stopServer(int serverVM, int serverVersion)
     {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java?rev=1300475&r1=1300474&r2=1300475&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java
Wed Mar 14 07:42:55 2012
@@ -35,6 +35,7 @@ import org.apache.derby.jdbc.ClientDataS
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.BaseTestCase;
+import org.apache.derbyTesting.junit.NetworkServerTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
@@ -123,7 +124,6 @@ public class ReplicationRun extends Base
     final static String PS = File.pathSeparator;
     
     static boolean showSysinfo = false;
-    static long PINGSERVER_SLEEP_TIME_MILLIS = 500L;
     
     static long sleepTime = 5000L; // millisecs.
     
@@ -136,8 +136,6 @@ public class ReplicationRun extends Base
     
     static final String remoteShell = "/usr/bin/ssh -x"; // or /usr/bin/ssh ?
 
-    private static final long DEFAULT_SERVER_START_TIMEOUT = 75000;
-    
     Utils util = new Utils();
     
     State state = new State();
@@ -2119,15 +2117,11 @@ public class ReplicationRun extends Base
                 }
             }
             );
-            // DERBY-4564. Make replication tests use derby.tests.networkServerTimeout proeprty
-            String userStartTimeout = getSystemProperty("derby.tests.networkServerStartTimeout");
-            long startTimeout = (userStartTimeout != null )? 
-            		(Long.parseLong(userStartTimeout) * 1000): DEFAULT_SERVER_START_TIMEOUT;
-            long iterations = startTimeout / PINGSERVER_SLEEP_TIME_MILLIS;		
             util.DEBUG(debugId+"************** Do .start().");
             serverThread.start();
             registerThread(serverThread);
-            pingServer(serverHost, serverPort, (int) iterations); // Wait for the server
to come up in a reasonable time....
+            // Wait for the server to come up in a reasonable time.
+            pingServer(serverHost, serverPort);
 
         }
         
@@ -2428,40 +2422,15 @@ public class ReplicationRun extends Base
         helperThreads.add(thread);
     }
 
-    private void pingServer( String hostName, int port, int iterations)
+    private void pingServer( String hostName, int port)
     throws Exception
     {
         util.DEBUG("+++ pingServer: " + hostName +":" + port);
-        ping( new NetworkServerControl(InetAddress.getByName(hostName),port), iterations);
+        NetworkServerControl controller =
+            new NetworkServerControl(InetAddress.getByName(hostName), port);
+        NetworkServerTestSetup.pingForServerStart(controller);
         util.DEBUG("--- pingServer: " + hostName +":" + port);
     }
-    
-    private	void ping( NetworkServerControl controller, int iterations )
-    throws Exception
-    {
-        Exception	finalException = null;
-        
-        for ( int i = 0; i < iterations; i++ )
-        {
-            try
-            {
-                controller.ping();
-                util.DEBUG("Server came up in less than "+i+" * "+PINGSERVER_SLEEP_TIME_MILLIS+"ms.");
-                return;
-            }
-            catch (Exception e)
-            { finalException = e; }
-            
-            Thread.sleep( PINGSERVER_SLEEP_TIME_MILLIS  );
-        }
-        
-        String msg = "Could not ping in " 
-                + iterations + " * " + PINGSERVER_SLEEP_TIME_MILLIS + "ms.: "
-                + finalException.getMessage();
-        util.DEBUG( msg );
-        throw finalException;
-        
-    }
 
     void startOptionalLoad(Load load,
             String dbSubPath,

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?rev=1300475&r1=1300474&r2=1300475&view=diff
==============================================================================
--- 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
Wed Mar 14 07:42:55 2012
@@ -43,19 +43,27 @@ import org.apache.derby.drda.NetworkServ
  */
 final public class NetworkServerTestSetup extends BaseTestSetup {
 
-    /** Setting maximum wait time to 40 seconds by default.  On some platforms
-     * it may take this long to start the server.  Increasing the wait
-     *  time should not adversely affect those
+    /**
+     * <p>
+     * Setting maximum wait time to 4 minutes by default. On some platforms
+     * it may take this long to start the server. See for example
+     * <a href="http://bugs.sun.com/view_bug.do?bug_id=6483406">this JVM
+     * bug</a> that sometimes makes server startup take more than 3 minutes.
+     * </p>
+     *
+     * <p>
+     * Increasing the wait time should not adversely affect those
      *  systems with fast port turnaround as the actual code loops for 
      *  SLEEP_TIME intervals, so should never see WAIT_TIME.
      *  For even slower systems (or for faster systems) the default value can
      *  be overwritten using the property derby.tests.networkServerStartTimeout
      *  (which is in seconds, rather than milliseconds)
+     * </p>
      */
-    private static final long DEFAULT_WAIT_TIME = 40000;
+    private static final long DEFAULT_WAIT_TIME = 240000;
     private static final long WAIT_TIME = getWaitTime();
     
-    /** Sleep for 500 ms before pinging the network server (again) */
+    /** Sleep for 100 ms before pinging the network server (again) */
     private static final int SLEEP_TIME = 100;
 
     public static final String HOST_OPTION = "-h";
@@ -640,13 +648,15 @@ final public class NetworkServerTestSetu
         while (true) {
             try {
                 networkServerController.ping();
-                if (expectServerUp)
-                    return true;
-                else
-                {
-                    if (System.currentTimeMillis() - startTime > waitTime) {
-                        return true;
+                long elapsed = System.currentTimeMillis() - startTime;
+                if (expectServerUp) {
+                    if (elapsed > 60000L) {
+                        BaseTestCase.alarm(
+                            "Very slow server startup: " + elapsed + " ms");
                     }
+                    return true;
+                } else if (elapsed > waitTime) {
+                    return true;
                 }
             } catch (Throwable e) {
                 if ( !vetPing( e ) )
@@ -711,14 +721,16 @@ final public class NetworkServerTestSetu
         return pingForServerUp(control, null, true);
     }
     
-    /*
-     * set the period before network server times out on start up based on the
+    /**
+     * Set the period before network server times out on start up based on the
      * value passed in with property derby.tests.networkServerStartTimeout
-     * in seconds, or use the default
-     * for example: with DEFAULT_WAIT_TIME set to 40000, i.e. 40 seconds,
+     * in seconds, or use the default.
+     * For example: with DEFAULT_WAIT_TIME set to 240000, i.e. 4 minutes,
      * setting the property like so: 
-     *          -Dderby.tests.networkServerStartTimeout=60
-     * would extend the timeout to 1 minute.
+     * <pre>
+     *          -Dderby.tests.networkServerStartTimeout=600
+     * </pre>
+     * would extend the timeout to 10 minutes.
      * If an invalid value is passed in (eg. 'abc') the calling test will fail
      */
     public static long getWaitTime() {
@@ -730,9 +742,9 @@ final public class NetworkServerTestSetu
             try {
                 waitTime = (Long.parseLong(waitString)*1000);
             } catch (Exception e) {
-                e.printStackTrace();
-                fail("trouble setting WAIT_TIME from passed in property " +
-                        "derby.tests.networkServerStartTimeout");
+                BaseTestCase.fail(
+                        "trouble setting WAIT_TIME from passed in property " +
+                        "derby.tests.networkServerStartTimeout", e);
             }
         }
         return waitTime;



Mime
View raw message