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 TestBasicDataSource.java
Date Tue, 26 Aug 2003 14:20:15 GMT
dirkv       2003/08/26 07:20:15

  Modified:    dbcp/src/test/org/apache/commons/dbcp
                        TestBasicDataSource.java
  Log:
  Bugzilla Bug 18012: BasicDataSource doesn't include PreparedStmt Pooling
  
  junit test for the new feature
  
  Revision  Changes    Path
  1.7       +42 -3     jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestBasicDataSource.java
  
  Index: TestBasicDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestBasicDataSource.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestBasicDataSource.java	25 Aug 2003 16:18:51 -0000	1.6
  +++ TestBasicDataSource.java	26 Aug 2003 14:20:15 -0000	1.7
  @@ -62,6 +62,8 @@
   package org.apache.commons.dbcp;
   
   import java.sql.Connection;
  +import java.sql.PreparedStatement;
  +import java.sql.SQLException;
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  @@ -121,4 +123,41 @@
           conn3.close();
       }
   
  +    public void testPreparedStatementPooling() throws Exception {
  +        ds.setPoolPreparedStatements(true);
  +        ds.setMaxOpenPreparedStatements(2);
  +        
  +        Connection conn = getConnection();
  +        assertNotNull(conn);
  +        
  +        PreparedStatement stmt1 = conn.prepareStatement("select 'a' from dual");
  +        assertNotNull(stmt1);
  +        
  +        PreparedStatement stmt2 = conn.prepareStatement("select 'b' from dual");
  +        assertNotNull(stmt2);
  +        
  +        assertTrue(stmt1 != stmt2);
  +        
  +        // go over the maxOpen limit
  +        PreparedStatement stmt3 = null;
  +		try {
  +			stmt3 = conn.prepareStatement("select 'c' from dual");
  +            fail("expected SQLException");
  +		} 
  +        catch (SQLException e) {}
  +        
  +        // make idle
  +        stmt2.close();
  +
  +        // test cleanup the 'b' statement
  +        stmt3 = conn.prepareStatement("select 'c' from dual");
  +        assertNotNull(stmt3);
  +        assertTrue(stmt3 != stmt1);
  +        assertTrue(stmt3 != stmt2);
  +        
  +        // normal reuse of statement
  +        stmt1.close();
  +        PreparedStatement stmt4 = conn.prepareStatement("select 'a' from dual");
  +        assertNotNull(stmt4);
  +    }
   }
  
  
  

Mime
View raw message