db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1213251 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java
Date Mon, 12 Dec 2011 14:17:55 GMT
Author: kahatlen
Date: Mon Dec 12 14:17:55 2011
New Revision: 1213251

URL: http://svn.apache.org/viewvc?rev=1213251&view=rev
Log:
DERBY-5517: testReplication_Local_3_p1_StateNegativeTests failed with connection refused

Make sure server processes in one test case have stopped before the next
test case is started.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java

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=1213251&r1=1213250&r2=1213251&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
Mon Dec 12 14:17:55 2011
@@ -26,6 +26,7 @@ import org.apache.derby.drda.NetworkServ
 import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.Properties;
 
 import java.sql.*;
@@ -162,6 +163,13 @@ public class ReplicationRun extends Base
     private volatile Exception startSlaveException = null;
 
     /**
+     * List of threads that have been started by the tests and not explicitly
+     * waited for. Wait for these to complete in {@link #tearDown()} so that
+     * they don't interfere with subsequent test cases.
+     */
+    private ArrayList helperThreads = new ArrayList();
+
+    /**
      * Creates a new instance of ReplicationRun
      * @param testcaseName Identifying the test.
      */
@@ -193,6 +201,13 @@ public class ReplicationRun extends Base
         stopServer(jvmVersion, derbyVersion,
                 masterServerHost, masterServerPort);
 
+        // Wait for all threads to complete.
+        for (Iterator it = helperThreads.iterator(); it.hasNext(); ) {
+            Thread t = (Thread) it.next();
+            t.join();
+        }
+        helperThreads = null;
+
         super.tearDown();
     }
     
@@ -1201,6 +1216,7 @@ public class ReplicationRun extends Base
             }
             );
             connThread.start();
+            registerThread(connThread);
             util.DEBUG("startSlave_direct exit.");
     }
     
@@ -1715,6 +1731,7 @@ public class ReplicationRun extends Base
             );
             util.DEBUG(ID+"************** Do .start(). ");
             serverThread.start();
+            registerThread(serverThread);
             // serverThread.join();
             // DEBUG(ID+"************** Done .join().");
             
@@ -2123,6 +2140,7 @@ public class ReplicationRun extends Base
             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....
 
         }
@@ -2399,6 +2417,16 @@ public class ReplicationRun extends Base
         
     }
 
+    /**
+     * Register that a thread has been started so that we can wait for it to
+     * complete in {@link #tearDown()}.
+     *
+     * @param thread a thread that has been started
+     */
+    private void registerThread(Thread thread) {
+        helperThreads.add(thread);
+    }
+
     private void pingServer( String hostName, int port, int iterations)
     throws Exception
     {



Mime
View raw message