org.apache.derbyTesting.junit.BaseJDBCTestCase Java Examples
The following examples show how to use
org.apache.derbyTesting.junit.BaseJDBCTestCase.
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: 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 #2
Source File: BLOBDataModelSetup.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Teardown test. * Rollback connection and close it. * @exception Exceptions causes the test to fail with error */ protected final void tearDown() throws Exception { // GemStone changes BEGIN super.preTearDown(); // GemStone changes END try { Connection con = getConnection(); Statement statement = con.createStatement(); statement.execute("DROP TABLE " + tableName); statement.close(); con.commit(); } catch (SQLException e) { BaseJDBCTestCase.printStackTrace(e); } super.tearDown(); }
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 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 #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: BLOBDataModelSetup.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Teardown test. * Rollback connection and close it. * @exception Exceptions causes the test to fail with error */ protected final void tearDown() throws Exception { // GemStone changes BEGIN super.preTearDown(); // GemStone changes END try { Connection con = getConnection(); Statement statement = con.createStatement(); statement.execute("DROP TABLE " + tableName); statement.close(); con.commit(); } catch (SQLException e) { BaseJDBCTestCase.printStackTrace(e); } super.tearDown(); }
Example #8
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 #9
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 #10
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 #11
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 #12
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 #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 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 #15
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 #16
Source File: SURDataModelSetup.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Creates a datamodel for testing Scrollable Updatable ResultSets * and populates the database model with data. * @param model enumerator for which model to use * @param con connection to database * @param records number of records in the data model */ public static void createDataModel(SURDataModel model, Connection con, int records) throws SQLException { BaseJDBCTestCase.dropTable(con, "T1"); Statement statement = con.createStatement(); /** Create the table */ statement.execute(model.getCreateTableStatement()); BaseTestCase.println(model.getCreateTableStatement()); /** Create secondary index */ if (model.hasSecondaryKey()) { statement.execute("create index a_on_t on t1(a)"); BaseTestCase.println("create index a_on_t on t1(a)"); } /** Populate with data */ PreparedStatement ps = con. prepareStatement("insert into t1 values (?,?,?,?)"); for (int i=0; i<records; i++) { ps.setInt(1, i); ps.setInt(2, i); ps.setInt(3, i*2 + 17); ps.setString(4, "Tuple " +i); ps.addBatch(); } ps.executeBatch(); ps.close(); statement.close(); con.commit(); }
Example #17
Source File: SURDataModelSetup.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Creates a datamodel for testing Scrollable Updatable ResultSets * and populates the database model with data. * @param model enumerator for which model to use * @param con connection to database * @param records number of records in the data model */ public static void createDataModel(SURDataModel model, Connection con, int records) throws SQLException { BaseJDBCTestCase.dropTable(con, "T1"); Statement statement = con.createStatement(); /** Create the table */ statement.execute(model.getCreateTableStatement()); BaseTestCase.println(model.getCreateTableStatement()); /** Create secondary index */ if (model.hasSecondaryKey()) { statement.execute("create index a_on_t on t1(a)"); BaseTestCase.println("create index a_on_t on t1(a)"); } /** Populate with data */ PreparedStatement ps = con. prepareStatement("insert into t1 values (?,?,?,?)"); for (int i=0; i<records; i++) { ps.setInt(1, i); ps.setInt(2, i); ps.setInt(3, i*2 + 17); ps.setString(4, "Tuple " +i); ps.addBatch(); } ps.executeBatch(); ps.close(); statement.close(); con.commit(); }
Example #18
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 #19
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 #20
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 #21
Source File: SURDataModelSetup.java From gemfirexd-oss with Apache License 2.0 | 2 votes |
/** * Prints the stack trace. If run in the harness, the * harness will mark the test as failed if this method * has been called. */ static void printStackTrace(Throwable t) { BaseJDBCTestCase.printStackTrace(t); }
Example #22
Source File: SURDataModelSetup.java From gemfirexd-oss with Apache License 2.0 | 2 votes |
/** * Prints the stack trace. If run in the harness, the * harness will mark the test as failed if this method * has been called. */ static void printStackTrace(Throwable t) { BaseJDBCTestCase.printStackTrace(t); }