commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From di...@apache.org
Subject cvs commit: jakarta-commons/dbcp/src/test/org/apache/commons/dbcp TestPStmtPoolingBasicDataSource.java
Date Sun, 07 Mar 2004 10:53:56 GMT
dirkv       2004/03/07 02:53:56

  Modified:    dbcp/src/test/org/apache/commons/dbcp
                        TestPStmtPoolingBasicDataSource.java
  Log:
  Testcases for issue 27492
  - prepared statements pooled accross a connection close
  
  Revision  Changes    Path
  1.4       +68 -1     jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestPStmtPoolingBasicDataSource.java
  
  Index: TestPStmtPoolingBasicDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestPStmtPoolingBasicDataSource.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestPStmtPoolingBasicDataSource.java	28 Feb 2004 11:47:52 -0000	1.3
  +++ TestPStmtPoolingBasicDataSource.java	7 Mar 2004 10:53:56 -0000	1.4
  @@ -19,6 +19,7 @@
   import java.sql.Connection;
   import java.sql.PreparedStatement;
   import java.sql.SQLException;
  +import java.sql.Statement;
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  @@ -84,5 +85,71 @@
           stmt1.close();
           PreparedStatement stmt4 = conn.prepareStatement("select 'a' from dual");
           assertNotNull(stmt4);
  +    }
  +
  +    public void testPStmtPoolingWithNoClose() throws Exception {
  +        ds.setMaxActive(1); // only one connection in pool needed
  +        ds.setMaxIdle(1);
  +        ds.setAccessToUnderlyingConnectionAllowed(true);
  +        Connection conn1 = getConnection();
  +        assertNotNull(conn1);
  +        assertEquals(1, ds.getNumActive());
  +        assertEquals(0, ds.getNumIdle());
  +        
  +        PreparedStatement stmt1 = conn1.prepareStatement("select 'a' from dual");
  +        assertNotNull(stmt1);
  +        
  +        Statement inner1 = ((DelegatingPreparedStatement) stmt1).getInnermostDelegate();
  +        assertNotNull(inner1);
  +        
  +        stmt1.close();
  +
  +        Connection conn2 = conn1;
  +        assertNotNull(conn2);
  +        assertEquals(1, ds.getNumActive());
  +        assertEquals(0, ds.getNumIdle());
  +        
  +        PreparedStatement stmt2 = conn2.prepareStatement("select 'a' from dual");
  +        assertNotNull(stmt2);
  +
  +        Statement inner2 = ((DelegatingPreparedStatement) stmt2).getInnermostDelegate();
  +        assertNotNull(inner2);
  +        
  +        assertSame(inner1, inner2);
  +    }
  +    
  +    public void testPStmtPoolingAccrossClose() throws Exception {
  +        ds.setMaxActive(1); // only one connection in pool needed
  +        ds.setMaxIdle(1);
  +        ds.setAccessToUnderlyingConnectionAllowed(true);
  +        Connection conn1 = getConnection();
  +        assertNotNull(conn1);
  +        assertEquals(1, ds.getNumActive());
  +        assertEquals(0, ds.getNumIdle());
  +        
  +        PreparedStatement stmt1 = conn1.prepareStatement("select 'a' from dual");
  +        assertNotNull(stmt1);
  +        
  +        Statement inner1 = ((DelegatingPreparedStatement) stmt1).getInnermostDelegate();
  +        assertNotNull(inner1);
  +        
  +        stmt1.close();
  +        conn1.close();
  +
  +        assertEquals(0, ds.getNumActive());
  +        assertEquals(1, ds.getNumIdle());
  +
  +        Connection conn2 = getConnection();
  +        assertNotNull(conn2);
  +        assertEquals(1, ds.getNumActive());
  +        assertEquals(0, ds.getNumIdle());
  +        
  +        PreparedStatement stmt2 = conn2.prepareStatement("select 'a' from dual");
  +        assertNotNull(stmt2);
  +
  +        Statement inner2 = ((DelegatingPreparedStatement) stmt2).getInnermostDelegate();
  +        assertNotNull(inner2);
  +        
  +        assertSame(inner1, inner2);
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message