@Test
public void testCloseExpired() throws Exception {

    final HttpConnection conn1 = Mockito.mock(HttpConnection.class);
    final HttpConnection conn2 = Mockito.mock(HttpConnection.class);
    final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2);
    final Future<PoolEntry<String, HttpConnection>> future1 = pool.lease("somehost", null);
    final Future<PoolEntry<String, HttpConnection>> future2 = pool.lease("somehost", null);
    Assert.assertTrue(future1.isDone());
    final PoolEntry<String, HttpConnection> entry1 = future1.get();
    Assert.assertNotNull(entry1);
    entry1.assignConnection(conn1);
    Assert.assertTrue(future2.isDone());
    final PoolEntry<String, HttpConnection> entry2 = future2.get();
    Assert.assertNotNull(entry2);
    entry2.assignConnection(conn2);
    entry1.updateExpiry(TimeValue.of(1, TimeUnit.MILLISECONDS));
    pool.release(entry1, true);
    Thread.sleep(200);
    entry2.updateExpiry(TimeValue.of(1000, TimeUnit.SECONDS));
    pool.release(entry2, true);
    pool.closeExpired();
    Mockito.verify(conn1).close(CloseMode.GRACEFUL);
    Mockito.verify(conn2, Mockito.never()).close(ArgumentMatchers.<CloseMode>any());
    final PoolStats totals = pool.getTotalStats();
    Assert.assertEquals(1, totals.getAvailable());
    Assert.assertEquals(0, totals.getLeased());
    Assert.assertEquals(0, totals.getPending());
    final PoolStats stats = pool.getStats("somehost");
    Assert.assertEquals(1, stats.getAvailable());
    Assert.assertEquals(0, stats.getLeased());
    Assert.assertEquals(0, stats.getPending());
}