https://issues.apache.org/bugzilla/show_bug.cgi?id=50805
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 22 Feb 2011 22:42:44 +0000 (22:42 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 22 Feb 2011 22:42:44 +0000 (22:42 +0000)
Make sure we only call borrowConnection once per connection per checkout

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1073531 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/Bug50805.java [new file with mode: 0644]

index 3bfc242..1583bf2 100644 (file)
@@ -142,6 +142,7 @@ public class ConnectionPool {
     public Future<Connection> getConnectionAsync() throws SQLException {
         PooledConnection pc = this.borrowConnection(0, null, null);
         if (pc!=null) {
+            
             return new ConnectionFuture(pc);
         } 
         //we can only retrieve a future if the underlying queue supports it.
@@ -1054,8 +1055,10 @@ public class ConnectionPool {
             this.pcFuture = pcf;
         }
         
-        public ConnectionFuture(PooledConnection pc) {
+        public ConnectionFuture(PooledConnection pc) throws SQLException {
             this.pc = pc;
+            result = ConnectionPool.this.setupConnection(pc);
+            configured.set(true);
         }
         /**
          * {@inheritDoc}
diff --git a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/Bug50805.java b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/Bug50805.java
new file mode 100644 (file)
index 0000000..3605e1e
--- /dev/null
@@ -0,0 +1,38 @@
+package org.apache.tomcat.jdbc.test;
+
+import java.sql.Connection;
+import java.util.concurrent.Future;
+
+public class Bug50805 extends DefaultTestCase {
+    public Bug50805(String name) {
+        super(name);
+    }
+    
+    public void test50805() throws Exception {
+        init();
+        this.datasource.setInitialSize(0);
+        this.datasource.setMaxActive(10);
+        this.datasource.setMinIdle(1);
+        
+        assertEquals("Current size should be 0.", 0, this.datasource.getSize());
+        
+        this.datasource.getConnection().close();
+        
+        assertEquals("Current size should be 1.", 1, this.datasource.getSize());
+        assertEquals("Idle size should be 1.", 1, this.datasource.getIdle());
+        assertEquals("Busy size should be 0.", 0, this.datasource.getActive());
+        
+        Future<Connection> fc = this.datasource.getConnectionAsync();
+        
+        Connection con = fc.get();
+        
+        assertEquals("Current size should be 1.", 1, this.datasource.getSize());
+        assertEquals("Idle size should be 0.", 0, this.datasource.getIdle());
+        assertEquals("Busy size should be 1.", 1, this.datasource.getActive());
+        
+        con.close();
+        assertEquals("Current size should be 1.", 1, this.datasource.getSize());
+        assertEquals("Idle size should be 1.", 1, this.datasource.getIdle());
+        assertEquals("Busy size should be 0.", 0, this.datasource.getActive());
+    }
+}