db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oyste...@apache.org
Subject svn commit: r642193 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: suites/All.java tests/replicationTests/ReplicationRun.java tests/replicationTests/ReplicationRun_Local_1.java tests/replicationTests/ReplicationSuite.java
Date Fri, 28 Mar 2008 10:54:23 GMT
Author: oysteing
Date: Fri Mar 28 03:54:09 2008
New Revision: 642193

URL: http://svn.apache.org/viewvc?rev=642193&view=rev
Log:
DERBY-3162: 
Make replication tests run when starting with a relative path for classpath
Enable ReplicationSuite in suites.All
Contributed by Ole Solberg

Details:
1. java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationSuite.java
 .1 Added ReplicationRun_Local_1.suite() which does a simple consistency test
     on contents in master and slave db's after replication.
2. java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java
 .1 Set user.dir and derby.system.home correctly when starting servers.
    (StartServer())
 .2 Minor cleanup on detecting we are running in a "localhost" environment.
 .3 Cleanup some DEBUG.
 .4 Do master and slave verification directly from the ReplicationRun VM.
    (verifySlave(), verifyMaster())
 .5 Set user.dir correctly when running existing JUnit tests as
    "replication load".
    (runUserCommandLocally())
3. java/testing/org/apache/derbyTesting/functionTests/suites/All.java
 .1 Add ReplicationSuite.suite() to suites.All.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_1.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/All.java
    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/ReplicationSuite.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/All.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/All.java?rev=642193&r1=642192&r2=642193&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/All.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/All.java
Fri Mar 28 03:54:09 2008
@@ -51,8 +51,7 @@
         suite.addTest(EncryptionSuite.suite());
         
         // Replication tests
-        // These tests currently don't behave well on Windows:
-        // suite.addTest(ReplicationSuite.suite());
+        suite.addTest(ReplicationSuite.suite());
         
         return suite;
     }

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=642193&r1=642192&r2=642193&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
Fri Mar 28 03:54:09 2008
@@ -338,7 +338,7 @@
         }
         else
         { // JUnit
-            if ( classPath != null ) // "localhost" case...
+            if ( testClientHost.equals("localhost") )
             {
                 testingClassPath = classPath; // Using the complete classpath
             }
@@ -359,7 +359,7 @@
         String results = null;
         if ( testClientHost.equalsIgnoreCase("localhost") )
         {
-            runUserCommandLocally(command, userDir, "runTest ");
+            runUserCommandLocally(command, userDir+FS+masterDbSubPath, "runTest ");
         }
         else
         {
@@ -378,7 +378,7 @@
             String dbName)
             throws Exception
     {
-        util.DEBUG("runTest(" + replicationTest
+        util.DEBUG("runTestOnSlave(" + replicationTest
                 + ", " + clientVM
                 + ", " + testClientHost
                 + ", " + serverHost
@@ -427,7 +427,7 @@
         }
         else
         { // JUnit
-            if ( classPath != null ) // "localhost" case...
+            if ( testClientHost.equals("localhost") ) 
             {
                 testingClassPath = classPath; // Using the complete classpath
             }
@@ -448,14 +448,14 @@
         String results = null;
         if ( testClientHost.equalsIgnoreCase("localhost") )
         {
-            runUserCommandLocally(command, userDir, "runTest ");
+            runUserCommandLocally(command, userDir+FS+slaveDbSubPath, "runTestOnSlave ");
         }
         else
         {
             command = "cd "+ userDir +";" // Must be positioned where the properties file
is located.
                     + command;
             results = runUserCommandRemotely(command, testClientHost, testUser,
-                    "runTest ");
+                    "runTestOnSlave ");
         }
         util.DEBUG("Time: " + (System.currentTimeMillis() - startTime) / 1000.0);
         
@@ -892,14 +892,14 @@
                     String state = se.getSQLState();
                     String expectedState = "XRE04";
                     util.DEBUG("startMaster Got SQLException: " 
-                            + errCode + " " + state + " " + msg);
+                            + errCode + " " + state + " " + msg + ". Expected " + expectedState);
                     if ( (errCode == -1)
                     && (state.equalsIgnoreCase(expectedState) ) )
                     {
                         util.DEBUG("Not ready to startMaster. "
                                 +"Beware: Will also report "
                                 + "'... got a fatal error for database '...../<dbname>'"
-                                + " in master derby-log.");
+                                + " in master derby.log.");
                         Thread.sleep(100L); // ms.
                     }
                     else
@@ -908,12 +908,14 @@
                         {
                             util.DEBUG("Master already started?");
                         }
+                        util.DEBUG("Got: "+state+" Expected "+expectedState);
                         throw se;
                     }
                 }
 
                 this.assertTrue("startMaster did not succeed.", count++ < 100); // 100*100ms
= 10s.
             }
+            util.DEBUG("startMaster_direct exit.");
     }
     
     /**
@@ -1109,6 +1111,7 @@
                 {
                     startSlaveException = null;
                     Connection conn = null;
+                    String expectedState = "XRE08";
                     try {
                         // NB! WIll hang here until startMaster is executed!
                         /*On 1.5 locking of Drivermanager.class prevents
@@ -1128,11 +1131,11 @@
                     catch (SQLException se)
                     {
                         startSlaveException = se;
+                        util.DEBUG("Got: "+se.getSQLState()+" Expected: "+expectedState);
                         /*
                         int errCode = se.getErrorCode();
                         String msg = se.getMessage();
                         String state = se.getSQLState();
-                        String expectedState = "XRE08";
                         util.DEBUG("startSlave Got SQLException: " + errCode + " " + state
+ " " + msg);
                         if ( (errCode == -1)
                         && (state.equalsIgnoreCase(expectedState) ) )
@@ -1149,12 +1152,14 @@
                     catch (Exception ex)
                     {
                         startSlaveException = ex;
-                        util.DEBUG("Got Exception " + ex.getMessage());
+                        util.DEBUG("Got Exception " + ex.getMessage()
+                            +" Expected: SQLException "+expectedState);
                     }
                 }
             }
             );
             connThread.start();
+            util.DEBUG("startSlave_direct exit.");
     }
     
     private void stopSlave(String dbName)
@@ -1413,26 +1418,56 @@
     void verifySlave()
     throws Exception
     {
-        util.DEBUG("BEGIN verifySlave PROTOTYPE VARIANT!");
-        
+        util.DEBUG("BEGIN verifySlave "+slaveServerHost+":"
+                +slaveServerPort+"/"+slaveDatabasePath+FS+slaveDbSubPath+FS+replicatedDb);
+        ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
+        ds.setDatabaseName(slaveDatabasePath + FS + slaveDbSubPath + FS +
+                           replicatedDb);
+        ds.setServerName(slaveServerHost);
+        ds.setPortNumber(slaveServerPort);
+        Connection conn = ds.getConnection();
+            
+        simpleVerify(conn);
+        conn.close();
+        /*
         runSlaveVerificationCLient(jvmVersion,
                 testClientHost,
                 replicatedDb,
                 slaveServerHost, slaveServerPort);
-        
-        util.DEBUG("END   verifySlave PROTOTYPE VARIANT!");
+        */
+        util.DEBUG("END   verifySlave");
     }
     void verifyMaster()
     throws Exception
     {
-        util.DEBUG("BEGIN verifyMaster PROTOTYPE VARIANT!");
-        
+        util.DEBUG("BEGIN verifyMaster " + masterServerHost + ":"
+                +masterServerPort+"/"+masterDatabasePath+FS+masterDbSubPath+FS+replicatedDb);
+        ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
+        ds.setDatabaseName(masterDatabasePath + FS + masterDbSubPath + FS +
+                           replicatedDb);
+        ds.setServerName(masterServerHost);
+        ds.setPortNumber(masterServerPort);
+        Connection conn = ds.getConnection();
+            
+        simpleVerify(conn);
+        conn.close();
+        /*
         runMasterVerificationCLient(jvmVersion,
                 testClientHost,
                 replicatedDb,
                 masterServerHost, masterServerPort);
-        
-        util.DEBUG("END   verifyMaster PROTOTYPE VARIANT!");
+        */
+        util.DEBUG("END   verifyMaster");
+    }
+    private void simpleVerify(Connection conn) // Verification code..
+    throws SQLException
+    {
+        Statement s = conn.createStatement();
+        ResultSet rs = s.executeQuery("select SCHEMAID, TABLENAME from sys.systables");
+        while (rs.next())
+        {
+            util.DEBUG(rs.getString(1) + " " + rs.getString(2));
+        }
     }
     
     private void runSlaveVerificationCLient(String jvmVersion,
@@ -1605,21 +1640,18 @@
         
         return output;
     }
-    private void runUserCommandLocally(String command, String userDir, String ID)
+    private void runUserCommandLocally(String command, String user_dir, String ID)
     { // Running on localhost.
         util.DEBUG("");
         final String debugId = "runUserCommandLocally " + ID + " ";
-        util.DEBUG("+++ runUserCommandLocally " + command + " / " + userDir);
+        util.DEBUG("+++ runUserCommandLocally " + command + " / " + user_dir);
                         
-        String workingDirName = userDir;
-        util.DEBUG(debugId+"user.dir: " + workingDirName);
-        
         String tmp ="";
         util.DEBUG(debugId+command);
         
         final String fullCmd = command;
         
-        String[] envElements = null;
+        String[] envElements = null; // rt.exec() will inherit..
         /*
         tmp ="";
         for ( int i=0;i<envElements.length;i++)
@@ -1627,8 +1659,6 @@
         util.DEBUG(debugId+"envElements: " + tmp);
          */
         
-        final File workingDir = new File(workingDirName);
-        
         String shellCmd = fullCmd;
         
         {
@@ -1637,7 +1667,8 @@
             
             try
             {
-                Process proc = Runtime.getRuntime().exec(localCommand,envElements,workingDir);
+                Process proc = Runtime.getRuntime().exec(localCommand,envElements,
+                        null); // Inherit user.dir
                 processDEBUGOutput(debugId+"pDo ", proc);
             }
             catch (Exception ex)
@@ -1855,6 +1886,10 @@
     void initEnvironment()
     throws IOException
     {
+        util.printDebug = System.getProperty("derby.tests.repltrace", "false")
+                                                     .equalsIgnoreCase("true");
+        util.DEBUG("printDebug: " + util.printDebug);
+        
         util.DEBUG("*** ReplicationRun.initEnvironment -----------------------------------------");
         util.DEBUG("*** Properties -----------------------------------------");
         userDir = System.getProperty("user.dir");
@@ -1862,10 +1897,6 @@
         
         util.DEBUG("derby.system.home: " + System.getProperty("derby.system.home"));
         
-        util.printDebug = System.getProperty("derby.tests.repltrace", "false")
-                                                     .equalsIgnoreCase("true");
-        util.DEBUG("printDebug: " + util.printDebug);
-        
         showSysinfo = true;
         util.DEBUG("showSysinfo: " + showSysinfo);
         
@@ -2144,7 +2175,7 @@
             String serverHost,
             String interfacesToListenOn,
             int serverPort,
-            String dbSubDirPath) // fullDbDirPath)
+            String dbSubDirPath)
             throws Exception
     {
         util.DEBUG("");
@@ -2165,7 +2196,10 @@
         
         securityOption = "-noSecurityManager";
         
+        String workingDirName = userDir+FS+dbSubDirPath;// "system" for this server
+        
         final String[] commandElements = {serverJvm
+                , " -Dderby.system.home=" + workingDirName
                 , " -Dderby.infolog.append=true"
                 // , " -Dderby.language.logStatementText=true" // Goes into derby.log: Gets
HUGE!
                 , " -cp ", serverClassPath
@@ -2183,8 +2217,6 @@
             envElements = null;
         }
         
-        String workingDirName = userDir+FS+dbSubDirPath;// was fullDbDirPath; // "system"
for this server, typically <user.dir>/db_master or ..slave
-        util.DEBUG(debugId+"user.dir: " + workingDirName);
         String tmp ="";
         
         for ( int i=0;i<commandElements.length;i++)
@@ -2198,10 +2230,9 @@
             for ( int i=0;i<envElements.length;i++)
             {tmp = tmp + envElements[i] + " ";}
         }
-        util.DEBUG(debugId+"envElements: " + tmp);
-        
-        final File workingDir = new File(workingDirName);
-        util.DEBUG(debugId+"workingDir: " + workingDirName);
+        util.DEBUG(debugId+"envElements:    " + tmp);
+
+        File workingDir = new File(workingDirName);
         
         if ( serverHost.equalsIgnoreCase("localhost") || localEnv )
         {
@@ -2251,7 +2282,7 @@
             final String localCommand = shellCmd;
             util.DEBUG(debugId+"localCommand: " + localCommand);
             
-            final String[] fEnvElements = envElements;
+            final String[] fEnvElements = envElements; // null for localhost
             Thread serverThread = new Thread(
                     new Runnable()
             {
@@ -2261,7 +2292,9 @@
                     try
                     {
                         util.DEBUG(debugId+"************** In run().");
-                        proc = Runtime.getRuntime().exec(localCommand,fEnvElements,workingDir);
+                        proc = Runtime.getRuntime().exec(localCommand,
+                                fEnvElements, // if null inherit environment
+                                null); // null: means inherit user.dir.
                         util.DEBUG(debugId+"************** Done exec().");
                         processDEBUGOutput(debugId+"pDo ", proc);
                     }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_1.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_1.java?rev=642193&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_1.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_1.java
Fri Mar 28 03:54:09 2008
@@ -0,0 +1,196 @@
+/*
+ 
+Derby - Class org.apache.derbyTesting.functionTests.tests.replicationTests.ReplicationRun
+ 
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+ 
+   http://www.apache.org/licenses/LICENSE-2.0
+ 
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ 
+ */
+package org.apache.derbyTesting.functionTests.tests.replicationTests;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.derby.jdbc.ClientDataSource;
+import org.apache.derbyTesting.junit.SecurityManagerSetup;
+
+
+/**
+ * Run a replication test on localhost
+ * by using default values for master and slave hosts,
+ * and master and slave ports.
+ * 
+ */
+
+public class ReplicationRun_Local_1 extends ReplicationRun
+{
+    
+    /**
+     * Creates a new instance of ReplicationRun_Local
+     * @param testcaseName Identifying the test.
+     */
+    public ReplicationRun_Local_1(String testcaseName)
+    {
+        super(testcaseName);
+    }
+    
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite("ReplicationRun_Local_1 Suite");
+        
+        suite.addTestSuite( ReplicationRun_Local_1.class );
+        
+        return SecurityManagerSetup.noSecurityManager(suite);
+
+    }
+    
+    public void testReplication_Local_1()
+    throws Exception
+    {
+        cleanAllTestHosts();
+        
+        initEnvironment();
+        
+        initMaster(masterServerHost,
+                replicatedDb);
+        
+        masterServer = startServer(masterJvmVersion, derbyMasterVersion,
+                masterServerHost, ALL_INTERFACES, masterServerPort,
+                masterDbSubPath);
+        
+        slaveServer = startServer(slaveJvmVersion, derbySlaveVersion,
+                slaveServerHost, ALL_INTERFACES, slaveServerPort,
+                slaveDbSubPath);
+        
+        startServerMonitor(slaveServerHost);
+        
+        bootMasterDatabase(jvmVersion,
+                masterDatabasePath +FS+ masterDbSubPath, replicatedDb,
+                masterServerHost, masterServerPort,
+                null // bootLoad, // The "test" to start when booting db.
+                );
+        
+        initSlave(slaveServerHost,
+                jvmVersion,
+                replicatedDb);
+        
+        startSlave(jvmVersion, replicatedDb,
+                slaveServerHost, slaveServerPort,
+                slaveServerHost, 
+                slaveReplPort,
+                testClientHost);
+        
+        startMaster(jvmVersion, replicatedDb,
+                masterServerHost, masterServerPort,
+                masterServerHost,
+                slaveServerPort, slaveServerHost,
+                slaveReplPort);
+        
+        // Replication "load"
+        String dbPath = masterDatabasePath + FS + masterDbSubPath + FS +
+                replicatedDb;
+        _testInsertUpdateDeleteOnMaster(masterServerHost, masterServerPort, 
+                dbPath);
+        
+        failOver(jvmVersion,
+                masterDatabasePath, masterDbSubPath, replicatedDb,
+                masterServerHost, masterServerPort,
+                testClientHost);
+        
+        connectPing(slaveDatabasePath+FS+slaveDbSubPath+FS+replicatedDb,
+                slaveServerHost,slaveServerPort,
+                testClientHost);
+        
+        // verifySlave();
+        dbPath = slaveDatabasePath+FS+slaveDbSubPath+FS+replicatedDb;
+        _verifyDatabase(slaveServerHost, slaveServerPort,
+            dbPath);
+        // We should verify the master as well, 
+        // at least to see that we still can connect.
+        // verifyMaster();
+        dbPath = masterDatabasePath +FS+masterDbSubPath +FS+ replicatedDb;
+        _verifyDatabase(masterServerHost, masterServerPort,
+            dbPath);
+    }
+    
+    private final int noTuplesToInsert = 10000;
+    private void _testInsertUpdateDeleteOnMaster(String serverHost, 
+            int serverPort,
+            String dbPath)
+        throws SQLException
+    {
+        util.DEBUG("_testInsertUpdateDeleteOnMaster: " + serverHost + ":" +
+                   serverPort + "/" + dbPath);
+        ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
+        ds.setDatabaseName(dbPath);
+        ds.setServerName(serverHost);
+        ds.setPortNumber(serverPort);
+        Connection conn = ds.getConnection();
+        
+        PreparedStatement ps = conn.prepareStatement("create table t(i integer primary key,
s varchar(64))");
+        
+        ps.execute();
+        
+        ps = conn.prepareStatement("insert into t values (?,?)");
+        for (int i = 0; i< noTuplesToInsert; i++)
+        {
+            ps.setInt(1,i);
+            ps.setString(2,"dilldall"+i);
+            ps.execute();
+            if ( (i % 10000) == 0 ) conn.commit();
+        }
+        
+        _verify(conn);
+        
+        conn.close();
+    }
+    private void _verifyDatabase(String serverHost, 
+            int serverPort,
+            String dbPath)
+        throws SQLException
+    {
+        util.DEBUG("_verifyDatabase: "+serverHost+":"+serverPort+"/"+dbPath);
+        ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
+        ds.setDatabaseName(dbPath);
+        ds.setServerName(serverHost);
+        ds.setPortNumber(serverPort);
+        Connection conn = ds.getConnection();
+        
+        _verify(conn);
+        
+        conn.close();
+    }
+    private void _verify(Connection conn)
+        throws SQLException
+    {
+        Statement s = conn.createStatement();
+        ResultSet rs = s.executeQuery("select count(*) from t");
+        rs.next();
+        int count = rs.getInt(1);
+        rs = s.executeQuery("select max(i) from t");
+        rs.next();
+        int max = rs.getInt(1);
+        util.DEBUG("_verify: " + count + "/" + noTuplesToInsert + " " + max +
+                   "/" + (noTuplesToInsert - 1));
+        assertEquals("Expected "+ noTuplesToInsert +" tuples, got "+ count +".",
+                     noTuplesToInsert, count);
+        assertEquals("Expected " +(noTuplesToInsert-1) +" max, got " + max +".",
+                     noTuplesToInsert - 1, max);
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationSuite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationSuite.java?rev=642193&r1=642192&r2=642193&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationSuite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationSuite.java
Fri Mar 28 03:54:09 2008
@@ -48,6 +48,8 @@
 
 		suite.addTest(ReplicationRun_Local.suite());
         
+		suite.addTest(ReplicationRun_Local_1.suite());
+        
 		suite.addTest(ReplicationRun_Local_StateTest_part1.suite());
 		suite.addTest(ReplicationRun_Local_StateTest_part1_1.suite());
 		suite.addTest(ReplicationRun_Local_StateTest_part1_2.suite());



Mime
View raw message