Author: fhanik
Date: Fri Aug 8 00:22:51 2014
New Revision: 1616649
URL: http://svn.apache.org/r1616649
Log:
Fix suspect test cases. If validation times out, it should be treated as a
validation error.
Modified:
tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestValidationQueryTimeout.java
Modified:
tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestValidationQueryTimeout.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestValidationQueryTimeout.java?rev=1616649&r1=1616648&r2=1616649&view=diff
==============================================================================
---
tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestValidationQueryTimeout.java
(original)
+++
tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestValidationQueryTimeout.java
Fri Aug 8 00:22:51 2014
@@ -34,6 +34,8 @@ import org.junit.Test;
import org.apache.tomcat.jdbc.pool.interceptor.QueryTimeoutInterceptor;
+import static org.junit.Assert.fail;
+
public class TestValidationQueryTimeout extends DefaultTestCase {
private static int TIMEOUT = 10;
@@ -131,7 +133,7 @@ public class TestValidationQueryTimeout
@Test(expected=SQLException.class)
public void testValidationInvalidOnConnection() throws Exception {
- // use our mock driver
+ // use a real driver cause we have an invalid query to validate
this.datasource.setDriverClassName("org.h2.Driver");
this.datasource.setUrl("jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=FALSE");
@@ -161,38 +163,31 @@ public class TestValidationQueryTimeout
// this is a requirement for other tests to run properly
start = System.currentTimeMillis();
stmt.execute(longQuery);
- } catch (SQLException ex) {}
- finally {
+ } catch (SQLTimeoutException ex) {
+
+ } catch (SQLException x) {
+ fail("We should have got a timeout exception.");
+ } finally {
end = System.currentTimeMillis();
if (stmt != null) { stmt.close(); }
if (con != null) { con.close(); }
Assert.assertTrue(start != 0 && end != 0);
- Assert.assertTrue((end - start) > 1000);
+ //we're faking it
+ //Assert.assertTrue((end - start) > 1000);
}
}
- @Test
+ @Test(expected = SQLException.class)
public void testValidationQueryTimeoutOnBorrow() throws Exception {
- // use our mock driver
- this.datasource.setDriverClassName("org.h2.Driver");
-
this.datasource.setUrl("jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=FALSE");
-
// Required to trigger validation query's execution
this.datasource.setTestOnBorrow(true);
this.datasource.setValidationInterval(-1);
this.datasource.setValidationQuery(longQuery);
this.datasource.setValidationQueryTimeout(1);
-
- // assert that even though the validation query times out, we still
get a connection
+ // assert that even though the validation query we don't get a
connection
Connection con = this.datasource.getConnection();
- Assert.assertNotNull(con);
- Statement st = con.createStatement();
- ResultSet rs = st.executeQuery("SELECT 1");
- rs.close();
- st.close();
- con.close();
}
/**
@@ -261,10 +256,6 @@ public class TestValidationQueryTimeout
@Override
public boolean execute(String sql) throws SQLException {
if (longQuery.equals(sql)) {
- try {
- Thread.sleep(getQueryTimeout() * 1000);
- }catch (Exception x) {
- }
throw new SQLTimeoutException();
} else {
return super.execute(sql);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]