db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oyste...@apache.org
Subject svn commit: r640506 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests: ReplicationRun.java Utils.java
Date Mon, 24 Mar 2008 18:34:27 GMT
Author: oysteing
Date: Mon Mar 24 11:34:25 2008
New Revision: 640506

URL: http://svn.apache.org/viewvc?rev=640506&view=rev
Log:
DERBY-3162: Fix to allow ReplicationSuite to run on JVM 1.4 and 1.5:
Contributed by Ole Solberg.

The replicationTest framework (ReplicationRun) used Drivermanager.getConnection()
to do startMaster=true and startSlave=true concurrently.
On 1.5 (and 1.4), but not on 1.6, it turned out that this caused a deadlock (on DriverManager.class?).
Using DataSource instead of DriverManager solved the problem.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Utils.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=640506&r1=640505&r2=640506&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 Mar 24 11:34:25 2008
@@ -29,6 +29,7 @@
 
 import java.sql.*;
 import java.io.*;
+import org.apache.derby.jdbc.ClientDataSource;
 import org.apache.derby.shared.common.reference.SQLState;
 
 import org.apache.derbyTesting.junit.BaseTestCase;
@@ -859,8 +860,21 @@
             {
                 try
                 {
+                    /* On 1.5 locking of Drivermanager.class prevents
+                     * using DriverManager.getConnection() concurrently
+                     * in startMaster and startSlave!
                     Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes!
                     conn = DriverManager.getConnection(URL);
+                     */
+                    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
+                    ds.setDatabaseName(masterDatabasePath+FS+masterDbSubPath+FS+dbName);
+                    ds.setServerName(masterHost);
+                    ds.setPortNumber(masterServerPort);
+                    ds.setConnectionAttributes("startMaster=true"
+                            +";slaveHost="+slaveReplInterface
+                            +";slavePort="+slaveReplPort);
+                    conn = ds.getConnection();
+                    
                     done = true;
                     conn.close();
                     util.DEBUG("startMaster OK");
@@ -871,7 +885,7 @@
                     String msg = se.getMessage();
                     String state = se.getSQLState();
                     String expectedState = "XRE04";
-                    util.DEBUG("startSlave Got SQLException: " 
+                    util.DEBUG("startMaster Got SQLException: " 
                             + errCode + " " + state + " " + msg);
                     if ( (errCode == -1)
                     && (state.equalsIgnoreCase(expectedState) ) )
@@ -1046,6 +1060,12 @@
         
             util.DEBUG("startSlave_direct getConnection("+URL+")");
             
+            final String fDbPath = slaveDatabasePath+FS+slaveDbSubPath+FS+dbName;
+            final String fSlaveHost = slaveHost;
+            final int fSlaveServerPort = slaveServerPort;
+            final String fConnAttrs = "startSlave=true"
+                                +";slaveHost="+slaveReplInterface
+                                +";slavePort="+slaveReplPort;
             Thread connThread = new Thread(
                     new Runnable()
             {
@@ -1054,9 +1074,19 @@
                     Connection conn = null;
                     try {
                         // NB! WIll hang here until startMaster is executed!
+                        /*On 1.5 locking of Drivermanager.class prevents
+                         * using DriverManager.getConnection() concurrently
+                         * in startMaster and startSlave!
                         Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes!
                         conn = DriverManager.getConnection(URL);
-                        // conn.close();
+                         */
+                        ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
+                        ds.setDatabaseName(fDbPath);
+                        ds.setServerName(fSlaveHost);
+                        ds.setPortNumber(fSlaveServerPort);
+                        ds.setConnectionAttributes(fConnAttrs);
+                        conn = ds.getConnection();
+                        conn.close();
                     }
                     catch (SQLException se)
                     {
@@ -1069,17 +1099,18 @@
                         && (state.equalsIgnoreCase(expectedState) ) )
                         {
                             util.DEBUG("As expected.");
-
                         }
                         else
                         {
-                            se.printStackTrace(); // FIXME!
+                            util.DEBUG("Got Exception " + msg);
+                            se.printStackTrace();
                         }
                         ;
                     }
                     catch (Exception ex)
                     {
-                        ex.printStackTrace(); // FIXME!
+                        util.DEBUG("Got Exception " + ex.getMessage());
+                        ex.printStackTrace();
                     }
                 }
             }
@@ -2050,35 +2081,6 @@
                 "initSlave ");
         }
         util.DEBUG(results);
-        
-        // Preliminary needs to freeze db before copying to slave and setting replication
mode.
-        // Should do: Assuming startMaster does unfreeze! 
-        /* */
-        util.DEBUG("*************************** DERBY-3384. Must manually unfreeze.");
-        if ( host.equalsIgnoreCase("localhost") || localEnv )
-        {
-             String URL = DB_PROTOCOL
-                +"://"+masterServerHost
-                +":"+masterServerPort+"/"
-                +masterDatabasePath+FS+masterDbSubPath+FS+dbName;
-            util.DEBUG("initSlave getConnection("+URL+")");
-            Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes!
-            Connection conn = DriverManager.getConnection(URL);
-            Statement s = conn.createStatement();
-            s.execute("call syscs_util.syscs_unfreeze_database()");
-            conn.close();
-        }
-        else
-        {
-            runTest(unFreezeDB,
-                    clientVM,
-                    testClientHost,
-                    masterServerHost, masterServerPort,
-                    dbName
-                    );
-        }
-         /* */
-
         
     }
     // ?? The following should be moved to a separate class, subclass this and

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Utils.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Utils.java?rev=640506&r1=640505&r2=640506&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Utils.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Utils.java
Mon Mar 24 11:34:25 2008
@@ -151,8 +151,8 @@
         }
         else
         {
-            // copy(src,dest);
-            NIOcopy(src,dest);
+            copy(src,dest);  // Also works w/ JVM 1.4
+            // NIOcopy(src,dest); // Requires JVM 1.5 or 1.6
         }
     }
     private void copy(File source, File dest) 



Mime
View raw message