Make properties configurable and resolve https://issues.apache.org/bugzilla/show_bug...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 29 Jun 2009 14:36:57 +0000 (14:36 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 29 Jun 2009 14:36:57 +0000 (14:36 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@789345 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CheckOutThreadTest.java
modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultProperties.java
modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestSlowQueryReport.java

index 7196df9..93e7ef1 100644 (file)
@@ -202,7 +202,6 @@ public class CheckOutThreadTest extends DefaultTestCase {
     public void testDBCPThreads10Connections10Validate() throws Exception {
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
-        this.datasource.getPoolProperties().setValidationQuery("SELECT 1");
         this.datasource.getPoolProperties().setTestOnBorrow(true);
         this.threadcount = 10;
         this.transferProperties();
@@ -224,7 +223,6 @@ public class CheckOutThreadTest extends DefaultTestCase {
     public void testPoolThreads10Connections10Validate() throws Exception {
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
-        this.datasource.getPoolProperties().setValidationQuery("SELECT 1");
         this.datasource.getPoolProperties().setTestOnBorrow(true);
         this.datasource.getPoolProperties().setFairQueue(false);
         this.threadcount = 10;
@@ -247,7 +245,6 @@ public class CheckOutThreadTest extends DefaultTestCase {
     public void testPoolThreads10Connections10ValidateFair() throws Exception {
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
-        this.datasource.getPoolProperties().setValidationQuery("SELECT 1");
         this.datasource.getPoolProperties().setTestOnBorrow(true);
         this.datasource.getPoolProperties().setFairQueue(true);
         this.threadcount = 10;
@@ -270,7 +267,6 @@ public class CheckOutThreadTest extends DefaultTestCase {
     public void testC3P0Threads10Connections10Validate() throws Exception {
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
-        this.datasource.getPoolProperties().setValidationQuery("SELECT 1");
         this.datasource.getPoolProperties().setTestOnBorrow(true);
         this.threadcount = 10;
         this.transferPropertiesToC3P0();
@@ -292,7 +288,6 @@ public class CheckOutThreadTest extends DefaultTestCase {
     public void testDBCPThreads20Connections10Validate() throws Exception {
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
-        this.datasource.getPoolProperties().setValidationQuery("SELECT 1");
         this.datasource.getPoolProperties().setTestOnBorrow(true);
         this.threadcount = 20;
         this.transferProperties();
@@ -314,7 +309,6 @@ public class CheckOutThreadTest extends DefaultTestCase {
     public void testPoolThreads10Connections20Validate() throws Exception {
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
-        this.datasource.getPoolProperties().setValidationQuery("SELECT 1");
         this.datasource.getPoolProperties().setTestOnBorrow(true);
         this.datasource.getPoolProperties().setFairQueue(false);
         this.threadcount = 20;
@@ -337,7 +331,6 @@ public class CheckOutThreadTest extends DefaultTestCase {
     public void testPoolThreads10Connections20ValidateFair() throws Exception {
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
-        this.datasource.getPoolProperties().setValidationQuery("SELECT 1");
         this.datasource.getPoolProperties().setTestOnBorrow(true);
         this.datasource.getPoolProperties().setFairQueue(true);
         this.threadcount = 20;
@@ -360,7 +353,6 @@ public class CheckOutThreadTest extends DefaultTestCase {
     public void testC3P0Threads10Connections20Validate() throws Exception {
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
-        this.datasource.getPoolProperties().setValidationQuery("SELECT 1");
         this.datasource.getPoolProperties().setTestOnBorrow(true);
         this.threadcount = 20;
         this.transferPropertiesToC3P0();
index 51399a3..61ba223 100644 (file)
@@ -28,10 +28,13 @@ import org.apache.tomcat.jdbc.pool.PoolProperties;
 public class DefaultProperties extends PoolProperties {
     public DefaultProperties() {
         dbProperties = new Properties();
-        url = "jdbc:mysql://localhost:3306/mysql?autoReconnect=true";
-        driverClassName = "com.mysql.jdbc.Driver";
-        password = "password";
-        username = "root";
+        
+        url = System.getProperty("url","jdbc:mysql://localhost:3306/mysql?autoReconnect=true");
+        driverClassName = System.getProperty("driverClassName","com.mysql.jdbc.Driver");
+        password = System.getProperty("password","password");
+        username = System.getProperty("username","root");
+        
+        validationQuery = System.getProperty("validationQuery","SELECT 1");
         defaultAutoCommit = true;
         defaultReadOnly = false;
         defaultTransactionIsolation = DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION;
@@ -42,7 +45,7 @@ public class DefaultProperties extends PoolProperties {
         maxIdle = initialSize;
         minIdle = initialSize;
         maxWait = 10000;
-        validationQuery = "SELECT 1";
+        
         testOnBorrow = true;
         testOnReturn = false;
         testWhileIdle = true;
index 8807e2c..cbc75a1 100644 (file)
@@ -80,10 +80,10 @@ public class TestSlowQueryReport extends DefaultTestCase {
         this.datasource.setMaxActive(1);
         this.datasource.setJdbcInterceptors(SlowQueryReport.class.getName());
         Connection con = this.datasource.getConnection();
-        String slowSql = "select 1";
+        String fastSql = this.datasource.getValidationQuery();
         for (int i=0; i<count; i++) {
             Statement st = con.createStatement();
-            ResultSet rs = st.executeQuery(slowSql);
+            ResultSet rs = st.executeQuery(fastSql);
             rs.close();
             st.close();
         }