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 2009/04/29 02:44:48 UTC

svn commit: r769602 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests: ReplicationRun_Local_3_p3.java ReplicationRun_Local_StateTest_part1_1.java ReplicationRun_Local_StateTest_part1_2.java

Author: dag
Date: Wed Apr 29 00:44:47 2009
New Revision: 769602

URL: http://svn.apache.org/viewvc?rev=769602&view=rev
Log:
DERBY-4175 Instability in some replication tests under load, since tests don't wait long enough for final state or anticipate intermediate states

Patch derby-4175-3 (+ resolved some conflicts arising from commit of DERBY-3417).

It makes three replication tests less sensitive to load by making
them accept intermediate states without failing or wait for longer
before giving up on seeing the final end state of a replication state
change.


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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_3_p3.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_3_p3.java?rev=769602&r1=769601&r2=769602&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_3_p3.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_3_p3.java Wed Apr 29 00:44:47 2009
@@ -167,7 +167,7 @@
         showCurrentState("Post stopMaster +5s", 5000L,
             slaveDatabasePath + FS + slaveDbSubPath + FS + replicatedDb, 
             slaveServerHost, slaveServerPort); */
-        waitForSQLState("08004", 100L, 20, // 08004.C.7 - CANNOT_CONNECT_TO_DB_IN_SLAVE_MODE
+        waitForSQLState("08004", 1000L, 20, // 08004.C.7 - CANNOT_CONNECT_TO_DB_IN_SLAVE_MODE
                 slaveDatabasePath + FS + slaveDbSubPath + FS + replicatedDb, 
                 slaveServerHost, slaveServerPort);
         /* Got it above... showCurrentState("Post stopMaster +30s", 30000L,
@@ -198,7 +198,7 @@
                 testClientHost); //  XRE07 Could not perform operation because the database is not in replication master mode.
         */
         
-        waitForSQLState("08004", 100L, 20, // 08004.C.7 - CANNOT_CONNECT_TO_DB_IN_SLAVE_MODE
+        waitForSQLState("08004", 1000L, 20, // 08004.C.7 - CANNOT_CONNECT_TO_DB_IN_SLAVE_MODE
                 slaveDatabasePath + FS + slaveDbSubPath + FS + replicatedDb,
                 slaveServerHost, slaveServerPort); // _failOver above fails...
         /*

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java?rev=769602&r1=769601&r2=769602&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java Wed Apr 29 00:44:47 2009
@@ -41,6 +41,7 @@
     final static String REPLICATION_DB_NOT_BOOTED              = "XRE11";
     final static String REPLICATION_NOT_IN_SLAVE_MODE          = "XRE40";
     final static String SLAVE_OPERATION_DENIED_WHILE_CONNECTED = "XRE41";
+    final static String REPLICATION_SLAVE_SHUTDOWN_OK          = "XRE42";
 
     /**
      * Creates a new instance of ReplicationRun_Local_StateTest_part1
@@ -141,7 +142,7 @@
     }
 
     private void _testPostStartedMasterAndSlave_StopSlave()
-    throws InterruptedException
+            throws InterruptedException, SQLException
     {
         String db = null;
         String connectionURL = null;  
@@ -204,7 +205,6 @@
         
         // Take down master - slave connection:
         killMaster(masterServerHost, masterServerPort);
-        Thread.sleep(5000L); // TEMPORARY to see if slave sees that master is gone!
         
         // 3.  stopSlave on slave should now result in an exception stating that
         //     the slave database has been shutdown. A master shutdown results
@@ -217,25 +217,66 @@
                 + ";stopSlave=true";
         boolean stopSlaveCorrect = false;
         util.DEBUG("3. testPostStartedMasterAndSlave_StopSlave: " + connectionURL);
-        try
-        {
-            conn = DriverManager.getConnection(connectionURL); // From anywhere against slaveServerHost?
-            util.DEBUG("Unexpectedly connected: " + connectionURL);
-            assertTrue("Unexpectedly connected: " + connectionURL,false);
+
+        // We use a loop below, to allow for intermediate states before the
+        // expected final state.
+        //
+        // If we get here quick enough we see these error states (in order):
+        //     a) SLAVE_OPERATION_DENIED_WHILE_CONNECTED
+        //     b) REPLICATION_SLAVE_SHUTDOWN_OK
+        //
+        // The final end state is expected to be REPLICATION_DB_NOT_BOOTED.
+        //
+        SQLException gotEx = null;
+        int tries = 20;
+
+        while (tries-- > 0) {
+            gotEx = null;
+
+            try {
+                // From anywhere against slaveServerHost?
+                conn = DriverManager.getConnection(connectionURL); 
+                util.DEBUG("Unexpectedly connected: " + connectionURL);
+                assertTrue("Unexpectedly connected: " + connectionURL,false);
+
+            } catch (SQLException se) {
+                if (se.getSQLState().
+                        equals(SLAVE_OPERATION_DENIED_WHILE_CONNECTED)) {
+                    // Try again, shutdown did not complete yet..
+                    gotEx = se;
+                    util.DEBUG
+                        ("got SLAVE_OPERATION_DENIED_WHILE_CONNECTED, sleep");
+                    Thread.sleep(1000L);
+                    continue;
+
+                } else if (se.getSQLState().
+                               equals(REPLICATION_SLAVE_SHUTDOWN_OK)) {
+                    // Try again, shutdown started but did not complete yet.
+                    gotEx = se;
+                    util.DEBUG("got REPLICATION_SLAVE_SHUTDOWN_OK, sleep..");
+                    Thread.sleep(1000L);
+                    continue;
+
+                } else if (se.getSQLState().equals(REPLICATION_DB_NOT_BOOTED)) {
+                    // All is fine, so proceed
+                    util.DEBUG("Got REPLICATION_DB_NOT_BOOTED as expected");
+                    stopSlaveCorrect = true;
+                    break;
+
+                } else {
+                    // Something else, so report.
+                    gotEx = se;
+                    break;
+                }
+            }
         }
-        catch (SQLException se)
-        {
-            int ec = se.getErrorCode();
-            String ss = se.getSQLState();
-            String msg = ec + " " + ss + " " + se.getMessage();
-            util.DEBUG("3. Got "+msg + " Expected: " + 
-                       REPLICATION_DB_NOT_BOOTED);
-            BaseJDBCTestCase.assertSQLState(
-                connectionURL + " failed: ",
-                REPLICATION_DB_NOT_BOOTED, 
-                se);
-            util.DEBUG("3. Failed as expected: " + connectionURL +  " " + msg);
-            stopSlaveCorrect = true;
+
+        if (gotEx != null) {
+            // We did not get what we expected as the final state
+            // (REPLICATION_DB_NOT_BOOTED) in reasonable time, or we saw
+            // something that is not a legal intermediate state, so we fail
+            // now:
+            throw gotEx;
         }
         
         // Default replication test sequence will NOT be OK after this point.
@@ -247,7 +288,7 @@
                     + "//" + slaveServerHost + ":" + slaveServerPort + "/"
                     + db;
             util.DEBUG("4. testPostStartedMasterAndSlave_StopSlave: " + connectionURL);
-            Thread.sleep(5000L); // TEMP FIX! To avoid 40000 08004 The connection was refused because the database ..../wombat was not found!
+
             try
             {
                 conn = DriverManager.getConnection(connectionURL);
@@ -260,7 +301,6 @@
                 String msg = ec + " " + ss + " " + se.getMessage();
                 util.DEBUG("4. Unexpectedly failed to connect: " + connectionURL +  " " + msg);
                 assertTrue("Unexpectedly failed to connect: " + connectionURL +  " " + msg, false);
-                // CURRENTLY FAILS W/ 40000 08004 The connection was refused because the database /home/os136789/Replication/testing/db_slave/wombat was not found.
             }
         }
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java?rev=769602&r1=769601&r2=769602&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java Wed Apr 29 00:44:47 2009
@@ -39,11 +39,13 @@
 public class ReplicationRun_Local_StateTest_part1_2 extends ReplicationRun
 {
     
+    final static String CANNOT_CONNECT_TO_DB_IN_SLAVE_MODE     = "08004";
     final static String LOGIN_FAILED = "08004";
     final static String REPLICATION_DB_NOT_BOOTED = "XRE11";
     final static String REPLICATION_MASTER_ALREADY_BOOTED = "XRE22";
     final static String REPLICATION_NOT_IN_MASTER_MODE = "XRE07";
     final static String REPLICATION_SLAVE_STARTED_OK = "XRE08";
+
     /**
      * Creates a new instance of ReplicationRun_Local_StateTest_part1
      * 
@@ -144,7 +146,7 @@
 
 
     private void _testPostStartedMasterAndSlave_StopMaster()
-    throws InterruptedException
+            throws InterruptedException, SQLException
     {
         Connection conn = null;
         String db = null;
@@ -210,24 +212,46 @@
                 + "//" + slaveServerHost + ":" + slaveServerPort + "/"
                 + db;
         util.DEBUG("3. testPostStartedMasterAndSlave_StopMaster: " + connectionURL);
-        // Try a sleep:
-        Thread.sleep(15000L);
-        try
-        {
-            conn = DriverManager.getConnection(connectionURL);
-            util.DEBUG("Successfully connected: " + connectionURL);
+
+        // We use a loop below, to allow for intermediate states before success.
+        // If we get here quick enough, we see this error state:
+        //     CANNOT_CONNECT_TO_DB_IN_SLAVE_MODE
+        //
+        SQLException gotEx = null;
+        int tries = 20;
+
+        while (tries-- > 0) {
+            gotEx = null;
+            try {
+                conn = DriverManager.getConnection(connectionURL);
+                util.DEBUG("Successfully connected: " + connectionURL);
+                break;
+            } catch (SQLException se) {
+                gotEx = se;
+                if (se.getSQLState().
+                        equals(CANNOT_CONNECT_TO_DB_IN_SLAVE_MODE)) {
+                    // Try again, shutdown did not complete yet..
+                    util.DEBUG("got CANNOT_CONNECT_TO_DB_IN_SLAVE_MODE, sleep");
+                    Thread.sleep(1000L);
+                    continue;
+
+                } else {
+                    // Something else, so report.
+                    break;
+                }
+            }
         }
-        catch (SQLException se)
-        {
-            int ec = se.getErrorCode();
-            String ss = se.getSQLState();
-            String msg = ec + " " + ss + " " + se.getMessage();
-            util.DEBUG("3. Connect to slave unexpectedly failed : " 
-                    + connectionURL + " " + msg);
-            assertTrue("3. Connect to slave unexpectedly failed : " 
-                    + connectionURL + " " + msg, false);
+
+        if (gotEx != null) {
+            // We did not get what we expected as the final state (connect
+            // success) in reasonable time, or we saw something that is not a
+            // legal intermediate state, so we fail now:
+
+            util.DEBUG("3. failed to connect to ex-slave");
+            throw gotEx;
         }
-        
+
+
         // 4. stopMaster on slave which now is not in replication mode should fail.
         db = slaveDatabasePath +FS+ReplicationRun.slaveDbSubPath +FS+ replicatedDb;
         connectionURL = "jdbc:derby:"