/** * This method tests the functionality of connection with error in high stress. * * @throws Exception if any error occurs. */ public void testStressForConnectionWithError() throws Exception { long startTime = System.currentTimeMillis(); for (int i = 0; i < COUNT; ++i) { Connection conn = null; try { conn = new DBConnectionFactoryImpl(DBConnectionFactoryImpl.class.getName()).createConnection(); conn.setAutoCommit(true); StressHelper.doDMLQuery(conn, QUERY6, new Object[] {}); conn.close(); conn = new DBConnectionFactoryImpl(DBConnectionFactoryImpl.class.getName()).createConnection(); conn.setAutoCommit(false); StressHelper.doDMLQuery(conn, QUERY4, new Object[] {}); persistence.closeConnectionOnError(conn); assertTrue("Fails to close the connection.", conn.isClosed()); conn = new DBConnectionFactoryImpl(DBConnectionFactoryImpl.class.getName()).createConnection(); conn.setAutoCommit(true); Object[][] rows = StressHelper.doQuery( conn, QUERY5, new Object[] {}, new DataType[] {StressHelper.STRING_TYPE}); assertEquals("Fails to commit the changes in database.", 0, rows.length); conn.close(); conn = new DBConnectionFactoryImpl(DBConnectionFactoryImpl.class.getName()).createConnection(); conn.setAutoCommit(true); StressHelper.doDMLQuery(conn, QUERY6, new Object[] {}); conn.close(); } finally { if (conn != null && !conn.isClosed()) { conn.close(); } } } long endTime = System.currentTimeMillis(); System.out.println( "The stress test for connection with error costs: " + (endTime - startTime) + " milliseconds."); }