Author: fhanik Date: Thu Aug 7 23:16:14 2014 New Revision: 1616625 URL: http://svn.apache.org/r1616625 Log: Fixed validation when testOnConnect=false. In this case, we need to verify, do we have an init query, if so, do an init validation, otherwise do a borrow validation.
Added: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug54978.java (with props) Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java?rev=1616625&r1=1616624&r2=1616625&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java Thu Aug 7 23:16:14 2014 @@ -794,7 +794,11 @@ public class ConnectionPool { //the connection shouldn't have to poll again. try { con.reconnect(); - if (con.validate(PooledConnection.VALIDATE_INIT)) { + int validationMode = getPoolProperties().isTestOnConnect() || getPoolProperties().getInitSQL()!=null ? + PooledConnection.VALIDATE_INIT : + PooledConnection.VALIDATE_BORROW; + + if (con.validate(validationMode)) { //set the timestamp con.setTimestamp(now); if (getPoolProperties().isLogAbandoned()) { Added: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug54978.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug54978.java?rev=1616625&view=auto ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug54978.java (added) +++ tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug54978.java Thu Aug 7 23:16:14 2014 @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomcat.jdbc.bugs; + +import org.apache.tomcat.jdbc.pool.DataSource; +import org.apache.tomcat.jdbc.pool.PoolProperties; +import org.apache.tomcat.jdbc.test.DefaultProperties; +import org.junit.Test; + +import java.sql.SQLException; + +import static org.junit.Assert.fail; + +public class Bug54978 { + + @Test + public void testIllegalValidationQuery() throws SQLException, InterruptedException { + PoolProperties poolProperties = new DefaultProperties(); + poolProperties.setMinIdle(0); + poolProperties.setInitialSize(1); + poolProperties.setMaxActive(1); + poolProperties.setMaxWait(5000); + poolProperties.setMaxAge(100); + poolProperties.setRemoveAbandoned(false); + poolProperties.setTestOnBorrow(true); + poolProperties.setTestOnConnect(false); + poolProperties.setValidationQuery("sdadsada"); + final DataSource ds = new DataSource(poolProperties); + try { + ds.getConnection().close(); + fail("Validation should have failed."); + }catch (SQLException x) { + } + } + + @Test + public void testIllegalValidationQueryWithLegalInit() throws SQLException, InterruptedException { + PoolProperties poolProperties = new DefaultProperties(); + poolProperties.setMinIdle(0); + poolProperties.setInitialSize(1); + poolProperties.setMaxActive(1); + poolProperties.setMaxWait(5000); + poolProperties.setMaxAge(100); + poolProperties.setRemoveAbandoned(false); + poolProperties.setTestOnBorrow(true); + poolProperties.setTestOnConnect(false); + poolProperties.setValidationQuery("sdadsada"); + poolProperties.setInitSQL("SELECT 1"); + final DataSource ds = new DataSource(poolProperties); + ds.getConnection().close(); + } +} \ No newline at end of file Propchange: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug54978.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org