Java Code Examples for org.apache.derbyTesting.junit.BaseJDBCTestCase#assertSQLState()
The following examples show how to use
org.apache.derbyTesting.junit.BaseJDBCTestCase#assertSQLState() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CollationTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * We should get a locale unavailable message because there is no support for * locale xx. */ public void testMissingCollatorSupport() throws SQLException { String createDBurl = ";create=true;territory=xx;collation=TERRITORY_BASED"; try { //Use following utility method rather than //DriverManager.getConnection because the following utility method //will use DataSource or DriverManager depending on the VM that is //being used. Use of DriverManager to get a Connection will faile //on JSR169 VMs. DERBY-3052 // GemStone changes BEGIN TestUtil.getConnection("gemfirexd", createDBurl); /* (original code) TestUtil.getConnection("missingCollatorDB", createDBurl); */ // GemStone changes END } catch (SQLException sqle) { //Database can't be created because Collator support does not exist //for the requested locale BaseJDBCTestCase.assertSQLState("Unexpected error when connecting to database ", "XBM04", sqle); } }
Example 2
Source File: ReplicationRun.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Assert that the latest startSlave connection attempt got the expected * SQLState. The method will wait for upto 5 seconds for the startSlave * connection attemt to complete. If the connection attempt has not * completed after 5 seconds it is assumed to have failed. * @param expected the expected SQLState * @throws java.lang.Exception the Exception to check the SQLState of */ protected void assertSqlStateSlaveConn(String expected) throws Exception { boolean verified = false; for (int i = 0; i < 10; i++) { if (startSlaveException != null) { if (startSlaveException instanceof SQLException) { BaseJDBCTestCase. assertSQLState("Unexpexted SQL State", expected, (SQLException)startSlaveException); verified = true; break; } else { throw startSlaveException; } } else { Thread.sleep(500); } } if (!verified) { fail("Attempt to start slave hangs. Expected SQL state " + expected); } }
Example 3
Source File: CollationTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * We should get a locale unavailable message because there is no support for * locale xx. */ public void testMissingCollatorSupport() throws SQLException { String createDBurl = ";create=true;territory=xx;collation=TERRITORY_BASED"; try { //Use following utility method rather than //DriverManager.getConnection because the following utility method //will use DataSource or DriverManager depending on the VM that is //being used. Use of DriverManager to get a Connection will faile //on JSR169 VMs. DERBY-3052 // GemStone changes BEGIN TestUtil.getConnection("gemfirexd", createDBurl); /* (original code) TestUtil.getConnection("missingCollatorDB", createDBurl); */ // GemStone changes END } catch (SQLException sqle) { //Database can't be created because Collator support does not exist //for the requested locale BaseJDBCTestCase.assertSQLState("Unexpected error when connecting to database ", "XBM04", sqle); } }
Example 4
Source File: ReplicationRun.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Assert that the latest startSlave connection attempt got the expected * SQLState. The method will wait for upto 5 seconds for the startSlave * connection attemt to complete. If the connection attempt has not * completed after 5 seconds it is assumed to have failed. * @param expected the expected SQLState * @throws java.lang.Exception the Exception to check the SQLState of */ protected void assertSqlStateSlaveConn(String expected) throws Exception { boolean verified = false; for (int i = 0; i < 10; i++) { if (startSlaveException != null) { if (startSlaveException instanceof SQLException) { BaseJDBCTestCase. assertSQLState("Unexpexted SQL State", expected, (SQLException)startSlaveException); verified = true; break; } else { throw startSlaveException; } } else { Thread.sleep(500); } } if (!verified) { fail("Attempt to start slave hangs. Expected SQL state " + expected); } }
Example 5
Source File: 919148_ReplicationRun_0_s.java From coming with MIT License | 6 votes |
/** * Assert that the latest startSlave connection attempt got the expected * SQLState. The method will wait for upto 5 seconds for the startSlave * connection attemt to complete. If the connection attempt has not * completed after 5 seconds it is assumed to have failed. * @param expected the expected SQLState * @throws java.lang.Exception the Exception to check the SQLState of */ protected void assertSqlStateSlaveConn(String expected) throws Exception { boolean verified = false; for (int i = 0; i < 10; i++) { if (startSlaveException != null) { if (startSlaveException instanceof SQLException) { BaseJDBCTestCase. assertSQLState("Unexpexted SQL State", expected, (SQLException)startSlaveException); verified = true; break; } else { throw startSlaveException; } } else { Thread.sleep(500); } } if (!verified) { fail("Attempt to start slave hangs. Expected SQL state " + expected); } }
Example 6
Source File: 919148_ReplicationRun_0_t.java From coming with MIT License | 6 votes |
/** * Assert that the latest startSlave connection attempt got the expected * SQLState. The method will wait for upto 5 seconds for the startSlave * connection attemt to complete. If the connection attempt has not * completed after 5 seconds it is assumed to have failed. * @param expected the expected SQLState * @throws java.lang.Exception the Exception to check the SQLState of */ protected void assertSqlStateSlaveConn(String expected) throws Exception { boolean verified = false; for (int i = 0; i < 10; i++) { if (startSlaveException != null) { if (startSlaveException instanceof SQLException) { BaseJDBCTestCase. assertSQLState("Unexpexted SQL State", expected, (SQLException)startSlaveException); verified = true; break; } else { throw startSlaveException; } } else { Thread.sleep(500); } } if (!verified) { fail("Attempt to start slave hangs. Expected SQL state " + expected); } }
Example 7
Source File: 919148_ReplicationRun_0_s.java From gumtree-spoon-ast-diff with Apache License 2.0 | 6 votes |
/** * Assert that the latest startSlave connection attempt got the expected * SQLState. The method will wait for upto 5 seconds for the startSlave * connection attemt to complete. If the connection attempt has not * completed after 5 seconds it is assumed to have failed. * @param expected the expected SQLState * @throws java.lang.Exception the Exception to check the SQLState of */ protected void assertSqlStateSlaveConn(String expected) throws Exception { boolean verified = false; for (int i = 0; i < 10; i++) { if (startSlaveException != null) { if (startSlaveException instanceof SQLException) { BaseJDBCTestCase. assertSQLState("Unexpexted SQL State", expected, (SQLException)startSlaveException); verified = true; break; } else { throw startSlaveException; } } else { Thread.sleep(500); } } if (!verified) { fail("Attempt to start slave hangs. Expected SQL state " + expected); } }
Example 8
Source File: 919148_ReplicationRun_0_t.java From gumtree-spoon-ast-diff with Apache License 2.0 | 6 votes |
/** * Assert that the latest startSlave connection attempt got the expected * SQLState. The method will wait for upto 5 seconds for the startSlave * connection attemt to complete. If the connection attempt has not * completed after 5 seconds it is assumed to have failed. * @param expected the expected SQLState * @throws java.lang.Exception the Exception to check the SQLState of */ protected void assertSqlStateSlaveConn(String expected) throws Exception { boolean verified = false; for (int i = 0; i < 10; i++) { if (startSlaveException != null) { if (startSlaveException instanceof SQLException) { BaseJDBCTestCase. assertSQLState("Unexpexted SQL State", expected, (SQLException)startSlaveException); verified = true; break; } else { throw startSlaveException; } } else { Thread.sleep(500); } } if (!verified) { fail("Attempt to start slave hangs. Expected SQL state " + expected); } }
Example 9
Source File: ReplicationRun.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private void failOver_direct(String dbPath, String dbSubPath, String dbName, String host, // Where the db is run. int serverPort) throws Exception { String URL = DB_PROTOCOL +"://"+host +":"+serverPort+"/" +dbPath+FS+dbSubPath+FS+dbName +";failover=true"; util.DEBUG("failOver_direct getConnection("+URL+")"); Connection conn = null; try { Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes! conn = DriverManager.getConnection(URL); // conn.close(); } catch (SQLException se) { int errCode = se.getErrorCode(); String msg = se.getMessage(); String state = se.getSQLState(); String expectedState = "XRE20"; util.DEBUG("failOver_direct Got SQLException: " + errCode + " " + state + " " + msg); BaseJDBCTestCase.assertSQLState(expectedState, se); } }
Example 10
Source File: ReplicationRun.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private void failOver_direct(String dbPath, String dbSubPath, String dbName, String host, // Where the db is run. int serverPort) throws Exception { String URL = DB_PROTOCOL +"://"+host +":"+serverPort+"/" +dbPath+FS+dbSubPath+FS+dbName +";failover=true"; util.DEBUG("failOver_direct getConnection("+URL+")"); Connection conn = null; try { Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes! conn = DriverManager.getConnection(URL); // conn.close(); } catch (SQLException se) { int errCode = se.getErrorCode(); String msg = se.getMessage(); String state = se.getSQLState(); String expectedState = "XRE20"; util.DEBUG("failOver_direct Got SQLException: " + errCode + " " + state + " " + msg); BaseJDBCTestCase.assertSQLState(expectedState, se); } }
Example 11
Source File: 919148_ReplicationRun_0_s.java From coming with MIT License | 5 votes |
private void failOver_direct(String dbPath, String dbSubPath, String dbName, String host, // Where the db is run. int serverPort) throws Exception { String URL = masterURL(dbName) +";failover=true"; util.DEBUG("failOver_direct getConnection("+URL+")"); Connection conn = null; try { Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes! conn = DriverManager.getConnection(URL); // conn.close(); } catch (SQLException se) { int errCode = se.getErrorCode(); String msg = se.getMessage(); String sState = se.getSQLState(); String expectedState = "XRE20"; msg = "failOver_direct Got SQLException: " + errCode + " " + sState + " " + msg + ". Expected: " + expectedState; util.DEBUG(msg); BaseJDBCTestCase.assertSQLState(expectedState, se); } }
Example 12
Source File: 919148_ReplicationRun_0_t.java From coming with MIT License | 5 votes |
private void failOver_direct(String dbPath, String dbSubPath, String dbName, String host, // Where the db is run. int serverPort) throws Exception { String URL = masterURL(dbName) +";failover=true"; util.DEBUG("failOver_direct getConnection("+URL+")"); Connection conn = null; try { Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes! conn = DriverManager.getConnection(URL); // conn.close(); } catch (SQLException se) { int errCode = se.getErrorCode(); String msg = se.getMessage(); String sState = se.getSQLState(); String expectedState = "XRE20"; msg = "failOver_direct Got SQLException: " + errCode + " " + sState + " " + msg + ". Expected: " + expectedState; util.DEBUG(msg); BaseJDBCTestCase.assertSQLState(expectedState, se); } }
Example 13
Source File: 919148_ReplicationRun_0_s.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
private void failOver_direct(String dbPath, String dbSubPath, String dbName, String host, // Where the db is run. int serverPort) throws Exception { String URL = masterURL(dbName) +";failover=true"; util.DEBUG("failOver_direct getConnection("+URL+")"); Connection conn = null; try { Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes! conn = DriverManager.getConnection(URL); // conn.close(); } catch (SQLException se) { int errCode = se.getErrorCode(); String msg = se.getMessage(); String sState = se.getSQLState(); String expectedState = "XRE20"; msg = "failOver_direct Got SQLException: " + errCode + " " + sState + " " + msg + ". Expected: " + expectedState; util.DEBUG(msg); BaseJDBCTestCase.assertSQLState(expectedState, se); } }
Example 14
Source File: 919148_ReplicationRun_0_t.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
private void failOver_direct(String dbPath, String dbSubPath, String dbName, String host, // Where the db is run. int serverPort) throws Exception { String URL = masterURL(dbName) +";failover=true"; util.DEBUG("failOver_direct getConnection("+URL+")"); Connection conn = null; try { Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes! conn = DriverManager.getConnection(URL); // conn.close(); } catch (SQLException se) { int errCode = se.getErrorCode(); String msg = se.getMessage(); String sState = se.getSQLState(); String expectedState = "XRE20"; msg = "failOver_direct Got SQLException: " + errCode + " " + sState + " " + msg + ". Expected: " + expectedState; util.DEBUG(msg); BaseJDBCTestCase.assertSQLState(expectedState, se); } }
Example 15
Source File: ReplicationRun_Local.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * DERBY-3382: Test that start replication fails if master db is updated * after copying the db to the slave location * @throws java.lang.Exception on test errors. */ public void testLogFilesSynched() 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); // copy db to slave initSlave(slaveServerHost, jvmVersion, replicatedDb); // database has now been copied to slave. Updating the master // database at this point will cause unsynced log files executeOnMaster("call syscs_util.syscs_unfreeze_database()"); executeOnMaster("create table breakLogSynch (v varchar(20))"); executeOnMaster("drop table breakLogSynch"); // startSlave is supposed do fail. We check the sql state in // assertSqlStateSlaveConn below startSlave(jvmVersion, replicatedDb, slaveServerHost, slaveServerPort, slaveServerHost, slaveReplPort, testClientHost); SQLException sqlexception = null; try { startMaster(jvmVersion, replicatedDb, masterServerHost, masterServerPort, masterServerHost, slaveServerPort, slaveServerHost, slaveReplPort); } catch (SQLException sqle) { sqlexception = sqle; } // the startMaster connection attempt should fail with exception XRE05 if (sqlexception == null) { fail("Start master did not get the expected SQL Exception XRE05"); } else { BaseJDBCTestCase.assertSQLState("Unexpected SQL state.", "XRE05", sqlexception); } // The startSlave connection attempt should fail with exception XJ040 assertSqlStateSlaveConn("XJ040"); stopServer(jvmVersion, derbyVersion, masterServerHost, masterServerPort); stopServer(jvmVersion, derbyVersion, slaveServerHost, slaveServerPort); }
Example 16
Source File: ReplicationRun_Local.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * DERBY-3382: Test that start replication fails if master db is updated * after copying the db to the slave location * @throws java.lang.Exception on test errors. */ public void testLogFilesSynched() 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); // copy db to slave initSlave(slaveServerHost, jvmVersion, replicatedDb); // database has now been copied to slave. Updating the master // database at this point will cause unsynced log files executeOnMaster("call syscs_util.syscs_unfreeze_database()"); executeOnMaster("create table breakLogSynch (v varchar(20))"); executeOnMaster("drop table breakLogSynch"); // startSlave is supposed do fail. We check the sql state in // assertSqlStateSlaveConn below startSlave(jvmVersion, replicatedDb, slaveServerHost, slaveServerPort, slaveServerHost, slaveReplPort, testClientHost); SQLException sqlexception = null; try { startMaster(jvmVersion, replicatedDb, masterServerHost, masterServerPort, masterServerHost, slaveServerPort, slaveServerHost, slaveReplPort); } catch (SQLException sqle) { sqlexception = sqle; } // the startMaster connection attempt should fail with exception XRE05 if (sqlexception == null) { fail("Start master did not get the expected SQL Exception XRE05"); } else { BaseJDBCTestCase.assertSQLState("Unexpected SQL state.", "XRE05", sqlexception); } // The startSlave connection attempt should fail with exception XJ040 assertSqlStateSlaveConn("XJ040"); stopServer(jvmVersion, derbyVersion, masterServerHost, masterServerPort); stopServer(jvmVersion, derbyVersion, slaveServerHost, slaveServerPort); }