package testsuite.simple; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import testsuite.BaseTestCase; import com.mysql.jdbc.Messages; public class ConnPropDontTrackOpenResources extends BaseTestCase { public ConnPropDontTrackOpenResources(String name) { super(name); } public static void main(String[] args) { junit.textui.TestRunner.run(ConnPropDontTrackOpenResources.class); } public void testBug() throws Exception { Connection testConnection = getConnectionWithProps("dontTrackOpenResources=true"); Statement testStatement = testConnection.createStatement(); ResultSet testResultSet = testStatement.executeQuery("SELECT 1"); assertFalse("Connection should not be closed.", testConnection.isClosed()); assertFalse("Statement should not be closed.", isClosedStatement(testStatement)); assertFalse("ResultSet should not be closed.", isClosedResultSet(testResultSet)); testConnection.close(); assertTrue("Connection should be closed.", testConnection.isClosed()); assertFalse("Statement should not be closed.", isClosedStatement(testStatement)); assertFalse("ResultSet should not be closed.", isClosedResultSet(testResultSet)); testStatement.close(); assertTrue("Connection should be closed.", testConnection.isClosed()); assertTrue("Statement should be closed.", isClosedStatement(testStatement)); assertFalse("ResultSet should not be closed.", isClosedResultSet(testResultSet)); testResultSet.close(); assertTrue("Connection should be closed.", testConnection.isClosed()); assertTrue("Statement should be closed.", isClosedStatement(testStatement)); assertTrue("ResultSet should be closed.", isClosedResultSet(testResultSet)); } private boolean isClosedStatement(Statement statement) { try { statement.getResultSet(); } catch (SQLException ex) { return ex.getMessage().compareToIgnoreCase(Messages.getString("Statement.49")) == 0; } return false; } private boolean isClosedResultSet(ResultSet resultSet) { try { resultSet.first(); } catch (SQLException ex) { return ex.getMessage().compareToIgnoreCase( Messages.getString("ResultSet.Operation_not_allowed_after_ResultSet_closed_144")) == 0; } return false; } }