db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r798700 - in /db/derby/code/branches/10.5: ./ java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/
Date Tue, 28 Jul 2009 20:27:55 GMT
Author: dag
Date: Tue Jul 28 20:27:54 2009
New Revision: 798700

URL: http://svn.apache.org/viewvc?rev=798700&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

Backported fix to 10.5 branch as 

svn merge -c 769602  https://svn.eu.apache.org/repos/asf/db/derby/code/trunk


Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_3_p3.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 28 20:27:54 2009
@@ -1 +1 @@
-/db/derby/code/trunk:769596,772090,772449,772534,774281,779681,782991,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793588,794955,795166,796020,796027,797147
+/db/derby/code/trunk:769596,769602,772090,772449,772534,774281,779681,782991,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793588,794955,795166,796020,796027,797147

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_3_p3.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_3_p3.java?rev=798700&r1=798699&r2=798700&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_3_p3.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_3_p3.java
Tue Jul 28 20:27:54 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/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java?rev=798700&r1=798699&r2=798700&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java
Tue Jul 28 20:27:54 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/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java?rev=798700&r1=798699&r2=798700&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java
Tue Jul 28 20:27:54 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:"  



Mime
View raw message