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

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

    expect(mockConnection.isExpired(anyLong())).andReturn(false).once();

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

    mockPool.putConnectionBackInPartition(mockConnection);
    expectLastCall().once();

    replay(mockQueue, mockExecutor, mockConnectionPartition, mockConnection, mockPool);
    testClass.run();
    verify(mockConnection, mockPool);
  }
  /** @throws SQLException */
  @Test
  @SuppressWarnings("unchecked")
  public void testExceptionsCaseWherePutInPartitionFails() throws SQLException {

    TransferQueue<ConnectionHandle> mockQueue = createNiceMock(TransferQueue.class);
    expect(mockConnectionPartition.getAvailableConnections()).andReturn(1);
    expect(mockConnectionPartition.getFreeConnections()).andReturn(mockQueue).anyTimes();
    ConnectionHandle mockConnectionException = createNiceMock(ConnectionHandle.class);
    expect(mockQueue.poll()).andReturn(mockConnectionException).times(1);
    expect(mockConnectionException.isExpired(anyLong())).andReturn(false).anyTimes();
    expect(mockExecutor.isShutdown()).andReturn(false).anyTimes();
    mockPool.putConnectionBackInPartition(mockConnectionException);
    expectLastCall().andThrow(new SQLException()).once();

    // we should be able to reschedule
    expect(mockExecutor.schedule((Runnable) anyObject(), anyLong(), (TimeUnit) anyObject()))
        .andReturn(null)
        .once();

    replay(mockQueue, mockConnectionException, mockExecutor, mockConnectionPartition, mockPool);
    testClass.run();
    verify(mockExecutor, mockConnectionException);
  }