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/10/15 21:55:57 UTC

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

dirkv       2003/10/15 12:55:57

  Modified:    dbcp/src/test/org/apache/commons/dbcp/datasources
                        TestPerUserPoolDataSource.java
  Log:
  tests for issue 23843 (to debug the problem)
  
  Revision  Changes    Path
  1.7       +75 -3     jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java
  
  Index: TestPerUserPoolDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestPerUserPoolDataSource.java	9 Oct 2003 21:05:30 -0000	1.6
  +++ TestPerUserPoolDataSource.java	15 Oct 2003 19:55:57 -0000	1.7
  @@ -78,6 +78,7 @@
   import junit.framework.TestSuite;
   
   import org.apache.commons.dbcp.TestConnectionPool;
  +import org.apache.commons.dbcp.TesterDriver;
   import org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS;
   
   /**
  @@ -530,5 +531,76 @@
           in.close();
   
           assertEquals( 1, ((PerUserPoolDataSource)obj).getNumIdle() );
  +    }
  +
  +    // see issue http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23843
  +    // unregistered user is in the same pool as without username 
  +    public void testUnregisteredUser() throws Exception {
  +        PerUserPoolDataSource tds = (PerUserPoolDataSource) ds;
  +        
  +        assertEquals(0, tds.getNumActive());
  +        assertEquals(0, tds.getNumIdle());
  +        
  +        Connection conn = tds.getConnection();
  +        assertNotNull(conn);
  +        assertEquals(1, tds.getNumActive());
  +        assertEquals(0, tds.getNumIdle());
  +
  +        conn.close();
  +        assertEquals(0, tds.getNumActive());
  +        assertEquals(1, tds.getNumIdle());
  +
  +        conn = tds.getConnection("u1", null);
  +        assertNotNull(conn);
  +        assertEquals(1, tds.getNumActive());
  +        assertEquals(0, tds.getNumIdle());
  +
  +        conn.close();
  +        assertEquals(0, tds.getNumActive());
  +        assertEquals(1, tds.getNumIdle());
  +    }
  +
  +    // see issue http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23843
  +    public void testDefaultUser1() throws Exception {
  +        TesterDriver.addUser("mkh", "password");
  +        TesterDriver.addUser("hanafey", "password");
  +        TesterDriver.addUser("jsmith", "password");
  +
  +        PerUserPoolDataSource puds = (PerUserPoolDataSource) ds;
  +        puds.setPerUserMaxActive("jsmith", new Integer(2));
  +        String[] users = {"mkh", "hanafey", "jsmith"};
  +        String password = "password";
  +        Connection[] c = new Connection[users.length];
  +        for (int i = 0; i < users.length; i++) {
  +            c[i] = puds.getConnection(users[i], password);
  +        }
  +        System.out.println("testDefaultUser1:");
  +        for (int i = 0; i < users.length; i++) {
  +            System.out.println(
  +                "   Tried: " + users[i] + 
  +                "   got: " + getUsername(c[i]));
  +        }
  +    }
  +    
  +    // see issue http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23843
  +    public void testDefaultUser2() throws Exception {
  +        TesterDriver.addUser("mkh", "password");
  +        TesterDriver.addUser("hanafey", "password");
  +        TesterDriver.addUser("jsmith", "password");
  +
  +        PerUserPoolDataSource puds = (PerUserPoolDataSource) ds;
  +        puds.setPerUserMaxActive("jsmith", new Integer(2));
  +        String[] users = {"jsmith", "hanafey", "mkh"};
  +        String password = "password";
  +        Connection[] c = new Connection[users.length];
  +        for (int i = 0; i < users.length; i++) {
  +            c[i] = puds.getConnection(users[i], password);
  +        }
  +        System.out.println("testDefaultUser2:");
  +        for (int i = 0; i < users.length; i++) {
  +            System.out.println(
  +                "   Tried: " + users[i] + 
  +                "   got: " + getUsername(c[i]));
  +        }
       }
   }
  
  
  

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