LaxConnPool implements ManagedConnPool<T, C> { @Override public void closeExpired() { final long now = System.currentTimeMillis(); enumAvailable(new Callback<PoolEntry<T, C>>() { @Override public void execute(final PoolEntry<T, C> entry) { if (entry.getExpiryDeadline().isBefore(now)) { entry.discardConnection(CloseMode.GRACEFUL); } } }); } LaxConnPool(
            final int defaultMaxPerRoute,
            final TimeValue timeToLive,
            final PoolReusePolicy policy,
            final DisposalCallback<C> disposalCallback,
            final ConnPoolListener<T> connPoolListener);  LaxConnPool(
            final int defaultMaxPerRoute,
            final TimeValue timeToLive,
            final PoolReusePolicy policy,
            final ConnPoolListener<T> connPoolListener);  LaxConnPool(final int defaultMaxPerRoute); boolean isShutdown(); @Override void close(final CloseMode closeMode); @Override void close(); @Override Future<PoolEntry<T, C>> lease(
            final T route, final Object state,
            final Timeout requestTimeout,
            final FutureCallback<PoolEntry<T, C>> callback); Future<PoolEntry<T, C>> lease(final T route, final Object state); @Override void release(final PoolEntry<T, C> entry, final boolean reusable); void validatePendingRequests(); @Override void setMaxTotal(final int max); @Override int getMaxTotal(); @Override void setDefaultMaxPerRoute(final int max); @Override int getDefaultMaxPerRoute(); @Override void setMaxPerRoute(final T route, final int max); @Override int getMaxPerRoute(final T route); @Override PoolStats getTotalStats(); @Override PoolStats getStats(final T route); @Override Set<T> getRoutes(); void enumAvailable(final Callback<PoolEntry<T, C>> callback); void enumLeased(final Callback<PoolEntry<T, C>> callback); @Override void closeIdle(final TimeValue idleTime); @Override void closeExpired(); @Override String toString();  }
@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()); }