コード例 #1
0
 public void testCheckInReturnsConnectionsToAvailableMap() {
   Connection conn1 = pool.checkout();
   Connection conn2 = pool.checkout();
   assertEquals(0, pool.available.size());
   pool.checkin(conn1);
   Queue<ConnectionWrapper> queue = pool.available;
   assertTrue(queueContainsConnection(queue, conn1));
   assertFalse(queueContainsConnection(queue, conn2));
   pool.checkin(conn2);
   assertTrue(queueContainsConnection(queue, conn1));
   assertTrue(queueContainsConnection(queue, conn2));
 }
コード例 #2
0
 public void testCheckoutReusesAvailableConnection() {
   Connection conn = pool.checkout();
   pool.checkin(conn);
   int initCount = pool.connections;
   pool.checkout();
   assertEquals(initCount, pool.connections);
 }
コード例 #3
0
 public void testCheckinDoesNotThrowWhenStatementsAreClosed() throws Exception {
   Connection conn = pool.checkout();
   Statement stmt = conn.createStatement();
   ResultSet rs = stmt.executeQuery("SELECT 123");
   rs.close();
   stmt.close();
   pool.checkin(conn);
 }
コード例 #4
0
 public void testCheckoutExpiredAvailableConnection() {
   long timeout = pool.getConnectionIdleTime();
   pool.setConnectionIdleTime(0);
   Connection conn = pool.checkout();
   pool.checkin(conn);
   int initCount = pool.connections;
   pool.checkout();
   assertEquals(initCount, pool.connections);
   assertEquals(pool.getNumberAvailableConnections(), 0);
   pool.setConnectionIdleTime(timeout);
 }
コード例 #5
0
 public void testCheckinDoesNotThrowWhenStatementsAreNonActive() throws Exception {
   Connection conn = pool.checkout();
   Statement stmt = conn.createStatement();
   ResultSet rs = stmt.executeQuery("SELECT 123");
   rs.close();
   try {
     pool.checkin(conn);
   } catch (IllegalStateException e) {
     assertEquals(
         "Attempting to checkin a connection with 1 active statement(s).", e.getMessage());
   }
 }
コード例 #6
0
  public void testMultipleConnectionPools() {
    // check the number of available connections in the pool
    assertEquals(0, pool.getNumberAvailableConnections());

    // checkout a default db connection
    Connection conn = pool.checkout();
    pool.checkin(conn);
    assertEquals(1, pool.getNumberAvailableConnections());

    // checkout a tigerprawn db connection
    ConnectionPool tp = ConnectionPool.getInstance(OTHER_APP_NAME);
    try {
      assertNotSame(pool, tp);
      assertEquals(0, tp.getNumberAvailableConnections());
      conn = tp.checkout();
      tp.checkin(conn);
      assertEquals(1, pool.getNumberAvailableConnections());
      assertEquals(1, tp.getNumberAvailableConnections());
    } finally {
      if (tp != null) tp.stopPool();
    }
  }
コード例 #7
0
  public void testStopPoolClearsAvailableAndInUseConnections() {
    // create 1 in-use and 1 available connection
    Connection conn1 = pool.checkout();
    pool.checkout();
    pool.checkin(conn1);
    assertEquals(1, pool.inUse.size());
    assertEquals(1, pool.available.size());

    // invoke stopPool()
    pool.stopPool();

    // check that both maps have been cleared
    assertEquals(0, pool.inUse.size());
    assertEquals(0, pool.available.size());
  }
コード例 #8
0
  public void testStopPoolClosesAvailableAndInUseConnections() throws SQLException {
    // create 1 in-use and 2 available connection
    Connection conn1 = pool.checkout();
    Connection conn2 = pool.checkout();
    Connection conn3 = pool.checkout();
    pool.checkin(conn1);
    pool.checkin(conn2);
    assertFalse(conn1.isClosed());
    assertFalse(conn2.isClosed());
    assertFalse(conn3.isClosed());

    // invoke stopPool()
    pool.stopPool();

    // check that both connections are closed
    assertTrue(conn1.isClosed());
    assertTrue(conn2.isClosed());
    assertTrue(conn3.isClosed());
  }
コード例 #9
0
 public void testCheckInDoesNotCloseConnection() throws SQLException {
   Connection conn1 = pool.checkout();
   assertFalse(conn1.isClosed());
   pool.checkin(conn1);
   assertFalse(conn1.isClosed());
 }
コード例 #10
0
 public void testCheckInDoesNotDecrementConnectionCount() {
   Connection conn = pool.checkout();
   int initCount = pool.connections;
   pool.checkin(conn);
   assertEquals(initCount, pool.connections);
 }