You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2003/08/12 01:41:56 UTC

cvs commit: jakarta-commons/dbcp/src/test/org/apache/commons/dbcp TestBasicDataSource.java

dirkv       2003/08/11 16:41:56

  Modified:    dbcp/src/test/org/apache/commons/dbcp
                        TestBasicDataSource.java
  Log:
  Bugzilla Bug 21273: Memory-leak like behaviour in DBCP due
  to warnings chained to connections in the pool
  
  testClearWarnings
  
  Revision  Changes    Path
  1.3       +41 -4     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestBasicDataSource.java	6 Mar 2003 19:25:36 -0000	1.2
  +++ TestBasicDataSource.java	11 Aug 2003 23:41:56 -0000	1.3
  @@ -61,6 +61,7 @@
   package org.apache.commons.dbcp;
   
   import java.sql.Connection;
  +import java.sql.SQLWarning;
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  @@ -100,4 +101,40 @@
       public void tearDown() throws Exception {
           ds = null;
       }
  +    
  +    public void testClearWarnings() throws Exception {
  +        Connection[] c = new Connection[getMaxActive()];
  +        for (int i = 0; i < c.length; i++) {
  +            c[i] = getConnection();
  +            assertTrue(c[i] != null);
  +            if (c[i] instanceof DelegatingConnection) {
  +                Connection conn = ((DelegatingConnection) c[i]).getInnermostDelegate();
  +                if (conn instanceof TesterConnection){
  +                    ((TesterConnection) conn).setWarnings(new SQLWarning("warn1"));
  +                }
  +            }
  +        }
  +
  +        for (int i = 0; i < c.length; i++) {
  +            assertNotNull(c[i].getWarnings());
  +        }
  +
  +        for (int i = 0; i < c.length; i++) {
  +            c[i].close();
  +        }
  +        
  +        for (int i = 0; i < c.length; i++) {
  +            c[i] = getConnection();
  +        }        
  +
  +        for (int i = 0; i < c.length; i++) {
  +            // warnings should have been cleared by putting the connection back in the pool
  +            assertNull(c[i].getWarnings());
  +        }
  +
  +        for (int i = 0; i < c.length; i++) {
  +            c[i].close();
  +        }
  +    }
  +
   }