Added test case to test two concurrent datasources, fixed the flag to turn on the...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 10 Nov 2008 17:09:40 +0000 (17:09 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 10 Nov 2008 17:09:40 +0000 (17:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@712701 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/.classpath
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java
modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TwoDataSources.java [new file with mode: 0644]

index 93157c3..9930b5a 100644 (file)
@@ -3,9 +3,9 @@
        <classpathentry kind="src" path="java"/>
        <classpathentry kind="src" path="test"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-       <classpathentry kind="var" path="TOMCAT_LIBS_BASE/tomcat6-deps/dbcp/tomcat-dbcp.jar"/>
-       <classpathentry kind="var" path="TOMCAT_LIBS_BASE"/>
        <classpathentry combineaccessrules="false" kind="src" path="/tomcat-trunk"/>
        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
+       <classpathentry kind="var" path="TOMCAT_LIBS_BASE/tomcat6-deps/dbcp/tomcat-dbcp.jar"/>
+       <classpathentry kind="lib" path="mysql-connector-java-5.1.6-bin.jar"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index 1ddbc40..3a6e2a8 100644 (file)
@@ -391,7 +391,7 @@ public class PoolProperties {
     public boolean isPoolSweeperEnabled() {
         boolean result = getTimeBetweenEvictionRunsMillis()>0;
         result = result && (isRemoveAbandoned() && getRemoveAbandonedTimeout()>0);
-        result = result && (isTestWhileIdle() && getValidationQuery()!=null);
+        result = result || (isTestWhileIdle() && getValidationQuery()!=null);
         return result;
     }
 }
index 5de13e0..b7377b6 100644 (file)
@@ -39,7 +39,8 @@ public class DefaultTestCase extends TestCase {
         super(name);
     }
 
-    protected void init() throws Exception {
+    public DataSourceProxy createDefaultDataSource() {
+        DataSourceProxy datasource = null;
         PoolProperties p = new DefaultProperties();
         p.setJmxEnabled(false);
         p.setTestWhileIdle(false);
@@ -57,6 +58,11 @@ public class DefaultTestCase extends TestCase {
         p.setRemoveAbandoned(false);
         datasource = new org.apache.tomcat.jdbc.pool.DataSourceProxy();
         datasource.setPoolProperties(p);
+        return datasource;
+    }
+    
+    protected void init() throws Exception {
+        this.datasource = createDefaultDataSource();
     }
 
     protected void transferProperties() {
@@ -92,6 +98,7 @@ public class DefaultTestCase extends TestCase {
 
 
     protected void tearDown() throws Exception {
+        try {datasource.close();}catch(Exception ignore){}
         datasource = null;
         tDatasource = null;
         System.gc();
diff --git a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TwoDataSources.java b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TwoDataSources.java
new file mode 100644 (file)
index 0000000..37a6f38
--- /dev/null
@@ -0,0 +1,53 @@
+package org.apache.tomcat.jdbc.test;
+
+import java.sql.Connection;
+
+import org.apache.tomcat.jdbc.pool.DataSourceProxy;
+
+public class TwoDataSources extends DefaultTestCase {
+
+    public TwoDataSources(String name) {
+        super(name);
+    }
+    
+    public void testTwoDataSources() throws Exception {
+        DataSourceProxy d1 = this.createDefaultDataSource();
+        DataSourceProxy d2 = this.createDefaultDataSource();
+        d1.setRemoveAbandoned(true);
+        d1.setRemoveAbandonedTimeout(10);
+        d1.setTimeBetweenEvictionRunsMillis(1000);
+        d2.setRemoveAbandoned(false);
+        Connection c1 = d1.getConnection();
+        Connection c2 = d2.getConnection();
+        Thread.sleep(15000);
+        try {
+            c1.createStatement();
+            this.assertTrue("Connection should have been abandoned.",false);
+        }catch (Exception x) {
+            this.assertTrue("This is correct, c1 is abandoned",true);
+        }
+
+        try {
+            c2.createStatement();
+            this.assertTrue("Connection should not have been abandoned.",true);
+        }catch (Exception x) {
+            this.assertTrue("Connection c2 should be working",false);
+        }
+        try {
+            c1.close();
+            this.assertTrue("Connection should have been closed.",false);
+        }catch (Exception x) {
+            this.assertTrue("This is correct, c1 is closed",true);
+        }
+        try {
+            c2.close();
+            this.assertTrue("Connection c2 should not have been closed.",true);
+        }catch (Exception x) {
+            this.assertTrue("Connection c2 should be working",false);
+        }
+        
+
+        
+    }
+
+}