commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwaldh...@apache.org
Subject cvs commit: jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/jdbc2pool TestJdbc2PoolDataSource.java
Date Fri, 08 Nov 2002 18:51:07 GMT
rwaldhoff    2002/11/08 10:51:07

  Modified:    dbcp     build.xml maven.xml
               dbcp/doc test.jocl
               dbcp/src/java/org/apache/commons/dbcp/cpdsadapter
                        ConnectionImpl.java
                        PoolablePreparedStatementStub.java
                        PooledConnectionImpl.java
               dbcp/src/test/org/apache/commons/dbcp TestAll.java
                        TestJOCLed.java TestManual.java
                        TesterStatement.java
               dbcp/src/test/org/apache/commons/dbcp/jdbc2pool
                        TestJdbc2PoolDataSource.java
  Added:       dbcp/src/test testpool.jocl
               dbcp/src/test/org/apache/commons/dbcp
                        TestConnectionPool.java
  Log:
  refactor/cleanup test suite a bit
  apply generic tests to more configurations
  fix a couple of bugs that revealed
  
  Revision  Changes    Path
  1.16      +6 -1      jakarta-commons/dbcp/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/build.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- build.xml	5 Sep 2002 23:38:49 -0000	1.15
  +++ build.xml	8 Nov 2002 18:51:06 -0000	1.16
  @@ -239,6 +239,11 @@
                debug="true"
                deprecation="true"
                optimize="true"/>
  +      <copy todir="${dest.classes}" filtering="no">
  +        <fileset dir="${source.src.test}" defaultexcludes="no">
  +          <include name="testpool.jocl"/>
  +        </fileset>
  +      </copy>
      </target>
   
      <!-- ######################################################### -->
  
  
  
  1.2       +9 -2      jakarta-commons/dbcp/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/maven.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- maven.xml	23 Jul 2002 16:43:14 -0000	1.1
  +++ maven.xml	8 Nov 2002 18:51:06 -0000	1.2
  @@ -1,4 +1,11 @@
  -<project default="java:jar"
  -  xmlns:j="jelly:core">
  +<project default="java:jar" xmlns:j="jelly:core">
  +
  +    <postGoal name="test:compile">
  +      <copy todir="target/test-classes">
  +        <fileset dir="src/test">
  +          <include name="testpool.jocl"/>
  +        </fileset>
  +      </copy>
  +    </postGoal>
   
   </project>
  
  
  
  1.2       +2 -2      jakarta-commons/dbcp/doc/test.jocl
  
  Index: test.jocl
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/doc/test.jocl,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- test.jocl	14 Apr 2001 17:16:57 -0000	1.1
  +++ test.jocl	8 Nov 2002 18:51:07 -0000	1.2
  @@ -19,10 +19,10 @@
      </object>
      <object class="org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory">
         <object class="org.apache.commons.pool.KeyedPoolableObjectFactory" null="true"/>
  -      <int value="5"/>
  +      <int value="10"/>
         <byte value="1"/>
         <long value="2000"/>
  -      <int value="5"/>
  +      <int value="10"/>
         <boolean value="true"/>
         <boolean value="true"/>
         <long value="10000"/>
  
  
  
  1.2       +3 -2      jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/cpdsadapter/ConnectionImpl.java
  
  Index: ConnectionImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/cpdsadapter/ConnectionImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConnectionImpl.java	5 Aug 2002 06:42:01 -0000	1.1
  +++ ConnectionImpl.java	8 Nov 2002 18:51:07 -0000	1.2
  @@ -3,7 +3,7 @@
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -170,6 +170,7 @@
       public void close()
           throws SQLException
       {
  +        assertOpen();
           isClosed = true;
           pooledConnection.notifyListeners();
       }
  
  
  
  1.2       +8 -8      jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/cpdsadapter/PoolablePreparedStatementStub.java
  
  Index: PoolablePreparedStatementStub.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/cpdsadapter/PoolablePreparedStatementStub.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PoolablePreparedStatementStub.java	5 Aug 2002 06:42:01 -0000	1.1
  +++ PoolablePreparedStatementStub.java	8 Nov 2002 18:51:07 -0000	1.2
  @@ -1,5 +1,5 @@
   /*
  - * $Header$
  + * $Id$
    * $Revision$
    * $Date$
    *
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -80,10 +80,10 @@
   
       /**
        * Constructor
  -     * @param stmt my underlying {*link PreparedStatement}
  -     * @param key my key" as used by {*link KeyedObjectPool}
  -     * @param pool the {*link KeyedObjectPool} from which I was obtained.
  -     * @param conn the {*link Connection} from which I was created
  +     * @param stmt my underlying {@link PreparedStatement}
  +     * @param key my key" as used by {@link KeyedObjectPool}
  +     * @param pool the {@link KeyedObjectPool} from which I was obtained.
  +     * @param conn the {@link Connection} from which I was created
        */
       public PoolablePreparedStatementStub(PreparedStatement stmt, Object key, 
           KeyedObjectPool pool, Connection conn) {
  
  
  
  1.2       +2 -1      jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/cpdsadapter/PooledConnectionImpl.java
  
  Index: PooledConnectionImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/cpdsadapter/PooledConnectionImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PooledConnectionImpl.java	5 Aug 2002 06:42:01 -0000	1.1
  +++ PooledConnectionImpl.java	8 Nov 2002 18:51:07 -0000	1.2
  @@ -146,6 +146,7 @@
       public void close()
           throws SQLException
       {        
  +        assertOpen();
           isClosed = true;
           if (pstmtPool != null) 
           {
  
  
  
  1.1                  jakarta-commons/dbcp/src/test/testpool.jocl
  
  Index: testpool.jocl
  ===================================================================
  <object class="org.apache.commons.dbcp.PoolableConnectionFactory" xmlns="http://apache.org/xml/xmlns/jakarta/commons/jocl">
     <object class="org.apache.commons.dbcp.DriverConnectionFactory">
        <object class="org.apache.commons.dbcp.TesterDriver"/>
        <string value="jdbc:apache:commons:testdriver"/>
        <object class="java.util.Properties" null="true"/>
     </object>
     <object class="org.apache.commons.pool.impl.GenericObjectPool">
        <object class="org.apache.commons.pool.PoolableObjectFactory" null="true"/>
        <int value="10"/>
        <byte value="1"/>
        <long value="2000"/>
        <int value="10"/>
        <boolean value="true"/>
        <boolean value="true"/>
        <long value="10000"/>
        <int value="5"/>
        <long value="5000"/>
        <boolean value="true"/>
     </object>
     <object class="org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory">
        <object class="org.apache.commons.pool.KeyedPoolableObjectFactory" null="true"/>
        <int value="5"/>
        <byte value="1"/>
        <long value="2000"/>
        <int value="5"/>
        <boolean value="true"/>
        <boolean value="true"/>
        <long value="10000"/>
        <int value="5"/>
        <long value="5000"/>
        <boolean value="true"/>
     </object>
     <string value="SELECT COUNT(*) FROM DUAL"/>
     <boolean value="false"/>
     <boolean value="true"/>
  </object>
  
  
  
  1.4       +5 -4      jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestAll.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestAll.java	31 Oct 2002 21:41:50 -0000	1.3
  +++ TestAll.java	8 Nov 2002 18:51:07 -0000	1.4
  @@ -76,6 +76,7 @@
       public static Test suite() {
           TestSuite suite = new TestSuite();
           suite.addTest(TestManual.suite());
  +        suite.addTest(TestJOCLed.suite());
           suite.addTest(TestDelegatingStatement.suite());
           suite.addTest(TestDelegatingPreparedStatement.suite());
           suite.addTest(TestJdbc2PoolDataSource.suite());
  
  
  
  1.3       +17 -179   jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestJOCLed.java
  
  Index: TestJOCLed.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestJOCLed.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestJOCLed.java	16 Mar 2002 13:29:49 -0000	1.2
  +++ TestJOCLed.java	8 Nov 2002 18:51:07 -0000	1.3
  @@ -1,13 +1,12 @@
   /*
  - * $Header$
  + * $Id$
    * $Revision$
    * $Date$
  - *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -61,23 +60,17 @@
   
   package org.apache.commons.dbcp;
   
  -import junit.framework.*;
  -import java.sql.*;
  -import org.apache.commons.pool.*;
  -import org.apache.commons.pool.impl.*;
  -
  -// this suite requires a JOCL configuration
  -// file named testpool.jocl to be in your classpath
  -// see the doc directory for an example
  +import java.sql.Connection;
  +import java.sql.DriverManager;
   
  -// note that depending upon the configuration of the testpool,
  -// testThreaded1 might fail
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
   
   /**
    * @author Rodney Waldhoff
  - * @version $Id$
  + * @version $Revision$ $Date$
    */
  -public class TestJOCLed extends TestCase {
  +public class TestJOCLed extends TestConnectionPool {
       public TestJOCLed(String testName) {
           super(testName);
       }
  @@ -86,173 +79,18 @@
           return new TestSuite(TestJOCLed.class);
       }
   
  -    public static void main(String args[]) {
  -        String[] testCaseName = { TestJOCLed.class.getName() };
  -        junit.textui.TestRunner.main(testCaseName);
  +    protected Connection getConnection() throws Exception {
  +        return DriverManager.getConnection("jdbc:apache:commons:dbcp:/testpool");
       }
   
  +    private PoolingDriver driver = null;
  +    
       public void setUp() throws Exception {
  -        Class.forName("org.apache.commons.dbcp.PoolingDriver");
  -    }
  -
  -    public void testSimple() throws Exception {
  -        Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:/testpool");
  -        assertTrue(null != conn);
  -        PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -        assertTrue(null != stmt);
  -        ResultSet rset = stmt.executeQuery();
  -        assertTrue(null != rset);
  -        assertTrue(rset.next());
  -        rset.close();
  -        stmt.close();
  -        conn.close();
  -    }
  -
  -    public void testSimple2() throws Exception {
  -        Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:/testpool");
  -        assertTrue(null != conn);
  -        {
  -            PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -            assertTrue(null != stmt);
  -            ResultSet rset = stmt.executeQuery();
  -            assertTrue(null != rset);
  -            assertTrue(rset.next());
  -            rset.close();
  -            stmt.close();
  -        }
  -        {
  -            PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -            assertTrue(null != stmt);
  -            ResultSet rset = stmt.executeQuery();
  -            assertTrue(null != rset);
  -            assertTrue(rset.next());
  -            rset.close();
  -            stmt.close();
  -        }
  -        conn.close();
  -        try {
  -            conn.createStatement();
  -            fail("Can't use closed connections");
  -        } catch(SQLException e) {
  -            ; // expected
  -        }
  -
  -        conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:/testpool");
  -        assertTrue(null != conn);
  -        {
  -            PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -            assertTrue(null != stmt);
  -            ResultSet rset = stmt.executeQuery();
  -            assertTrue(null != rset);
  -            assertTrue(rset.next());
  -            rset.close();
  -            stmt.close();
  -        }
  -        {
  -            PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -            assertTrue(null != stmt);
  -            ResultSet rset = stmt.executeQuery();
  -            assertTrue(null != rset);
  -            assertTrue(rset.next());
  -            rset.close();
  -            stmt.close();
  -        }
  -        conn.close();
  -        conn = null;
  -    }
  -
  -    public void testPooling() throws Exception {
  -        Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:/testpool");
  -        assertTrue(conn != null);
  -        Connection conn2 = DriverManager.getConnection("jdbc:apache:commons:dbcp:/testpool");
  -        assertTrue(conn2 != null);
  -        assertTrue(conn != conn2);
  -        conn2.close();
  -        conn.close();
  -        conn2 = DriverManager.getConnection("jdbc:apache:commons:dbcp:/testpool");
  -        assertSame(conn,conn2);
  -    }
  -
  -    public void testThreaded1() {
  -        TestThread[] threads = new TestThread[20];
  -        for(int i=0;i<20;i++) {
  -            threads[i] = new TestThread(100,50);
  -            Thread t = new Thread(threads[i]);
  -            t.start();
  -        }
  -        for(int i=0;i<20;i++) {
  -            while(!(threads[i]).complete()) {
  -                try {
  -                    Thread.currentThread().sleep(500L);
  -                } catch(Exception e) {
  -                    // ignored
  -                }
  -            }
  -            if(threads[i].failed()) {
  -                fail();
  -            }
  -        }
  +        driver = new PoolingDriver();
       }
   
  -    class TestThread implements Runnable {
  -        java.util.Random _random = new java.util.Random();
  -        boolean _complete = false;
  -        boolean _failed = false;
  -        int _iter = 100;
  -        int _delay = 50;
  -
  -        public TestThread() {
  -        }
  -
  -        public TestThread(int iter) {
  -            _iter = iter;
  -        }
  -
  -        public TestThread(int iter, int delay) {
  -            _iter = iter;
  -            _delay = delay;
  -        }
  -
  -        public boolean complete() {
  -            return _complete;
  -        }
  -
  -        public boolean failed() {
  -            return _failed;
  -        }
  -
  -        public void run() {
  -            for(int i=0;i<_iter;i++) {
  -                try {
  -                    Thread.currentThread().sleep((long)_random.nextInt(_delay));
  -                } catch(Exception e) {
  -                    // ignored
  -                }
  -                Connection conn = null;
  -                PreparedStatement stmt = null;
  -                ResultSet rset = null;
  -                try {
  -                    conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:/testpool");
  -                    stmt = conn.prepareStatement("select 'literal', SYSDATE from dual");
  -                    rset = stmt.executeQuery();
  -                    try {
  -                        Thread.currentThread().sleep((long)_random.nextInt(_delay));
  -                    } catch(Exception e) {
  -                        // ignored
  -                    }
  -                } catch(Exception e) {
  -                    e.printStackTrace();
  -                    _failed = true;
  -                    _complete = true;
  -                    break;
  -                } finally {
  -                    try { rset.close(); } catch(Exception e) { }
  -                    try { stmt.close(); } catch(Exception e) { }
  -                    try { conn.close(); } catch(Exception e) { }
  -                }
  -            }
  -            _complete = true;
  -        }
  +    public void tearDown() throws Exception {
  +        DriverManager.deregisterDriver(driver);
       }
   
   }
  
  
  
  1.12      +27 -166   jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestManual.java
  
  Index: TestManual.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestManual.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TestManual.java	7 Nov 2002 21:06:57 -0000	1.11
  +++ TestManual.java	8 Nov 2002 18:51:07 -0000	1.12
  @@ -1,13 +1,12 @@
   /*
  - * $Header$
  + * $Id$
    * $Revision$
    * $Date$
  - *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -61,19 +60,25 @@
   
   package org.apache.commons.dbcp;
   
  -import junit.framework.*;
  -import java.sql.*;
  -import org.apache.commons.pool.*;
  -import org.apache.commons.pool.impl.*;
  +import java.sql.Connection;
  +import java.sql.DriverManager;
  +
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
  +
  +import org.apache.commons.pool.ObjectPool;
  +import org.apache.commons.pool.impl.GenericKeyedObjectPool;
  +import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory;
  +import org.apache.commons.pool.impl.GenericObjectPool;
   
   /**
  - * 
  + * Tests for a "manually configured", {@link GenericObjectPool}
  + * based {@link PoolingDriver}.
    * @author Rodney Waldhoff
    * @author Sean C. Sullivan
  - * 
  - * @version $Id$
  + * @version $Revision$ $Date$
    */
  -public class TestManual extends TestCase {
  +public class TestManual extends TestConnectionPool {
       public TestManual(String testName) {
           super(testName);
       }
  @@ -82,171 +87,27 @@
           return new TestSuite(TestManual.class);
       }
   
  -    public static void main(String args[]) {
  -        String[] testCaseName = { TestManual.class.getName() };
  -        junit.textui.TestRunner.main(testCaseName);
  +    protected Connection getConnection() throws Exception {
  +        return DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
       }
   
  +    private PoolingDriver driver = null;
  +    
       public void setUp() throws Exception {
  -        GenericObjectPool pool = new GenericObjectPool(null, 10, GenericObjectPool.WHEN_EXHAUSTED_BLOCK, 2000L, 10, true, true, 10000L, 5, 5000L, true);
  +        super.setUp();
  +        GenericObjectPool pool = new GenericObjectPool(null, getMaxActive(), GenericObjectPool.WHEN_EXHAUSTED_BLOCK, getMaxWait(), 10, true, true, 10000L, 5, 5000L, true);
           DriverConnectionFactory cf = new DriverConnectionFactory(new TesterDriver(),"jdbc:apache:commons:testdriver",null);
           GenericKeyedObjectPoolFactory opf = new GenericKeyedObjectPoolFactory(null, 10, GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK, 2000L, 10, true, true, 10000L, 5, 5000L, true);
           PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, pool, opf, "SELECT COUNT(*) FROM DUAL", false, true);
  -        PoolingDriver driver = new PoolingDriver();
  +        driver = new PoolingDriver();
           driver.registerPool("test",pool);
           DriverManager.registerDriver(driver);
       }
   
  -    public void testIsClosed() throws Exception {
  -        for(int i=0;i<10;i++) {
  -            Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
  -            assertTrue(null != conn);
  -            assertTrue(!conn.isClosed());
  -            PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -            assertTrue(null != stmt);
  -            ResultSet rset = stmt.executeQuery();
  -            assertTrue(null != rset);
  -            assertTrue(rset.next());
  -            rset.close();
  -            stmt.close();
  -            conn.close();
  -            assertTrue(conn.isClosed());
  -        }
  -    }
  -
  -    public void testCantCloseConnectionTwice() throws Exception {
  -        for(int i=0;i<2;i++) { // loop to show we *can* close again once we've borrowed it from the pool again
  -            Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
  -            assertTrue(null != conn);
  -            assertTrue(!conn.isClosed());
  -            conn.close();
  -            assertTrue(conn.isClosed());
  -            try {
  -                conn.close();
  -                fail("Expected SQLException on second attempt to close");
  -            } catch(SQLException e) {
  -                // expected
  -            }
  -            assertTrue(conn.isClosed());
  -        }
  -    }
  -
  -    public void testCantCloseStatementTwice() throws Exception {
  -        Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
  -        assertTrue(null != conn);
  -        assertTrue(!conn.isClosed());
  -        for(int i=0;i<2;i++) { // loop to show we *can* close again once we've borrowed it from the pool again
  -            PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -            assertTrue(null != stmt);
  -            stmt.close();
  -            try {
  -                stmt.close();
  -                fail("Expected SQLException on second attempt to close");
  -            } catch(SQLException e) {
  -                // expected
  -            }
  -        }
  -        conn.close();
  +    public void tearDown() throws Exception {
  +        DriverManager.deregisterDriver(driver);
       }
   
  -    public void testSimple() throws Exception {
  -        Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
  -        assertTrue(null != conn);
  -        PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -        assertTrue(null != stmt);
  -        ResultSet rset = stmt.executeQuery();
  -        assertTrue(null != rset);
  -        assertTrue(rset.next());
  -        rset.close();
  -        stmt.close();
  -        conn.close();
  -    }
  -
  -    public void testSimple2() throws Exception {
  -        Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
  -        assertTrue(null != conn);
  -        {
  -            PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -            assertTrue(null != stmt);
  -            ResultSet rset = stmt.executeQuery();
  -            assertTrue(null != rset);
  -            assertTrue(rset.next());
  -            rset.close();
  -            stmt.close();
  -        }
  -        {
  -            PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -            assertTrue(null != stmt);
  -            ResultSet rset = stmt.executeQuery();
  -            assertTrue(null != rset);
  -            assertTrue(rset.next());
  -            rset.close();
  -            stmt.close();
  -        }
  -        conn.close();
  -        try {
  -            conn.createStatement();
  -            fail("Can't use closed connections");
  -        } catch(SQLException e) {
  -            ; // expected
  -        }
  -
  -        conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
  -        assertTrue(null != conn);
  -        {
  -            PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -            assertTrue(null != stmt);
  -            ResultSet rset = stmt.executeQuery();
  -            assertTrue(null != rset);
  -            assertTrue(rset.next());
  -            rset.close();
  -            stmt.close();
  -        }
  -        {
  -            PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -            assertTrue(null != stmt);
  -            ResultSet rset = stmt.executeQuery();
  -            assertTrue(null != rset);
  -            assertTrue(rset.next());
  -            rset.close();
  -            stmt.close();
  -        }
  -        conn.close();
  -        conn = null;
  -    }
  -
  -    public void testPooling() throws Exception {
  -        Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
  -        assertTrue(conn != null);
  -        Connection conn2 = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
  -        assertTrue(conn2 != null);
  -        assertTrue(conn != conn2);
  -        conn2.close();
  -        conn.close();
  -        Connection conn3 = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
  -        assertTrue( conn3 == conn || conn3 == conn2 );
  -    }
  -    
  -    public void testAutoCommitBehavior() throws Exception {
  -        
  -        final String strDriverUrl = "jdbc:apache:commons:dbcp:test";
  -        Connection conn = DriverManager.getConnection(strDriverUrl);
  -        assertTrue(conn != null);
  -        assertTrue(conn.getAutoCommit());
  -        conn.setAutoCommit(false);
  -        conn.close();
  -        
  -        Connection conn2 = DriverManager.getConnection(strDriverUrl);
  -        assertTrue( conn2.getAutoCommit() );
  -        
  -        Connection conn3 = DriverManager.getConnection(strDriverUrl);
  -        assertTrue( conn3.getAutoCommit() );
  -
  -        conn2.close();
  -        
  -        conn3.close();
  -    }
  -    
       /** @see http://issues.apache.org/bugzilla/show_bug.cgi?id=12400 */
       public void testReportedBug12400() throws Exception {
           ObjectPool connectionPool = new GenericObjectPool(
  
  
  
  1.4       +5 -4      jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TesterStatement.java
  
  Index: TesterStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TesterStatement.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TesterStatement.java	31 Oct 2002 21:41:50 -0000	1.3
  +++ TesterStatement.java	8 Nov 2002 18:51:07 -0000	1.4
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -100,6 +100,7 @@
       }
   
       public void close() throws SQLException {
  +        checkOpen();
           _open = false;
       }
   
  
  
  
  1.1                  jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestConnectionPool.java
  
  Index: TestConnectionPool.java
  ===================================================================
  /*
   * $Id: TestConnectionPool.java,v 1.1 2002/11/08 18:51:07 rwaldhoff Exp $
   * $Revision: 1.1 $
   * $Date: 2002/11/08 18:51:07 $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.dbcp;
  
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  
  import junit.framework.TestCase;
  
  // XXX FIX ME XXX
  // this class still needs some cleanup, but at least
  // this consolidates most of the relevant test code
  // in a fairly re-usable fashion
  // XXX FIX ME XXX
  
  /**
   * Base test suite for DBCP pools.
   * @author Rodney Waldhoff
   * @author Sean C. Sullivan
   * @author John McNally
   * 
   * @version $Id: TestConnectionPool.java,v 1.1 2002/11/08 18:51:07 rwaldhoff Exp $
   */
  public abstract class TestConnectionPool extends TestCase {
      public TestConnectionPool(String testName) {
          super(testName);
      }
  
      public void setUp() throws Exception {
          super.setUp();
      }
  
      public void tearDown() throws Exception {
          super.tearDown();
      }
  
      protected abstract Connection getConnection() throws Exception;
      
      protected int getMaxActive() {
          return 10;
      }
      
      protected long getMaxWait() {
          return 50L;
      }
          
      public void testIsClosed() throws Exception {
          for(int i=0;i<getMaxActive();i++) {
              Connection conn = getConnection();
              assertTrue(null != conn);
              assertTrue(!conn.isClosed());
              PreparedStatement stmt = conn.prepareStatement("select * from dual");
              assertTrue(null != stmt);
              ResultSet rset = stmt.executeQuery();
              assertTrue(null != rset);
              assertTrue(rset.next());
              rset.close();
              stmt.close();
              conn.close();
              assertTrue(conn.isClosed());
          }
      }
  
      public void testCantCloseConnectionTwice() throws Exception {
          for(int i=0;i<getMaxActive();i++) { // loop to show we *can* close again once we've borrowed it from the pool again
              Connection conn = getConnection();
              assertTrue(null != conn);
              assertTrue(!conn.isClosed());
              conn.close();
              assertTrue(conn.isClosed());
              try {
                  conn.close();
                  fail("Expected SQLException on second attempt to close (" + conn.getClass().getName() + ")");
              } catch(SQLException e) {
                  // expected
              }
              assertTrue(conn.isClosed());
          }
      }
  
      public void testCantCloseStatementTwice() throws Exception {
          Connection conn = getConnection();
          assertTrue(null != conn);
          assertTrue(!conn.isClosed());
          for(int i=0;i<2;i++) { // loop to show we *can* close again once we've borrowed it from the pool again
              PreparedStatement stmt = conn.prepareStatement("select * from dual");
              assertTrue(null != stmt);
              stmt.close();
              try {
                  stmt.close();
                  fail("Expected SQLException on second attempt to close (" + stmt.getClass().getName() + ")");
              } catch(SQLException e) {
                  // expected
              }
          }
          conn.close();
      }
  
      public void testSimple() throws Exception {
          Connection conn = getConnection();
          assertTrue(null != conn);
          PreparedStatement stmt = conn.prepareStatement("select * from dual");
          assertTrue(null != stmt);
          ResultSet rset = stmt.executeQuery();
          assertTrue(null != rset);
          assertTrue(rset.next());
          rset.close();
          stmt.close();
          conn.close();
      }
  
      public void testSimple2() throws Exception {
          Connection conn = getConnection();
          assertTrue(null != conn);
          {
              PreparedStatement stmt = conn.prepareStatement("select * from dual");
              assertTrue(null != stmt);
              ResultSet rset = stmt.executeQuery();
              assertTrue(null != rset);
              assertTrue(rset.next());
              rset.close();
              stmt.close();
          }
          {
              PreparedStatement stmt = conn.prepareStatement("select * from dual");
              assertTrue(null != stmt);
              ResultSet rset = stmt.executeQuery();
              assertTrue(null != rset);
              assertTrue(rset.next());
              rset.close();
              stmt.close();
          }
          conn.close();
          try {
              conn.createStatement();
              fail("Can't use closed connections");
          } catch(SQLException e) {
              ; // expected
          }
  
          conn = getConnection();
          assertTrue(null != conn);
          {
              PreparedStatement stmt = conn.prepareStatement("select * from dual");
              assertTrue(null != stmt);
              ResultSet rset = stmt.executeQuery();
              assertTrue(null != rset);
              assertTrue(rset.next());
              rset.close();
              stmt.close();
          }
          {
              PreparedStatement stmt = conn.prepareStatement("select * from dual");
              assertTrue(null != stmt);
              ResultSet rset = stmt.executeQuery();
              assertTrue(null != rset);
              assertTrue(rset.next());
              rset.close();
              stmt.close();
          }
          conn.close();
          conn = null;
      }
  
      public void testPooling() throws Exception {
          Connection conn = getConnection();
          Connection underconn = null;
          if(conn instanceof DelegatingConnection) {
              underconn = ((DelegatingConnection)conn).getInnermostDelegate();
          } else {
              return; // skip this test
          }
          assertTrue(underconn != null);
          Connection conn2 = getConnection();
          Connection underconn2 = null;
          if(conn2 instanceof DelegatingConnection) {
              underconn2 = ((DelegatingConnection)conn2).getInnermostDelegate();
          } else {
              return; // skip this test
          }
          assertTrue(underconn2 != null);
          assertTrue(underconn != underconn2);
          conn2.close();
          conn.close();
          Connection conn3 = getConnection();
          Connection underconn3 = null;
          if(conn3 instanceof DelegatingConnection) {
              underconn3 = ((DelegatingConnection)conn3).getInnermostDelegate();
          } else {
              return; // skip this test
          }
          assertTrue( underconn3 == underconn || underconn3 == underconn2 );
          conn3.close();
      }
      
      public void testAutoCommitBehavior() throws Exception {
          Connection conn = getConnection();
          assertTrue(conn != null);
          assertTrue(conn.getAutoCommit());
          conn.setAutoCommit(false);
          conn.close();
          
          Connection conn2 = getConnection();
          assertTrue( conn2.getAutoCommit() );
          
          Connection conn3 = getConnection();
          assertTrue( conn3.getAutoCommit() );
  
          conn2.close();
          
          conn3.close();
      }
      
      /** @see http://issues.apache.org/bugzilla/show_bug.cgi?id=12400 */
      public void testConnectionsAreDistinct() throws Exception {
          Connection[] conn = new Connection[getMaxActive()];
          for(int i=0;i<conn.length;i++) {
              conn[i] = getConnection();
              for(int j=0;j<i;j++) {
                  assertTrue(conn[j] != conn[i]);
                  assertTrue(!conn[j].equals(conn[i]));
              }
          }
          for(int i=0;i<conn.length;i++) {
              conn[i].close();
          }
      }
  
  
      public void testOpening() throws Exception {
          Connection[] c = new Connection[getMaxActive()];
          // test that opening new connections is not closing previous
          for (int i = 0; i < c.length; i++) {
              c[i] = getConnection();
              assertTrue(c[i] != null);
              for (int j = 0; j <= i; j++) {
                  assertTrue(!c[j].isClosed());
              }
          }
  
          for (int i = 0; i < c.length; i++) {
              c[i].close();
          }
      }
  
      public void testClosing() throws Exception {
          Connection[] c = new Connection[getMaxActive()];
          // open the maximum connections
          for (int i = 0; i < c.length; i++) {
              c[i] = getConnection();
          }
  
          // close one of the connections
          c[0].close();
          assertTrue(c[0].isClosed());
  
          // get a new connection
          c[0] = getConnection();
  
          for (int i = 0; i < c.length; i++) {
              c[i].close();
          }
      }
  
      public void testMaxActive() throws Exception {
          Connection[] c = new Connection[getMaxActive()];
          for (int i = 0; i < c.length; i++) {
              c[i] = getConnection();
              assertTrue(c[i] != null);
          }
  
          try {
              getConnection();
              fail("Allowed to open more than DefaultMaxActive connections.");
          } catch (java.util.NoSuchElementException e) {
              // should only be able to open 10 connections, so this test should
              // throw an exception
          }
  
          for (int i = 0; i < c.length; i++) {
              c[i].close();
          }
      }
  
      public void testThreaded() {
          TestThread[] threads = new TestThread[getMaxActive()];
          for(int i=0;i<threads.length;i++) {
              threads[i] = new TestThread(50,50);
              Thread t = new Thread(threads[i]);
              t.start();
          }
          for(int i=0;i<threads.length;i++) {
              while(!(threads[i]).complete()) {
                  try {
                      Thread.currentThread().sleep(100L);
                  } catch(Exception e) {
                      // ignored
                  }
              }
              if(threads[i].failed()) {
                  fail();
              }
          }
      }
  
      class TestThread implements Runnable {
          java.util.Random _random = new java.util.Random();
          boolean _complete = false;
          boolean _failed = false;
          int _iter = 100;
          int _delay = 50;
  
          public TestThread() {
          }
  
          public TestThread(int iter) {
              _iter = iter;
          }
  
          public TestThread(int iter, int delay) {
              _iter = iter;
              _delay = delay;
          }
  
          public boolean complete() {
              return _complete;
          }
  
          public boolean failed() {
              return _failed;
          }
  
          public void run() {
              for(int i=0;i<_iter;i++) {
                  try {
                      Thread.currentThread().sleep((long)_random.nextInt(_delay));
                  } catch(Exception e) {
                      // ignored
                  }
                  Connection conn = null;
                  PreparedStatement stmt = null;
                  ResultSet rset = null;
                  try {
                      conn = getConnection();
                      stmt = conn.prepareStatement("select 'literal', SYSDATE from dual");
                      rset = stmt.executeQuery();
                      try {
                          Thread.currentThread().sleep((long)_random.nextInt(_delay));
                      } catch(Exception e) {
                          // ignored
                      }
                  } catch(Exception e) {
                      e.printStackTrace();
                      _failed = true;
                      _complete = true;
                      break;
                  } finally {
                      try { rset.close(); } catch(Exception e) { }
                      try { stmt.close(); } catch(Exception e) { }
                      try { conn.close(); } catch(Exception e) { }
                  }
              }
              _complete = true;
          }
      }
      
  }
  
  
  
  1.2       +66 -227   jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/jdbc2pool/TestJdbc2PoolDataSource.java
  
  Index: TestJdbc2PoolDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/jdbc2pool/TestJdbc2PoolDataSource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestJdbc2PoolDataSource.java	5 Aug 2002 06:42:01 -0000	1.1
  +++ TestJdbc2PoolDataSource.java	8 Nov 2002 18:51:07 -0000	1.2
  @@ -1,5 +1,5 @@
   /*
  - * $Header$
  + * $Id$
    * $Revision$
    * $Date$
    *
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -61,26 +61,23 @@
   
   package org.apache.commons.dbcp.jdbc2pool;
   
  -import junit.framework.*;
  -import java.sql.*;
  +import java.sql.Connection;
  +import java.sql.PreparedStatement;
  +import java.sql.ResultSet;
  +
   import javax.sql.DataSource;
  -import org.apache.commons.lang.exception.NestableRuntimeException;
  -import org.apache.commons.pool.*;
  -import org.apache.commons.pool.impl.*;
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
   
  +import org.apache.commons.dbcp.TestConnectionPool;
   import org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS;
  +import org.apache.commons.lang.exception.NestableRuntimeException;
   
   /**
  - * @author Rodney Waldhoff
  - * @version $Id$
  + * @author John McNally
  + * @version $Revision$ $Date$
    */
  -public class TestJdbc2PoolDataSource extends TestCase 
  -{
  -    private static final int MAX_ACTIVE = 10;
  -    private static final int MAX_WAIT = 50;
  -
  -    DataSource ds;
  -
  +public class TestJdbc2PoolDataSource extends TestConnectionPool {
       public TestJdbc2PoolDataSource(String testName) {
           super(testName);
       }
  @@ -89,13 +86,13 @@
           return new TestSuite(TestJdbc2PoolDataSource.class);
       }
   
  -    public static void main(String args[]) {
  -        String[] testCaseName = { TestJdbc2PoolDataSource.class.getName() };
  -        junit.textui.TestRunner.main(testCaseName);
  +    protected Connection getConnection() throws Exception {
  +        return ds.getConnection();
       }
   
  -    public void setUp() throws Exception 
  -    {
  +    private DataSource ds;
  +
  +    public void setUp() throws Exception {
           DriverAdapterCPDS pcds = new DriverAdapterCPDS();
           pcds.setDriver("org.apache.commons.dbcp.TesterDriver");
           pcds.setUrl("jdbc:apache:commons:testdriver");
  @@ -104,198 +101,48 @@
   
           Jdbc2PoolDataSource tds = new Jdbc2PoolDataSource();
           tds.setConnectionPoolDataSource(pcds);
  -        tds.setDefaultMaxActive(MAX_ACTIVE);
  -        tds.setDefaultMaxWait(MAX_WAIT);
  +        tds.setDefaultMaxActive(getMaxActive());
  +        tds.setDefaultMaxWait((int) (getMaxWait()));
   
           ds = tds;
       }
  -
  -    public void testSimple() throws Exception 
  -    {
  -        Connection conn = ds.getConnection();
  -        assertTrue(null != conn);
  -        PreparedStatement stmt = conn.prepareStatement("select * from dual");
  -        assertTrue(null != stmt);
  -        ResultSet rset = stmt.executeQuery();
  -        assertTrue(null != rset);
  -        assertTrue(rset.next());
  -        rset.close();
  -        stmt.close();
  -        conn.close();
  -    }
  -
  -    public void testSimple2() 
  -        throws Exception 
  -    {
  -        Connection conn = ds.getConnection();
  -        assertTrue(null != conn);
  -
  -        PreparedStatement stmt = 
  -            conn.prepareStatement("select * from dual");
  -        assertTrue(null != stmt);
  -        ResultSet rset = stmt.executeQuery();
  -        assertTrue(null != rset);
  -        assertTrue(rset.next());
  -        rset.close();
  -        stmt.close();
  -        
  -        stmt = conn.prepareStatement("select * from dual");
  -        assertTrue(null != stmt);
  -        rset = stmt.executeQuery();
  -        assertTrue(null != rset);
  -        assertTrue(rset.next());
  -        rset.close();
  -        stmt.close();
  -        
  -        conn.close();
  -        try 
  -        {
  -            conn.createStatement();
  -            fail("Can't use closed connections");
  -        } 
  -        catch(SQLException e) 
  -        {
  -            // expected
  -        }
  -
  -        conn = ds.getConnection();
  -        assertTrue(null != conn);
  -
  -        stmt = conn.prepareStatement("select * from dual");
  -        assertTrue(null != stmt);
  -        rset = stmt.executeQuery();
  -        assertTrue(null != rset);
  -        assertTrue(rset.next());
  -        rset.close();
  -        stmt.close();
  -
  -        stmt = conn.prepareStatement("select * from dual");
  -        assertTrue(null != stmt);
  -        rset = stmt.executeQuery();
  -        assertTrue(null != rset);
  -        assertTrue(rset.next());
  -        rset.close();
  -        stmt.close();
  -        
  -        conn.close();
  -        conn = null;
  -    }
  -
  -    public void testOpening() 
  -        throws Exception 
  -    {
  -        Connection[] c = new Connection[MAX_ACTIVE];
  -        // test that opening new connections is not closing previous
  -        for (int i=0; i<c.length; i++) 
  -        {
  -            c[i] = ds.getConnection();
  -            assertTrue(c[i] != null);
  -            for (int j=0; j<=i; j++) 
  -            {
  -                assertTrue(!c[j].isClosed());
  -            }
  -        }
  -
  -        for (int i=0; i<c.length; i++) 
  -        {
  -            c[i].close();
  -        }
  -    }
  -
  -    public void testClosing() 
  -        throws Exception 
  -    {
  -        Connection[] c = new Connection[MAX_ACTIVE];
  -        // open the maximum connections
  -        for (int i=0; i<c.length; i++) 
  -        {
  -            c[i] = ds.getConnection();
  -        }
  -
  -        // close one of the connections
  -        c[0].close();
  -        assertTrue(c[0].isClosed());
  -        
  -        // get a new connection
  -        c[0] = ds.getConnection();
  -
  -        for (int i=0; i<c.length; i++) 
  -        {
  -            c[i].close();
  -        }
  -    }
  -
  -    public void testMaxActive() 
  -        throws Exception 
  -    {
  -        Connection[] c = new Connection[MAX_ACTIVE];
  -        for (int i=0; i<c.length; i++) 
  -        {
  -            c[i] = ds.getConnection();
  -            assertTrue(c[i] != null);            
  -        }
  -
  -        try
  -        {
  -            ds.getConnection();
  -            fail("Allowed to open more than DefaultMaxActive connections.");
  -        }
  -        catch(java.util.NoSuchElementException e)
  -        {
  -            // should only be able to open 10 connections, so this test should
  -            // throw an exception
  -        }
  -
  -        for (int i=0; i<c.length; i++) 
  -        {
  -            c[i].close();
  -        }
  -    }
  -
  -    public void testMultipleThreads()
  -        throws Exception
  -    {
  +    
  +    public void testMultipleThreads() throws Exception {
           assertTrue(multipleThreads(1));
  -        assertTrue(!multipleThreads(2*MAX_WAIT));
  +        assertTrue(!multipleThreads(2 * (int)(getMaxWait())));
       }
   
  -    private boolean multipleThreads(int holdTime)
  -        throws Exception
  -    {
  +    private boolean multipleThreads(int holdTime) throws Exception {
           long startTime = System.currentTimeMillis();
           final boolean[] success = new boolean[1];
           success[0] = true;
  -        final PoolTest[] pts = new PoolTest[2*MAX_ACTIVE];
  -        ThreadGroup threadGroup = new ThreadGroup("foo")
  -            {
  -                public void uncaughtException(Thread t, Throwable e)
  +        final PoolTest[] pts = new PoolTest[2 * getMaxActive()];
  +        ThreadGroup threadGroup = new ThreadGroup("foo") {
  +            public void uncaughtException(Thread t, Throwable e) {
  +                /*
  +                for (int i = 0; i < pts.length; i++)
                   {
  -                    /*
  -                    for (int i = 0; i < pts.length; i++)
  -                    {
  -                        System.out.println(i + ": " + pts[i].reportState());
  -                    }
  -                    */
  -                    for (int i = 0; i < pts.length; i++)
  -                    {
  -                        pts[i].stop();
  -                    }
  -                    
  -                    //e.printStackTrace();
  -                    success[0] = false;
  +                    System.out.println(i + ": " + pts[i].reportState());
                   }
  -            };
  +                */
  +                for (int i = 0; i < pts.length; i++) {
  +                    pts[i].stop();
  +                }
  +
  +                //e.printStackTrace();
  +                success[0] = false;
  +            }
  +        };
   
  -        for (int i = 0; i < pts.length; i++)
  -        {
  +        for (int i = 0; i < pts.length; i++) {
               pts[i] = new PoolTest(threadGroup, holdTime);
           }
  -        Thread.currentThread().sleep(10*holdTime);
  -        for (int i = 0; i < pts.length; i++)
  -        {
  +        Thread.currentThread().sleep(10 * holdTime);
  +        for (int i = 0; i < pts.length; i++) {
               pts[i].stop();
           }
  -        long time = System.currentTimeMillis() - startTime; // - (pts.length*10*holdTime);
  +        long time = System.currentTimeMillis() - startTime;
  +        // - (pts.length*10*holdTime);
           System.out.println("Multithread test time = " + time + " ms");
   
           Thread.currentThread().sleep(holdTime);
  @@ -304,67 +151,59 @@
   
       private static int currentThreadCount = 0;
   
  -    private class PoolTest implements Runnable
  -    {
  +    private class PoolTest implements Runnable {
           /**
            * The number of milliseconds to hold onto a database connection
            */
           private int connHoldTime;
  -        
  +
           private boolean isRun;
  -        
  +
           private String state;
   
  -        protected PoolTest(ThreadGroup threadGroup, int connHoldTime)
  -        {
  +        protected PoolTest(ThreadGroup threadGroup, int connHoldTime) {
               this.connHoldTime = connHoldTime;
  -            Thread thread = new Thread(threadGroup, this,
  -                                       "Thread+" + currentThreadCount++);
  +            Thread thread =
  +                new Thread(threadGroup, this, "Thread+" + currentThreadCount++);
               thread.setDaemon(false);
               thread.start();
           }
  -        
  -        public void run()
  -        {
  +
  +        public void run() {
               Thread thread = Thread.currentThread();
               isRun = true;
  -            while (isRun)
  -            {
  -                try
  -                {
  +            while (isRun) {
  +                try {
                       Connection conn = null;
  -                    state="Getting Connection";
  -                    conn = ds.getConnection();
  -                    state="Using Connection";
  +                    state = "Getting Connection";
  +                    conn = getConnection();
  +                    state = "Using Connection";
                       assertTrue(null != conn);
  -                    PreparedStatement stmt = 
  +                    PreparedStatement stmt =
                           conn.prepareStatement("select * from dual");
                       assertTrue(null != stmt);
                       ResultSet rset = stmt.executeQuery();
                       assertTrue(null != rset);
                       assertTrue(rset.next());
  -                    state="Holding Connection";
  +                    state = "Holding Connection";
                       thread.sleep(connHoldTime);
  -                    state="Returning Connection";
  +                    state = "Returning Connection";
                       rset.close();
                       stmt.close();
                       conn.close();
  -                }
  -                catch (Exception e)
  -                {
  +                } catch (Exception e) {
                       throw new NestableRuntimeException(e);
                   }
               }
           }
  -        
  -        public void stop()
  -        {
  +
  +        public void stop() {
               isRun = false;
           }
   
  -        public String reportState()
  -        {
  +        public String reportState() {
               return state;
           }
       }
  +    
   }
  
  
  

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


Mime
View raw message