/**
   * Tests that a partition with expired connections should those connections killed off.
   *
   * @throws SQLException
   */
  @Test
  @SuppressWarnings({"unchecked", "rawtypes"})
  public void testConnectionExpired() throws SQLException {

    TransferQueue<ConnectionHandle> mockQueue = createNiceMock(TransferQueue.class);
    expect(mockConnectionPartition.getAvailableConnections()).andReturn(1);
    expect(mockConnectionPartition.getFreeConnections()).andReturn(mockQueue).anyTimes();
    ConnectionHandle mockConnectionExpired = createNiceMock(ConnectionHandle.class);
    ConnectionHandle mockConnection = createNiceMock(ConnectionHandle.class);
    expect(mockQueue.poll()).andReturn(mockConnectionExpired).once();

    expect(mockConnectionExpired.isExpired(anyLong())).andReturn(true).once();

    expect(mockExecutor.isShutdown()).andReturn(false).once();

    mockConnectionExpired.internalClose();
    expectLastCall().once();

    mockPool.postDestroyConnection(mockConnectionExpired);
    expectLastCall().once();

    expect(mockExecutor.schedule((Callable) anyObject(), anyLong(), (TimeUnit) anyObject()))
        .andReturn(null)
        .once();
    replay(
        mockQueue,
        mockExecutor,
        mockConnectionPartition,
        mockConnection,
        mockPool,
        mockConnectionExpired);
    testClass.run();
    verify(mockConnectionExpired);
  }
  /** @throws SQLException */
  @Test
  public void testCloseConnectionWithException() throws SQLException {
    ConnectionHandle mockConnection = createNiceMock(ConnectionHandle.class);
    mockPool.postDestroyConnection(mockConnection);
    expectLastCall().once();

    mockConnection.internalClose();
    expectLastCall().andThrow(new SQLException());

    replay(mockConnection, mockPool);
    testClass.closeConnection(mockConnection);
    verify(mockConnection, mockPool);
  }
  /** @throws SQLException */
  @Test
  public void testCloseConnectionWithExceptionCoverage() throws SQLException {
    ConnectionHandle mockConnection = createNiceMock(ConnectionHandle.class);
    mockPool.postDestroyConnection(mockConnection);
    expectLastCall().once();
    ConnectionMaxAgeThread.logger = null; // make it break.
    mockConnection.internalClose();
    expectLastCall().andThrow(new SQLException());

    replay(mockConnection, mockPool);
    try {
      testClass.closeConnection(mockConnection);
    } catch (Exception e) {
      // do nothing
    }
    verify(mockConnection, mockPool);
  }