Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 82111 invoked from network); 7 Mar 2008 16:35:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Mar 2008 16:35:06 -0000 Received: (qmail 21719 invoked by uid 500); 7 Mar 2008 16:34:55 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 21698 invoked by uid 500); 7 Mar 2008 16:34:55 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 21675 invoked by uid 99); 7 Mar 2008 16:34:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Mar 2008 08:34:55 -0800 X-ASF-Spam-Status: No, hits=-1998.8 required=10.0 tests=ALL_TRUSTED,FS_REPLICA X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Mar 2008 16:34:12 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id ADC361A9832; Fri, 7 Mar 2008 08:34:29 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r634734 [1/2] - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: suites/ tests/replicationTests/ Date: Fri, 07 Mar 2008 16:34:20 -0000 To: derby-commits@db.apache.org From: oysteing@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080307163429.ADC361A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oysteing Date: Fri Mar 7 08:34:18 2008 New Revision: 634734 URL: http://svn.apache.org/viewvc?rev=634734&view=rev Log: DERBY-3162: - Added tests for checking replication command behaviour in different states of replication. (ReplicationRun_Local_StateTest_part*) - Added 'ReplicationSuite.suite()' at end of .../suites/All.java. That is, the replication test will be run as part of suites.All. - replication tests now uses 'SecurityManagerSetup.noSecurityManager()'. - changed replication test trace output to use Utils.DEBUG(). Can be turned on by '-Dderby.tests.repltrace=true'. Contributed by Ole Solberg Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_CleanUp.java (with props) db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java (with props) db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java (with props) db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java (with props) db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_3.java (with props) db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part2.java (with props) db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationSuite.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/ReplicationRun_Distributed.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Full.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/TestPreStartedMaster.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/suites/All.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/All.java?rev=634734&r1=634733&r2=634734&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 7 08:34:18 2008 @@ -25,6 +25,7 @@ import org.apache.derbyTesting.junit.BaseTestCase; import org.apache.derbyTesting.junit.EnvTest; +import org.apache.derbyTesting.functionTests.tests.replicationTests.ReplicationSuite; public class All extends BaseTestCase { @@ -38,7 +39,7 @@ public static Test suite() throws Exception { TestSuite suite = new TestSuite("All"); - + // Simple "test" that displays environment information // as fixture names. suite.addTestSuite(EnvTest.class); @@ -48,6 +49,9 @@ // Encrypted tests suite.addTest(EncryptionSuite.suite()); + + // Replication tests + 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=634734&r1=634733&r2=634734&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 7 08:34:18 2008 @@ -29,8 +29,10 @@ import java.sql.*; import java.io.*; +import org.apache.derby.shared.common.reference.SQLState; import org.apache.derbyTesting.junit.BaseTestCase; +import org.apache.derbyTesting.junit.SecurityManagerSetup; /** * Framework to run replication tests. @@ -155,6 +157,12 @@ */ protected void tearDown() throws Exception { + stopServer(jvmVersion, derbyVersion, + slaveServerHost, slaveServerPort); + + stopServer(jvmVersion, derbyVersion, + masterServerHost, masterServerPort); + super.tearDown(); } @@ -165,7 +173,7 @@ suite.addTestSuite( ReplicationRun.class ); // Make sure to rename in subclasses! - return suite; + return SecurityManagerSetup.noSecurityManager(suite); } ////////////////////////////////////////////////////////////// @@ -184,12 +192,14 @@ //// ////////////////////////////////////////////////////////////// + /* Template public void testReplication() throws Exception { - System.out.println("WARNING: Override in subclass of ReplicationRun. " + util.DEBUG("WARNING: Define in subclass of ReplicationRun. " + "See ReplicationRun_Local for an example."); } + */ void connectPing(String fullDbPath, String serverHost, int serverPort, @@ -237,18 +247,25 @@ } } - private void shutdownDb(String serverHost, int serverPort, - String dbPath, String replicatedDb) - throws SQLException + void shutdownDb(String jvmVersion, // Not yet used + String serverHost, int serverPort, + String dbPath, String replicatedDb, + String clientHost) // Not yet used { String serverURL = "jdbc:derby:" +"//"+serverHost+":"+serverPort+"/"; String dbURL = serverURL +dbPath +"/"+replicatedDb; - System.out.println("**** DriverManager.getConnection(\"" + dbURL+";shutdown=true\");"); + util.DEBUG("**** DriverManager.getConnection(\"" + dbURL+";shutdown=true\");"); - DriverManager.getConnection(dbURL+";shutdown=true"); + try{ + DriverManager.getConnection(dbURL+";shutdown=true"); + } + catch (SQLException se) + { + + } } @@ -316,7 +333,7 @@ } command = clientJvm + " -Dderby.tests.trace=true" - + " -Djava.security.policy=\"\"" // To allow the test to e.g. kill servers... + // + " -Djava.security.policy=\"\"" // Now using noSecurityManager decorator + " -Dtest.serverHost=" + serverHost // Tell the test what server + " -Dtest.serverPort=" + serverPort // and port to connect to. + " -Dtest.inserts=" + tuplesToInsert // for SimplePerfTest @@ -340,7 +357,7 @@ results = runUserCommandRemotely(command, testClientHost, testUser, "runTest "); } - System.out.println("Time: " + (System.currentTimeMillis() - startTime) / 1000.0); + util.DEBUG("Time: " + (System.currentTimeMillis() - startTime) / 1000.0); } void runTestOnSlave(String replicationTest, @@ -400,7 +417,7 @@ } command = clientJvm + " -Dderby.tests.trace=true" - + " -Djava.security.policy=\"\"" // To allow the test to e.g. kill servers... + // + " -Djava.security.policy=\"\"" // Now using noSecurityManager decorator + " -Dtest.serverHost=" + serverHost // Tell the test what server + " -Dtest.serverPort=" + serverPort // and port to connect to. + " -Dtest.inserts=" + tuplesToInsert // for SimplePerfTest @@ -424,7 +441,7 @@ results = runUserCommandRemotely(command, testClientHost, testUser, "runTest "); } - System.out.println("Time: " + (System.currentTimeMillis() - startTime) / 1000.0); + util.DEBUG("Time: " + (System.currentTimeMillis() - startTime) / 1000.0); } @@ -484,7 +501,7 @@ /* BEGIN For junit: */ command = clientJvm // "java" + " -Dderby.tests.trace=true" - + " -Djava.security.policy=\"\"" // To allow the test to e.g. kill servers... + // + " -Djava.security.policy=\"\"" // Now using noSecurityManager decorator + " -classpath " + testingClassPath + " junit.textui.TestRunner" + " " + load // @@ -559,7 +576,7 @@ command = "cd "+ userDir +";" // Must be positioned where the properties file is located. + clientJvm + " -Dderby.tests.trace=true" - + " -Djava.security.policy=\"\"" // To allow the test to e.g. kill servers... + // + " -Djava.security.policy=\"\"" // Now using noSecurityManager decorator + " -classpath " + testingClassPath + " junit.textui.TestRunner" + " " + stateTest @@ -624,7 +641,7 @@ testUser, "bootMasterDatabase "); } - System.out.println(results); + util.DEBUG(results); // NB! should be done by startMaster. Preliminary needs to freeze db before copying to slave and setting replication mode. @@ -779,7 +796,7 @@ testClientHost, testUser, "startMaster_ij "); - System.out.println(results); + util.DEBUG(results); } private void startMaster_direct(String dbName, String masterHost, // Where the master db is run. @@ -808,6 +825,7 @@ conn = DriverManager.getConnection(URL); done = true; conn.close(); + util.DEBUG("startMaster OK"); } catch ( SQLException se ) { @@ -815,17 +833,25 @@ String msg = se.getMessage(); String state = se.getSQLState(); String expectedState = "XRE04"; - util.DEBUG("startSlave Got SQLException: " + errCode + " " + state + " " + msg); + util.DEBUG("startSlave Got SQLException: " + + errCode + " " + state + " " + msg); if ( (errCode == -1) && (state.equalsIgnoreCase(expectedState) ) ) { - util.DEBUG("Not ready to startMaster"); + util.DEBUG("Not ready to startMaster. " + +"Beware: Will also report " + + "'... got a fatal error for database '...../'" + + " in master derby-log."); Thread.sleep(100L); // ms. } else { - se.printStackTrace(); // FIXME! - return; + if (SQLState.REPLICATION_MASTER_TIMED_OUT.equals(state)) // FIXME! CANNOT_START_MASTER_ALREADY_BOOTED + { + util.DEBUG("Master already started?"); + } + se.printStackTrace(System.out); + return; // Trying to continue. Is that reasonable? } } @@ -945,7 +971,7 @@ testClientHost, testUser, "startSlave_ij "); - System.out.println(results); */ + util.DEBUG(results); */ // 618220 + failover_impl_3205_v3.diff + derby-3361-1a.diff : runUserCommandInThreadRemotely(command, testClientHost, @@ -988,11 +1014,11 @@ String msg = se.getMessage(); String state = se.getSQLState(); String expectedState = "XRE08"; - System.out.println("startSlave Got SQLException: " + errCode + " " + state + " " + msg); + util.DEBUG("startSlave Got SQLException: " + errCode + " " + state + " " + msg); if ( (errCode == -1) && (state.equalsIgnoreCase(expectedState) ) ) { - System.out.println("As expected."); + util.DEBUG("As expected."); } else @@ -1049,7 +1075,7 @@ testClientHost, testUser, "stopSlave_ij "); - System.out.println(results); + util.DEBUG(results); } void failOver(String jvmVersion, @@ -1105,7 +1131,7 @@ testClientHost, testUser, "failOver_ij "); - System.out.println(results); + util.DEBUG(results); } private void failOver_direct(String dbPath, String dbSubPath, String dbName, String host, // Where the db is run. @@ -1132,22 +1158,21 @@ String msg = se.getMessage(); String state = se.getSQLState(); String expectedState = "XRE20"; - System.out.println("failOver_direct Got SQLException: " + errCode + " " + state + " " + msg); + util.DEBUG("failOver_direct Got SQLException: " + errCode + " " + state + " " + msg); if ( (errCode == -1) && (state.equalsIgnoreCase(expectedState) ) ) { - System.out.println("As expected."); - + util.DEBUG("As expected."); } else { - se.printStackTrace(); // FIXME! + se.printStackTrace(System.out); // FIXME! } ; } catch (Exception ex) { - ex.printStackTrace(); // FIXME! + ex.printStackTrace(System.out); // FIXME! } } @@ -1190,7 +1215,7 @@ testClientHost, testUser, "stopSlave_ij "); - System.out.println(results); + util.DEBUG(results); } int xFindServerPID(String serverHost, int serverPort) @@ -1319,7 +1344,7 @@ // dbName, "runSlaveVerificationCLient "); } - System.out.println(results); + util.DEBUG(results); */ } @@ -1370,7 +1395,7 @@ // dbName, "runMasterVerificationCLient "); } - System.out.println(results); + util.DEBUG(results); */ } @@ -1386,7 +1411,7 @@ } catch (Exception e) { - System.out.println("Failed to create connection: " + url + ", " + e.getMessage()); + util.DEBUG("Failed to create connection: " + url + ", " + e.getMessage()); e.printStackTrace(); } return con; @@ -1691,121 +1716,122 @@ void initEnvironment() throws IOException { - System.out.println("*** ReplicationRun.initEnvironment -----------------------------------------"); - System.out.println("*** Properties -----------------------------------------"); + util.DEBUG("*** ReplicationRun.initEnvironment -----------------------------------------"); + util.DEBUG("*** Properties -----------------------------------------"); userDir = System.getProperty("user.dir"); - System.out.println("user.dir: " + userDir); + util.DEBUG("user.dir: " + userDir); - System.out.println("derby.system.home: " + System.getProperty("derby.system.home")); + util.DEBUG("derby.system.home: " + System.getProperty("derby.system.home")); - util.printDebug = true; - System.out.println("printDebug: " + util.printDebug); + util.printDebug = System.getProperty("derby.tests.repltrace", "false") + .equalsIgnoreCase("true"); + util.DEBUG("printDebug: " + util.printDebug); showSysinfo = true; - System.out.println("showSysinfo: " + showSysinfo); + util.DEBUG("showSysinfo: " + showSysinfo); testUser = null; - System.out.println("testUser: " + testUser); + util.DEBUG("testUser: " + testUser); masterServerHost = "localhost"; - System.out.println("masterServerHost: " + masterServerHost); + util.DEBUG("masterServerHost: " + masterServerHost); masterServerPort = 1527; - System.out.println("masterServerPort: " + masterServerPort); + util.DEBUG("masterServerPort: " + masterServerPort); slaveServerHost = "localhost"; - System.out.println("slaveServerHost: " + slaveServerHost); + util.DEBUG("slaveServerHost: " + slaveServerHost); slaveServerPort = 4527; - System.out.println("slaveServerPort: " + slaveServerPort); + util.DEBUG("slaveServerPort: " + slaveServerPort); slaveReplPort = 8888; - System.out.println("slaveReplPort: " + slaveReplPort); + util.DEBUG("slaveReplPort: " + slaveReplPort); testClientHost = "localhost"; - System.out.println("testClientHost: " + testClientHost); + util.DEBUG("testClientHost: " + testClientHost); masterDatabasePath = userDir; - System.out.println("masterDatabasePath: " + masterDatabasePath); + util.DEBUG("masterDatabasePath: " + masterDatabasePath); slaveDatabasePath = userDir; - System.out.println("slaveDatabasePath: " + slaveDatabasePath); + util.DEBUG("slaveDatabasePath: " + slaveDatabasePath); replicatedDb = "wombat"; - System.out.println("replicatedDb: " + replicatedDb); + util.DEBUG("replicatedDb: " + replicatedDb); bootLoad = null; - System.out.println("bootLoad: " + bootLoad); + util.DEBUG("bootLoad: " + bootLoad); freezeDB = null; - System.out.println("freezeDB: " + freezeDB); + util.DEBUG("freezeDB: " + freezeDB); unFreezeDB = null; - System.out.println("unFreezeDB: " + unFreezeDB); + util.DEBUG("unFreezeDB: " + unFreezeDB); /* Done in subclasses replicationTest = "org.apache.derbyTesting.functionTests.tests.replicationTests.ReplicationTestRun"; - System.out.println("replicationTest: " + replicationTest); + util.DEBUG("replicationTest: " + replicationTest); replicationVerify = "org.apache.derbyTesting.functionTests.tests.replicationTests.ReplicationTestRunVerify"; - System.out.println("replicationVerify: " + replicationVerify); + util.DEBUG("replicationVerify: " + replicationVerify); */ sqlLoadInit = null; - System.out.println("sqlLoadInit: " + sqlLoadInit); + util.DEBUG("sqlLoadInit: " + sqlLoadInit); specialTestingJar = null; - System.out.println("specialTestingJar: " + specialTestingJar); + util.DEBUG("specialTestingJar: " + specialTestingJar); jvmVersion = System.getProperty("java.home") +FS+"lib"; - System.out.println("jvmVersion: " + jvmVersion); + util.DEBUG("jvmVersion: " + jvmVersion); masterJvmVersion = null; if ( masterJvmVersion == null ) {masterJvmVersion = jvmVersion;} - System.out.println("masterJvmVersion: " + masterJvmVersion); + util.DEBUG("masterJvmVersion: " + masterJvmVersion); slaveJvmVersion = null; if ( slaveJvmVersion == null ) {slaveJvmVersion = jvmVersion;} - System.out.println("slaveJvmVersion: " + slaveJvmVersion); + util.DEBUG("slaveJvmVersion: " + slaveJvmVersion); classPath = System.getProperty("java.class.path"); util.DEBUG("classPath: " + classPath); int sep = classPath.indexOf("derby.jar:"); util.DEBUG("sep: " + sep); String tclassPath = classPath.substring(0,sep); util.DEBUG("classPath: " + classPath); sep = tclassPath.lastIndexOf("/"); util.DEBUG("sep: " + sep); derbyVersion = tclassPath.substring(0,sep); - System.out.println("derbyVersion: " + derbyVersion); + util.DEBUG("derbyVersion: " + derbyVersion); derbyMasterVersion = null; if ( derbyMasterVersion == null ) {derbyMasterVersion = derbyVersion;} - System.out.println("derbyMasterVersion: " + derbyMasterVersion); + util.DEBUG("derbyMasterVersion: " + derbyMasterVersion); derbySlaveVersion = null; if ( derbySlaveVersion == null ) {derbySlaveVersion = derbyVersion;} - System.out.println("derbySlaveVersion: " + derbySlaveVersion); + util.DEBUG("derbySlaveVersion: " + derbySlaveVersion); String derbyTestingJar = derbyVersion + FS+"derbyTesting.jar"; if ( specialTestingJar != null ) derbyTestingJar = specialTestingJar; - System.out.println("derbyTestingJar: " + derbyTestingJar); + util.DEBUG("derbyTestingJar: " + derbyTestingJar); junit_jar = derbyVersion + FS+"junit.jar"; - System.out.println("junit_jar: " + junit_jar); + util.DEBUG("junit_jar: " + junit_jar); test_jars = derbyTestingJar + ":" + junit_jar; - System.out.println("test_jars: " + test_jars); + util.DEBUG("test_jars: " + test_jars); sleepTime = 15000; - System.out.println("sleepTime: " + sleepTime); + util.DEBUG("sleepTime: " + sleepTime); runUnReplicated = false; - System.out.println("runUnReplicated: " + runUnReplicated); + util.DEBUG("runUnReplicated: " + runUnReplicated); localEnv = false; - System.out.println("localEnv: " + localEnv); + util.DEBUG("localEnv: " + localEnv); derbyProperties = "derby.infolog.append=true"+LF @@ -1813,7 +1839,7 @@ +"derby.drda.traceAll=true"+LF; - System.out.println("--------------------------------------------------------"); + util.DEBUG("--------------------------------------------------------"); masterPreRepl = null; // FIXME! masterPostRepl = null; // FIXME! @@ -1821,16 +1847,16 @@ masterPostSlave = null; // FIXME! slavePostSlave = null; // FIXME! - System.out.println("--------------------------------------------------------"); + util.DEBUG("--------------------------------------------------------"); // for SimplePerfTest tuplesToInsert = 10000; commitFreq = 1000; // "0" is autocommit - System.out.println("--------------------------------------------------------"); + util.DEBUG("--------------------------------------------------------"); // FIXME! state.initEnvironment(cp); - System.out.println("--------------------------------------------------------"); + util.DEBUG("--------------------------------------------------------"); } @@ -1877,7 +1903,7 @@ // dbName, // unneccessary? "initMaster "); } - System.out.println(results); + util.DEBUG(results); } @@ -1901,7 +1927,7 @@ testUser, // dbName, // unneccessary? "removeSlaveDBfiles "); - System.out.println(results); + util.DEBUG(results); } void initSlave(String host, String clientVM, String dbName) @@ -1948,7 +1974,7 @@ // dbName, // unneccessary? "initSlave "); } - System.out.println(results); + util.DEBUG(results); // Preliminary needs to freeze db before copying to slave and setting replication mode. // Should do: Assuming startMaster does unfreeze! @@ -2161,18 +2187,32 @@ void killMaster(String masterServerHost, int masterServerPort) throws InterruptedException { - /* Problem doing getProperty()... - stopServer(slaveJvmVersion, derbySlaveVersion, - slaveServerHost, slaveServerPort); - so instead */ - int pid = xFindServerPID(masterServerHost,masterServerPort); - xStopServer(masterServerHost, pid); + util.DEBUG("killMaster: " + masterServerHost +":" + masterServerPort); + if ( masterServerHost.equals("localhost") ) + { + stopServer(masterJvmVersion, derbyMasterVersion, + masterServerHost, masterServerPort); + } + else + { + int pid = xFindServerPID(masterServerHost,masterServerPort); + xStopServer(masterServerHost, pid); + } } void killSlave(String slaveServerHost, int slaveServerPort) throws InterruptedException { - int pid = xFindServerPID(slaveServerHost, slaveServerPort); - xStopServer(slaveServerHost, pid); + util.DEBUG("killSlave: " + slaveServerHost +":" + slaveServerPort); + if ( slaveServerHost.equals("localhost") ) + { + stopServer(slaveJvmVersion, derbySlaveVersion, + slaveServerHost, slaveServerPort); + } + else + { + int pid = xFindServerPID(slaveServerHost, slaveServerPort); + xStopServer(slaveServerHost, pid); + } } void destroySlaveDB(String slaveServerHost) throws InterruptedException @@ -2421,7 +2461,7 @@ util.DEBUG("--- pingServer"); } - private static void ping( NetworkServerControl controller, int iterations ) + private void ping( NetworkServerControl controller, int iterations ) throws Exception { Exception finalException = null; @@ -2440,7 +2480,7 @@ Thread.sleep( SLEEP_TIME_MILLIS ); } - System.out.println( "Server did not come up: " + finalException.getMessage() ); + util.DEBUG( "Server did not come up: " + finalException.getMessage() ); finalException.printStackTrace(); } @@ -2475,7 +2515,7 @@ ); if ( load == null ) { - System.out.println("No load supplied!"); + util.DEBUG("No load supplied!"); return; } if ( !existingDB ) @@ -2521,7 +2561,7 @@ */ void cleanAllTestHosts() { - System.out.println("************************** cleanAllTestHosts() Not yet implemented"); + util.DEBUG("************************** cleanAllTestHosts() Not yet implemented"); } /////////////////////////////////////////////////////////////////////////// @@ -2901,7 +2941,7 @@ /////////////////////////////////////////////////////////////////////////// /* Load started in different states of replication. */ - static class Load + class Load { Load(String load, String database, boolean existingDB, String clientHost) { @@ -2912,12 +2952,12 @@ } Load(String id, Properties testRunProperties) { - System.out.println("Load(): " + id); + util.DEBUG("Load(): " + id); String pid = "test." + id; if ( testRunProperties.getProperty(pid,"false").equalsIgnoreCase("false") ) { - System.out.println(pid + " Not defined or set to false!"); + util.DEBUG(pid + " Not defined or set to false!"); } else { @@ -2925,19 +2965,19 @@ pid = "test." + id + ".load"; load = testRunProperties.getProperty(pid, "org.apache.derbyTesting.functionTests.tests.replicationTests.DefaultLoad"); - System.out.println(pid+": " + load); + util.DEBUG(pid+": " + load); pid = "test." + id + ".database"; database = testRunProperties.getProperty(pid, id); - System.out.println(pid+": " + database); + util.DEBUG(pid+": " + database); pid = "test." + id + ".existingDB"; existingDB = testRunProperties.getProperty(pid,"false").equalsIgnoreCase("true"); - System.out.println(pid+": " + existingDB); + util.DEBUG(pid+": " + existingDB); pid = "test." + id + ".clientHost"; clientHost = testRunProperties.getProperty(pid, testClientHost); - System.out.println(pid+": " + clientHost); + util.DEBUG(pid+": " + clientHost); } Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_CleanUp.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_CleanUp.java?rev=634734&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_CleanUp.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_CleanUp.java Fri Mar 7 08:34:18 2008 @@ -0,0 +1,69 @@ +/* + +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 junit.framework.Test; +import junit.framework.TestSuite; +import org.apache.derbyTesting.junit.SecurityManagerSetup; + + +/** + * This is NOT a test but an attempt + * to make sure replication master and slave servers + * are really gone when ReplicationSuite is done. + * + */ + +public class ReplicationRun_CleanUp extends ReplicationRun +{ + + /** + * Creates a new instance of ReplicationRun_Local_StateTest_part1 + * + * @param testcaseName Identifying the test. + */ + public ReplicationRun_CleanUp(String testcaseName) + { + super(testcaseName); + } + + public static Test suite() + { + TestSuite suite = new TestSuite("ReplicationRun_CleanUp"); + + suite.addTestSuite( ReplicationRun_CleanUp.class ); + + return SecurityManagerSetup.noSecurityManager(suite); + } + + public void testReplication_CleanUp() + throws Exception + { + + stopServer(jvmVersion, derbyVersion, + slaveServerHost, slaveServerPort); + + stopServer(jvmVersion, derbyVersion, + masterServerHost, masterServerPort); + + } + +} Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_CleanUp.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Distributed.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Distributed.java?rev=634734&r1=634733&r2=634734&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Distributed.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Distributed.java Fri Mar 7 08:34:18 2008 @@ -26,6 +26,7 @@ import java.util.Properties; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.derbyTesting.junit.SecurityManagerSetup; @@ -55,7 +56,7 @@ suite.addTestSuite( ReplicationRun_Distributed.class ); - return suite; + return SecurityManagerSetup.noSecurityManager(suite); } ////////////////////////////////////////////////////////////// Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Full.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Full.java?rev=634734&r1=634733&r2=634734&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Full.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Full.java Fri Mar 7 08:34:18 2008 @@ -22,6 +22,7 @@ import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.derbyTesting.junit.SecurityManagerSetup; public class ReplicationRun_Full extends ReplicationRun { @@ -40,7 +41,7 @@ suite.addTestSuite( ReplicationRun_Full.class ); - return suite; + return SecurityManagerSetup.noSecurityManager(suite); } ////////////////////////////////////////////////////////////// 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=634734&r1=634733&r2=634734&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 Fri Mar 7 08:34:18 2008 @@ -22,6 +22,7 @@ import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.derbyTesting.junit.SecurityManagerSetup; /** @@ -59,7 +60,8 @@ suite.addTestSuite( ReplicationRun_Local.class ); - return suite; + return SecurityManagerSetup.noSecurityManager(suite); + } ////////////////////////////////////////////////////////////// @@ -73,7 +75,7 @@ //// ////////////////////////////////////////////////////////////// - public void testReplication() + public void testReplication_Local() throws Exception { cleanAllTestHosts(); Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java?rev=634734&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java Fri Mar 7 08:34:18 2008 @@ -0,0 +1,434 @@ +/* + +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.DriverManager; +import java.sql.SQLException; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.apache.derby.shared.common.reference.SQLState; +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_StateTest_part1 extends ReplicationRun +{ + + /** + * Creates a new instance of ReplicationRun_Local_StateTest_part1 + * + * @param testcaseName Identifying the test. + */ + public ReplicationRun_Local_StateTest_part1(String testcaseName) + { + super(testcaseName); + } + + public static Test suite() + { + TestSuite suite = new TestSuite("ReplicationRun_Local_StateTest_part1 Suite"); + + suite.addTestSuite( ReplicationRun_Local_StateTest_part1.class ); + + return SecurityManagerSetup.noSecurityManager(suite); + } + + ////////////////////////////////////////////////////////////// + //// + //// The replication test framework (testReplication()): + //// a) "clean" replication run starting master and slave servers, + //// preparing master and slave databases, + //// starting and stopping replication and doing + //// failover for a "normal"/"failure free" replication + //// test run. + //// + ////////////////////////////////////////////////////////////// + + public void testReplication_Local_StateTest_part1() + throws Exception + { + cleanAllTestHosts(); + + initEnvironment(); + + // State test. Continuation OK. + _testPreStartedMasterServer(); + + initMaster(masterServerHost, + replicatedDb); + + masterServer = startServer(masterJvmVersion, derbyMasterVersion, + masterServerHost, + ALL_INTERFACES, // masterServerHost, // "0.0.0.0", // All. or use masterServerHost for interfacesToListenOn, + masterServerPort, + masterDatabasePath +FS+ masterDbSubPath); // Distinguishing master/slave + + // State test. + _testPreStartedSlaveServer(); + + slaveServer = startServer(slaveJvmVersion, derbySlaveVersion, + slaveServerHost, + ALL_INTERFACES, // slaveServerHost, // "0.0.0.0", // All. or use slaveServerHost for interfacesToListenOn, + slaveServerPort, + slaveDatabasePath +FS+ slaveDbSubPath); // Distinguishing master/slave + + startServerMonitor(slaveServerHost); + + bootMasterDatabase(jvmVersion, + masterDatabasePath +FS+ masterDbSubPath, + replicatedDb, + masterServerHost, // Where the startreplication command must be given + masterServerPort, // master server interface accepting client requests + null // bootLoad, // The "test" to start when booting db. + ); + + // State test. + _testPreInitSlave(); + + initSlave(slaveServerHost, + jvmVersion, + replicatedDb); // Trunk and Prototype V2: copy master db to db_slave. + + // State test. + _testPreStartedSlave(); // Currently NOOP + + startSlave(jvmVersion, replicatedDb, + slaveServerHost, // slaveClientInterface // where the slave db runs + slaveServerPort, + slaveServerHost, // for slaveReplInterface + slaveReplPort, + testClientHost); + + // State test. + _testPreStartedMaster(); + + // With master started above, next will fail! + // Also seems failover will fail w/XRE21! : DERBY-3358! + // Further testing: skipping next startMaster seems to + // NOT remove failover failure! + /* TEMP: should be operational already - try skipping this. * / + startMaster(jvmVersion, replicatedDb, + masterServerHost, // Where the startMaster command must be given + masterServerPort, // master server interface accepting client requests + masterServerHost, // An interface on the master: masterClientInterface (==masterServerHost), + slaveServerPort, // Not used since slave don't allow clients. + slaveServerHost, // for slaveReplInterface + slaveReplPort); + / * */ + + // Used to run positive tests. + // Handle negative testing in State.testPostStartedMasterAndSlave(). + // Observe that it will not be meaningful to do runTest if State.XXXX() + // has led to incorrect replication state wrt. replicationTest. + + replicationTest = "org.apache.derbyTesting.functionTests.tests.replicationTests.ReplicationTestRun"; + util.DEBUG("replicationTest: " + replicationTest); + replicationVerify = "org.apache.derbyTesting.functionTests.tests.replicationTests.ReplicationTestRun_Verify"; + util.DEBUG("replicationVerify: " + replicationVerify); + + runTest(replicationTest, // Returns immediatly if replicationTest is null. + jvmVersion, + testClientHost, + masterServerHost, masterServerPort, + replicatedDb); + + failOver(jvmVersion, + masterDatabasePath, masterDbSubPath, replicatedDb, + masterServerHost, // Where the master db is run. + masterServerPort, + testClientHost); + + connectPing(slaveDatabasePath+FS+slaveDbSubPath+FS+replicatedDb, + slaveServerHost,slaveServerPort, + testClientHost); + + verifySlave(); + + // We should verify the master as well, at least to see that we still can connect. + verifyMaster(); + + stopServer(jvmVersion, derbyVersion, + slaveServerHost, slaveServerPort); + + stopServer(jvmVersion, derbyVersion, + masterServerHost, masterServerPort); + + } + + private void _testPreStartedMasterServer() + { + Connection conn = null; + String db = masterDatabasePath +"/"+ReplicationRun.masterDbSubPath +"/"+ replicatedDb; + String connectionURL = "jdbc:derby:" + + "//" + masterServerHost + ":" + masterServerPort + "/" + + db + + ";startMaster=true" + + ";slavehost=" + slaveServerHost + + ";slaveport=" + slaveServerPort; + util.DEBUG("testPreStartedMasterServer: " + connectionURL); + try + { + conn = DriverManager.getConnection(connectionURL); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + util.DEBUG("testStartMasterConnect_Illegal: " + msg); + assertTrue("Unexpected SQLException: " + msg, "08001".equals(ss)); + util.DEBUG("As expected."); + return; + } + assertTrue("Expected SQLException: '08001 " + db + "'",false); + } + + private void _testPreStartedSlaveServer() + { + Connection conn = null; + String db = slaveDatabasePath +"/"+ReplicationRun.slaveDbSubPath +"/"+ replicatedDb; + String connectionURL = "jdbc:derby:" + + "//" + slaveServerHost + ":" + slaveServerPort + "/" + + db + + ";startSlave=true" + + ";slavehost=" + slaveServerHost + + ";slaveport=" + slaveServerPort; + util.DEBUG("testPreStartedSlaveServer: " + connectionURL); + try + { + conn = DriverManager.getConnection(connectionURL); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + util.DEBUG("testStartSlaveConnect_Illegal: " + msg); + assertTrue("Unexpected SQLException: " + msg, "08001".equals(ss)); + util.DEBUG("As expected."); + return; + } + assertTrue("Expected SQLException: '08001 " + db + "'",false); + } + + private void _testPreInitSlave() + { + String db = null; + String connectionURL = null; + Connection conn = null; + + // 1. stopMaster on master: fail + db = masterDatabasePath +"/"+ReplicationRun.masterDbSubPath +"/"+ replicatedDb; + connectionURL = "jdbc:derby:" + + "//" + masterServerHost + ":" + masterServerPort + "/" + + db + + ";stopMaster=true"; + util.DEBUG("1. testPreInitSlave:" + connectionURL); + try + { + conn = DriverManager.getConnection(connectionURL); + util.DEBUG("Unexpectedly connected: " + connectionURL); + assertTrue("Unexpectedly connected: " + connectionURL,false); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + // SQLState.REPLICATION_NOT_IN_MASTER_MODE + + assertTrue("stopMaster on master failed: " + msg, + SQLState.REPLICATION_NOT_IN_MASTER_MODE.equals(ss)); + util.DEBUG("stopMaster on master failed as expected: " + connectionURL + " " + msg); + } + + // 2. stopSlave on slave: fail + db = slaveDatabasePath +"/"+ReplicationRun.slaveDbSubPath +"/"+ replicatedDb; + connectionURL = "jdbc:derby:" + + "//" + slaveServerHost + ":" + slaveServerPort + "/" + + db + + ";stopSlave=true"; + util.DEBUG("2. testPreInitSlave: " + connectionURL); + try + { + conn = DriverManager.getConnection(connectionURL); + util.DEBUG("Unexpectedly connected: " + connectionURL); + assertTrue("Unexpectedly connected: " + connectionURL,false); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + assertTrue("stopSlave on slave failed: " + msg, + SQLState.REPLICATION_DB_NOT_BOOTED.equals(ss)); + util.DEBUG("stopSlave on slave failed as expected: " + connectionURL + " " + msg); + } + } + + private void _testPreStartedSlave() + { + Connection conn = null; + String db = slaveDatabasePath +"/"+ReplicationRun.slaveDbSubPath +"/"+ replicatedDb; + String connectionURL = "jdbc:derby:" + + "//" + slaveServerHost + ":" + slaveServerPort + "/" + + db + + ";startSlave=true" + + ";slaveHost=" + slaveServerHost + + ";slavePort=" + slaveReplPort; + util.DEBUG("testPreStartedSlave: Test moved to TestPostStartedMasterAndSlave! " + connectionURL); + if (true)return; + + // First StartSlave connect ok: + try + { + conn = DriverManager.getConnection(connectionURL); + // Will hang until startMaster! + util.DEBUG("1. Successfully connected as: " + connectionURL); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + util.DEBUG(msg); + assertTrue("2. Unexpected SQLException: " + msg, + SQLState.REPLICATION_SLAVE_STARTED_OK.equals(ss)); + } + + // Next StartSlave connect should fail: + try + { + conn = DriverManager.getConnection(connectionURL); + util.DEBUG("2. Unexpectedly connected as: " + connectionURL); + assertTrue("2. Unexpectedly connected as: " + connectionURL, false); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + util.DEBUG(msg); + assertTrue("2. Unexpected SQLException: " + msg, + SQLState.LOGIN_FAILED.equals(ss)); + } + + } + + private void _testPreStartedMaster() + throws Exception + { + Connection conn = null; + String db = masterDatabasePath +"/"+ReplicationRun.masterDbSubPath +"/"+ replicatedDb; + String connectionURL = "jdbc:derby:" + + "//" + masterServerHost + ":" + masterServerPort + "/" + + db + + ";startMaster=true" + + ";slaveHost=" + slaveServerHost + + ";slavePort=" + slaveReplPort; + util.DEBUG("_testPreStartedMaster: " + connectionURL); + // First StartMaster connect ok: + // Must use "full" startMaster - including wait-loop. + + // Better move this to testPostStartedMasterAndSlave! + startMaster(jvmVersion, replicatedDb, + masterServerHost, // Where the startMaster command must be given + masterServerPort, // master server interface accepting client requests + masterServerHost, // An interface on the master: masterClientInterface (==masterServerHost), + slaveServerPort, // Not used since slave don't allow clients. + slaveServerHost, // for slaveReplInterface + slaveReplPort); + /* REMOVE! + try + { + conn = DriverManager.getConnection(connectionURL); + assertTrue("1. Unexpected!: startMaster Successfully connected as: " + + connectionURL, false); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + util.DEBUG(msg); + util.DEBUG("1. startMaster: No connection as expected: " + msg); + assertTrue("1. Unexpected SQLException: " + msg, + SQLState.REPLICATION_CONNECTION_EXCEPTION.equals(ss)); + } + */ + + util.DEBUG("2. startMaster attempt should fail on: " + connectionURL); + // util.DEBUG("********************'' 2. CURRENTLY HANGS!!!! Skipping."); + // if (false) // FIXME! ENABLE WHEN DERBY-3358 COMMITTED! + { + // A 2. StartMaster connect should fail: + try + { + conn = DriverManager.getConnection(connectionURL); + util.DEBUG("2. Unexpectedly connected as: " + connectionURL); + assertTrue("2. Unexpectedly connected as: " + connectionURL, false); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + util.DEBUG("2. startMaster No connection as expected: " + msg); + assertTrue("2. Unexpected SQLException: " + msg, + SQLState.REPLICATION_MASTER_ALREADY_BOOTED.equals(ss)); + } + } + + // A 2. StartSlave connect should fail: + util.DEBUG("startSlave attempt should fail on: " + connectionURL); + db = slaveDatabasePath +"/"+ReplicationRun.slaveDbSubPath +"/"+ replicatedDb; + connectionURL = "jdbc:derby:" + + "//" + slaveServerHost + ":" + slaveServerPort + "/" + + db + + ";startSlave=true" + + ";slaveHost=" + slaveServerHost + + ";slavePort=" + slaveReplPort; + util.DEBUG(connectionURL); + try + { + conn = DriverManager.getConnection(connectionURL); + util.DEBUG("3. startSlave Unexpectedly connected as: " + connectionURL); + assertTrue("3. startSlave Unexpectedly connected as: " + connectionURL, false); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + util.DEBUG("3. startSlave No connection as expected: " + msg); + assertTrue("3. Unexpected SQLException: " + msg, + SQLState.CANNOT_START_SLAVE_ALREADY_BOOTED.equals(ss)); + } + } + +} Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1.java ------------------------------------------------------------------------------ svn:eol-style = native Added: 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=634734&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java Fri Mar 7 08:34:18 2008 @@ -0,0 +1,254 @@ +/* + +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.DriverManager; +import java.sql.SQLException; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.apache.derby.shared.common.reference.SQLState; +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_StateTest_part1_1 extends ReplicationRun +{ + + /** + * Creates a new instance of ReplicationRun_Local_StateTest_part1 + * + * @param testcaseName Identifying the test. + */ + public ReplicationRun_Local_StateTest_part1_1(String testcaseName) + { + super(testcaseName); + } + + public static Test suite() + { + TestSuite suite = new TestSuite("ReplicationRun_Local_StateTest_part1_1 Suite"); + + suite.addTestSuite( ReplicationRun_Local_StateTest_part1_1.class ); + + return SecurityManagerSetup.noSecurityManager(suite); + } + + ////////////////////////////////////////////////////////////// + //// + //// The replication test framework (testReplication()): + //// a) "clean" replication run starting master and slave servers, + //// preparing master and slave databases, + //// starting and stopping replication and doing + //// failover for a "normal"/"failure free" replication + //// test run. + //// + ////////////////////////////////////////////////////////////// + + public void testReplication_Local_StateTest_part1_1() + throws Exception + { + cleanAllTestHosts(); + + initEnvironment(); + + initMaster(masterServerHost, + replicatedDb); + + masterServer = startServer(masterJvmVersion, derbyMasterVersion, + masterServerHost, + ALL_INTERFACES, // masterServerHost, // "0.0.0.0", // All. or use masterServerHost for interfacesToListenOn, + masterServerPort, + masterDatabasePath +FS+ masterDbSubPath); // Distinguishing master/slave + + slaveServer = startServer(slaveJvmVersion, derbySlaveVersion, + slaveServerHost, + ALL_INTERFACES, // slaveServerHost, // "0.0.0.0", // All. or use slaveServerHost for interfacesToListenOn, + slaveServerPort, + slaveDatabasePath +FS+ slaveDbSubPath); // Distinguishing master/slave + + startServerMonitor(slaveServerHost); + + bootMasterDatabase(jvmVersion, + masterDatabasePath +FS+ masterDbSubPath, + replicatedDb, + masterServerHost, // Where the startreplication command must be given + masterServerPort, // master server interface accepting client requests + null // bootLoad, // The "test" to start when booting db. + ); + + initSlave(slaveServerHost, + jvmVersion, + replicatedDb); // Trunk and Prototype V2: copy master db to db_slave. + + startSlave(jvmVersion, replicatedDb, + slaveServerHost, // slaveClientInterface // where the slave db runs + slaveServerPort, + slaveServerHost, // for slaveReplInterface + slaveReplPort, + testClientHost); + + // With master started above, next will fail! + // Also seems failover will fail w/XRE21! + // Further testing: skipping next startMaster seems to + // NOT remove failover failure! + /* TEMP: should be operational already - try skipping this. */ + startMaster(jvmVersion, replicatedDb, + masterServerHost, // Where the startMaster command must be given + masterServerPort, // master server interface accepting client requests + masterServerHost, // An interface on the master: masterClientInterface (==masterServerHost), + slaveServerPort, // Not used since slave don't allow clients. + slaveServerHost, // for slaveReplInterface + slaveReplPort); + /* */ + + + _testPostStartedMasterAndSlave_StopSlave(); // Not in a state to continue. + + stopServer(jvmVersion, derbyVersion, + slaveServerHost, slaveServerPort); + + stopServer(jvmVersion, derbyVersion, + masterServerHost, masterServerPort); + + } + + private void _testPostStartedMasterAndSlave_StopSlave() + throws InterruptedException + { + String db = null; + String connectionURL = null; + Connection conn = null; + + // 1. stopSlave to slave with connection to master should fail. + db = slaveDatabasePath +"/"+ReplicationRun.slaveDbSubPath +"/"+ replicatedDb; + connectionURL = "jdbc:derby:" + + "//" + slaveServerHost + ":" + slaveServerPort + "/" + + db + + ";stopSlave=true"; + util.DEBUG("1. testPostStartedMasterAndSlave_StopSlave: " + connectionURL); + try + { + conn = DriverManager.getConnection(connectionURL); + util.DEBUG("Unexpectdly connected as: " + connectionURL); + assertTrue("Unexpectedly connected: " + connectionURL,false); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + assertTrue("connectionURL + failed: " + msg, + SQLState.SLAVE_OPERATION_DENIED_WHILE_CONNECTED.equals(ss)); + util.DEBUG("1. Failed as expected: " + connectionURL + " " + msg); + } + // Default replication test sequence still OK. + + // 2. stopSlave to a master server should fail: + db = masterDatabasePath +"/"+ReplicationRun.masterDbSubPath +"/"+ replicatedDb; + connectionURL = "jdbc:derby:" + + "//" + masterServerHost + ":" + masterServerPort + "/" + + db + + ";stopSlave=true"; + util.DEBUG("2. testPostStartedMasterAndSlave_StopSlave: " + connectionURL); + try + { + conn = DriverManager.getConnection(connectionURL); // From anywhere against slaveServerHost? + util.DEBUG("Unexpectdly connected as: " + connectionURL); + // DERBY-???? - assertTrue("Unexpectedly connected: " + connectionURL,false); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + // SSQLCODE: -1, SQLSTATE: XRE40 + assertTrue("connectionURL + failed: " + msg, + SQLState.REPLICATION_NOT_IN_SLAVE_MODE.equals(ss)); + util.DEBUG("2. Failed as expected: " + connectionURL + " " + msg); + } + // Default replication test sequence still OK. + + // Replication should still be up. + + // 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 be allowed. Observe that the database shall be shutdown. + db = slaveDatabasePath +"/"+ReplicationRun.slaveDbSubPath +"/"+ replicatedDb; + connectionURL = "jdbc:derby:" + + "//" + slaveServerHost + ":" + slaveServerPort + "/" + + db + + ";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); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + assertTrue("connectionURL + failed: " + msg, + SQLState.REPLICATION_SLAVE_SHUTDOWN_OK.equals(ss)); + util.DEBUG("3. Failed as expected: " + connectionURL + " " + msg); + stopSlaveCorrect = true; + } + // Default replication test sequence will NOT be OK after this point. + + if ( stopSlaveCorrect ) + { + // 4. Try a normal connection: + connectionURL = "jdbc:derby:" + + "//" + 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); + util.DEBUG("4. Connected as expected: " + connectionURL); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + 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. + } + } + } + + +} Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_1.java ------------------------------------------------------------------------------ svn:eol-style = native Added: 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=634734&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java Fri Mar 7 08:34:18 2008 @@ -0,0 +1,298 @@ +/* + +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.DriverManager; +import java.sql.SQLException; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.apache.derby.shared.common.reference.SQLState; +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_StateTest_part1_2 extends ReplicationRun +{ + + /** + * Creates a new instance of ReplicationRun_Local_StateTest_part1 + * + * @param testcaseName Identifying the test. + */ + public ReplicationRun_Local_StateTest_part1_2(String testcaseName) + { + super(testcaseName); + } + + public static Test suite() + { + TestSuite suite = new TestSuite("ReplicationRun_Local_StateTest_part1_2 Suite"); + + suite.addTestSuite( ReplicationRun_Local_StateTest_part1_2.class ); + + return SecurityManagerSetup.noSecurityManager(suite); + } + + ////////////////////////////////////////////////////////////// + //// + //// The replication test framework (testReplication()): + //// a) "clean" replication run starting master and slave servers, + //// preparing master and slave databases, + //// starting and stopping replication and doing + //// failover for a "normal"/"failure free" replication + //// test run. + //// + ////////////////////////////////////////////////////////////// + + public void testReplication_Local_StateTest_part1_2() + throws Exception + { + cleanAllTestHosts(); + + initEnvironment(); + + initMaster(masterServerHost, + replicatedDb); + + masterServer = startServer(masterJvmVersion, derbyMasterVersion, + masterServerHost, + ALL_INTERFACES, // masterServerHost, // "0.0.0.0", // All. or use masterServerHost for interfacesToListenOn, + masterServerPort, + masterDatabasePath +FS+ masterDbSubPath); // Distinguishing master/slave + + + slaveServer = startServer(slaveJvmVersion, derbySlaveVersion, + slaveServerHost, + ALL_INTERFACES, // slaveServerHost, // "0.0.0.0", // All. or use slaveServerHost for interfacesToListenOn, + slaveServerPort, + slaveDatabasePath +FS+ slaveDbSubPath); // Distinguishing master/slave + + startServerMonitor(slaveServerHost); + + bootMasterDatabase(jvmVersion, + masterDatabasePath +FS+ masterDbSubPath, + replicatedDb, + masterServerHost, // Where the startreplication command must be given + masterServerPort, // master server interface accepting client requests + null // bootLoad, // The "test" to start when booting db. + ); + + initSlave(slaveServerHost, + jvmVersion, + replicatedDb); // Trunk and Prototype V2: copy master db to db_slave. + + startSlave(jvmVersion, replicatedDb, + slaveServerHost, // slaveClientInterface // where the slave db runs + slaveServerPort, + slaveServerHost, // for slaveReplInterface + slaveReplPort, + testClientHost); + + // With master started above, next will fail! + // Also seems failover will fail w/XRE21! + // Further testing: skipping next startMaster seems to + // NOT remove failover failure! + /* TEMP: should be operational already - try skipping this. */ + startMaster(jvmVersion, replicatedDb, + masterServerHost, // Where the startMaster command must be given + masterServerPort, // master server interface accepting client requests + masterServerHost, // An interface on the master: masterClientInterface (==masterServerHost), + slaveServerPort, // Not used since slave don't allow clients. + slaveServerHost, // for slaveReplInterface + slaveReplPort); + /* */ + + _testPostStartedMasterAndSlave_StopMaster(); // Not in a state to continue. + + stopServer(jvmVersion, derbyVersion, + slaveServerHost, slaveServerPort); + + stopServer(jvmVersion, derbyVersion, + masterServerHost, masterServerPort); + + } + + + private void _testPostStartedMasterAndSlave_StopMaster() + throws InterruptedException + { + Connection conn = null; + String db = null; + String connectionURL = null; + + // 1. Attempt to perform stopMaster on slave. Should fail. + db = slaveDatabasePath +"/"+ReplicationRun.slaveDbSubPath + +"/"+ replicatedDb; + connectionURL = "jdbc:derby:" + + "//" + slaveServerHost + ":" + slaveServerPort + "/" + + db + + ";stopMaster=true"; + util.DEBUG("1. testPostStartedMasterAndSlave_StopMaster: " + + connectionURL); + try + { + conn = DriverManager.getConnection(connectionURL); + util.DEBUG("Unexpectedly connected as: " + connectionURL); + assertTrue("Unexpectedly connected as: " + connectionURL,false); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + // SQLCODE: -1, SQLSTATE: 08004 + assertTrue("connectionURL + failed: " + msg, + SQLState.LOGIN_FAILED.equals(ss)); + util.DEBUG("stopMaster on slave failed as expected: " + + connectionURL + " " + msg); + } + // Default replication test sequence still OK. + + // 2. stopMaster on master: OK + db = masterDatabasePath +"/"+ReplicationRun.masterDbSubPath + +"/"+ replicatedDb; + connectionURL = "jdbc:derby:" + + "//" + masterServerHost + ":" + masterServerPort + "/" + + db + + ";stopMaster=true"; + util.DEBUG("2. testPostStartedMasterAndSlave_StopMaster: " + + connectionURL); + try + { + conn = DriverManager.getConnection(connectionURL); + util.DEBUG("Connected as expected: " + connectionURL); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + util.DEBUG("stopMaster on master failed: " + connectionURL + " " + msg); + assertTrue("stopMaster on master failed: " + connectionURL + " " + msg,false); + } + // Not meaningful to continue default replication test sequence after this point! + + // 3. Connect to slave which now is not in non-replication mode is OK. + db = slaveDatabasePath +"/"+ReplicationRun.slaveDbSubPath +"/"+ replicatedDb; + connectionURL = "jdbc:derby:" + + "//" + 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); + } + 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); + } + + // 4. stopMaster on slave which now is not in replication mode should fail. + db = slaveDatabasePath +"/"+ReplicationRun.slaveDbSubPath +"/"+ replicatedDb; + connectionURL = "jdbc:derby:" + + "//" + slaveServerHost + ":" + slaveServerPort + "/" + + db + + ";stopMaster=true"; + util.DEBUG("4. testPostStartedMasterAndSlave_StopMaster: " + connectionURL); + try + { + conn = DriverManager.getConnection(connectionURL); + util.DEBUG("4. Unexpectedly connected: " + connectionURL); + assertTrue("4. Unexpectedly connected: " + connectionURL,false); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + assertTrue("4. stopMaster on slave failed with: " + + connectionURL + " " + msg, + SQLState.REPLICATION_NOT_IN_MASTER_MODE.equals(ss)); + util.DEBUG("4. stopMaster on slave failed as expected: " + + connectionURL + " " + msg); + } + + // 5. Connect master which now is now in non-replication mode should succeed. + db = masterDatabasePath +"/"+ReplicationRun.masterDbSubPath +"/"+ replicatedDb; + connectionURL = "jdbc:derby:" + + "//" + masterServerHost + ":" + masterServerPort + "/" + + db; + util.DEBUG("5. testPostStartedMasterAndSlave_StopMaster: " + connectionURL); + try + { + conn = DriverManager.getConnection(connectionURL); + util.DEBUG("5. Successfully connected: " + connectionURL); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + util.DEBUG("5. Connect to db not in master mode unexpectedly failed : " + + connectionURL + " " + msg); + assertTrue("5. Connect to db not in master mode unexpectedly failed : " + + connectionURL + " " + msg, false); + } + + // 6. Attempt to do stopmaster on master which now is now in non-replication mode should fail. + db = masterDatabasePath +"/"+ReplicationRun.masterDbSubPath + +"/"+ replicatedDb; + connectionURL = "jdbc:derby:" + + "//" + masterServerHost + ":" + masterServerPort + "/" + + db + + ";stopMaster=true"; + util.DEBUG("6. testPostStartedMasterAndSlave_StopMaster: " + connectionURL); + try + { + conn = DriverManager.getConnection(connectionURL); + util.DEBUG("6. Unexpectedly connected: " + connectionURL); + assertTrue("6. Unexpectedly connected: " + connectionURL,false); + } + catch (SQLException se) + { + int ec = se.getErrorCode(); + String ss = se.getSQLState(); + String msg = ec + " " + ss + " " + se.getMessage(); + assertTrue("6. stopMaster on server not in master mode failed with: " + + connectionURL + " " + msg, + SQLState.REPLICATION_NOT_IN_MASTER_MODE.equals(ss)); + util.DEBUG("6. stopMaster on server not in master mode failed as expected: " + + connectionURL + " " + msg); + } + } + +} Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun_Local_StateTest_part1_2.java ------------------------------------------------------------------------------ svn:eol-style = native