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 da...@apache.org on 2013/04/14 05:19:00 UTC

svn commit: r1467722 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/replicationTests/ReplicationRun_Local.java junit/NetworkServerTestSetup.java

Author: dag
Date: Sun Apr 14 03:19:00 2013
New Revision: 1467722

URL: http://svn.apache.org/r1467722
Log:
DERBY-6179 Insert some guarding code into the first replication test to check port availability

Patch replscratch: checks the availability of the ports needed for the
replication test testReplication_Local_TestStraightReplication (the
first fixture) of the first test in the replication suite. This should
make it readily apparent in test log if there is such a
problem. Presently one needs to dig into the master or slaves' log
files to find that root cause.


Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local.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/replicationTests/ReplicationRun_Local.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local.java?rev=1467722&r1=1467721&r2=1467722&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local.java Sun Apr 14 03:19:00 2013
@@ -24,6 +24,7 @@ import java.sql.SQLException;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.NetworkServerTestSetup;
 import org.apache.derbyTesting.junit.SecurityManagerSetup;
 
 
@@ -103,6 +104,10 @@ public class ReplicationRun_Local extend
         initMaster(masterServerHost,
                 replicatedDb);
         
+        NetworkServerTestSetup.waitForAvailablePort(masterServerPort);
+        NetworkServerTestSetup.waitForAvailablePort(slaveServerPort);
+        NetworkServerTestSetup.waitForAvailablePort(slaveReplPort);
+
         startServer(masterJvmVersion, derbyMasterVersion,
                 masterServerHost,
                 ALL_INTERFACES, // masterServerHost, // "0.0.0.0", // All. or use masterServerHost for interfacesToListenOn,

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=1467722&r1=1467721&r2=1467722&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 Sun Apr 14 03:19:00 2013
@@ -240,10 +240,36 @@ final public class NetworkServerTestSetu
      */
     public static void waitForAvailablePort()
             throws InterruptedException, UnknownHostException {
+        waitForAvailablePort(-1);
+    }
+
+
+    /**
+     * Wait until the specified port has been released by
+     * by earlier test cases, or until the timeout specified by
+     * {@link #getWaitTime()} has elapsed.
+     *
+     * @param port If -1, use default port for configuration, else use this
+     *             value.
+     * @throws AssertionFailedError if the port didn't become available before
+     * the timeout
+     * @throws InterruptedException if the thread was interrupted while waiting
+     * for the port to become available
+     * @throws UnknownHostException if the host name couldn't be resolved
+     */
+    public static void waitForAvailablePort(int port)
+            throws InterruptedException, UnknownHostException {
+
         TestConfiguration conf = TestConfiguration.getCurrent();
         InetAddress serverAddress = InetAddress.getByName(conf.getHostName());
-        int port = conf.getPort();
+
+        if (port == -1) {
+            port = conf.getPort();
+        }
+
         long giveUp = System.currentTimeMillis() + getWaitTime();
+        BaseTestCase.println(
+                "probing port for availability: " + serverAddress + ":" + port);
 
         while (true) {
             try {
@@ -254,7 +280,8 @@ final public class NetworkServerTestSetu
                     Thread.sleep(SLEEP_TIME);
                 } else {
                     BaseTestCase.fail(
-                        getTimeoutErrorMsg("server port to become available"),
+                        getTimeoutErrorMsg("server port to become available",
+                            port),
                         ioe);
                 }
             }
@@ -714,11 +741,16 @@ final public class NetworkServerTestSetu
     }
 
     /** Returns an error message for timeouts including the port and host. */
-    private static String getTimeoutErrorMsg(String failedAction) {
+    private static String getTimeoutErrorMsg(String failedAction, int port) {
         TestConfiguration conf = TestConfiguration.getCurrent();
-        int port = conf.getPort();
         String host = conf.getHostName();
         return "Timed out waiting for " +
                 failedAction + " (" + host + ":" + port + ")";
     }
+
+    private static String getTimeoutErrorMsg(String failedAction) {
+        TestConfiguration conf = TestConfiguration.getCurrent();
+        int port = conf.getPort();
+        return getTimeoutErrorMsg(failedAction, port);
+    }
 }