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 TestAbandonedBasicDataSource.java
Date Sat, 01 May 2004 12:56:26 GMT
dirkv       2004/05/01 05:56:26

  Modified:    dbcp/src/test/org/apache/commons/dbcp
                        TestAbandonedBasicDataSource.java
  Log:
  Tests combining abandoned connections & network failures
  
  Revision  Changes    Path
  1.9       +50 -1     jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestAbandonedBasicDataSource.java
  
  Index: TestAbandonedBasicDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestAbandonedBasicDataSource.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestAbandonedBasicDataSource.java	28 Feb 2004 11:47:51 -0000	1.8
  +++ TestAbandonedBasicDataSource.java	1 May 2004 12:56:26 -0000	1.9
  @@ -16,7 +16,9 @@
   
   package org.apache.commons.dbcp;
   
  +import java.io.IOException;
   import java.sql.Connection;
  +import java.sql.SQLException;
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  @@ -84,5 +86,52 @@
           getConnection2();
           getConnection3();
           System.err.println("----------------------------------------");
  +    }
  +    
  +    public void testAbandonedClose() throws Exception {
  +        // force abandoned
  +        ds.setRemoveAbandonedTimeout(0);
  +        ds.setMaxActive(1);
  +
  +        Connection conn1 = getConnection();
  +        assertNotNull(conn1);
  +        assertEquals(1, ds.getNumActive());
  +        
  +        Connection conn2 = getConnection();        
  +        assertNotNull(conn2);
  +        assertEquals(1, ds.getNumActive());
  +        
  +        try { conn2.close(); } catch (SQLException ex) { }
  +        assertEquals(0, ds.getNumActive());
  +        
  +        try { conn1.close(); } catch (SQLException ex) { }
  +        assertEquals(0, ds.getNumActive());
  +    }
  +
  +    public void testAbandonedCloseWithExceptions() throws Exception {
  +        // force abandoned
  +        ds.setRemoveAbandonedTimeout(0);
  +        ds.setMaxActive(1);
  +        ds.setAccessToUnderlyingConnectionAllowed(true);
  +
  +        Connection conn1 = getConnection();
  +        assertNotNull(conn1);
  +        assertEquals(1, ds.getNumActive());
  +        
  +        Connection conn2 = getConnection();        
  +        assertNotNull(conn2);
  +        assertEquals(1, ds.getNumActive());
  +        
  +        // set an IO failure causing the isClosed mathod to fail
  +        TesterConnection tconn1 = (TesterConnection) ((DelegatingConnection)conn1).getInnermostDelegate();
  +        tconn1.setFailure(new IOException("network error"));
  +        TesterConnection tconn2 = (TesterConnection) ((DelegatingConnection)conn2).getInnermostDelegate();
  +        tconn2.setFailure(new IOException("network error"));
  +        
  +        try { conn2.close(); } catch (SQLException ex) { }
  +        assertEquals(0, ds.getNumActive());
  +        
  +        try { conn1.close(); } catch (SQLException ex) { }
  +        assertEquals(0, ds.getNumActive());
       }
   }
  
  
  

---------------------------------------------------------------------
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