public void test_create() throws Exception { DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class); conn.getConnection().close(); { SQLException error = null; try { conn.createStatement(); } catch (SQLException ex) { error = ex; } Assert.assertNotNull(error); } conn.close(); }
public void test_create_2() throws Exception { DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class); conn.getConnection().close(); { SQLException error = null; try { conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); } catch (SQLException ex) { error = ex; } Assert.assertNotNull(error); } conn.close(); }
public void test_connect() throws Exception { String sql = "SELECT 1"; { DruidPooledConnection conn = dataSource.getConnection(); PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.execute(); pstmt.close(); conn.close(); } DruidPooledConnection conn = dataSource.getConnection(); MockConnection mockConn = conn.unwrap(MockConnection.class); Assert.assertNotNull(mockConn); Statement stmt = conn.createStatement(); stmt.addBatch(sql); SQLException exception = new SQLException("xx", "xxx", 28); mockConn.setError(exception); SQLException stmtErrror = null; try { stmt.executeBatch(); } catch (SQLException ex) { stmtErrror = ex; } Assert.assertNotNull(stmtErrror); Assert.assertSame(exception, stmtErrror); SQLException commitError = null; try { conn.commit(); } catch (SQLException ex) { commitError = ex; } Assert.assertNotNull(commitError); Assert.assertSame(exception, commitError.getCause()); conn.close(); }
public void test_rollback() throws Exception { DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class); conn.setAutoCommit(false); Statement stmt = conn.createStatement(); stmt.execute("SELECT 1"); conn.getConnection().close(); { SQLException error = null; try { conn.rollback(); } catch (SQLException ex) { error = ex; } Assert.assertNotNull(error); } conn.close(); }