@Test public void testCloseExpired() throws Exception {
  IOSession iosession1=Mockito.mock(IOSession.class);
  Mockito.when(iosession1.isClosed()).thenReturn(Boolean.TRUE);
  SessionRequest sessionRequest1=Mockito.mock(SessionRequest.class);
  Mockito.when(sessionRequest1.getAttachment()).thenReturn("somehost");
  Mockito.when(sessionRequest1.getSession()).thenReturn(iosession1);
  IOSession iosession2=Mockito.mock(IOSession.class);
  SessionRequest sessionRequest2=Mockito.mock(SessionRequest.class);
  Mockito.when(sessionRequest2.getAttachment()).thenReturn("somehost");
  Mockito.when(sessionRequest2.getSession()).thenReturn(iosession2);
  ConnectingIOReactor ioreactor=Mockito.mock(ConnectingIOReactor.class);
  Mockito.when(ioreactor.connect(Mockito.any(SocketAddress.class),Mockito.any(SocketAddress.class),Mockito.any(),Mockito.any(SessionRequestCallback.class))).thenReturn(sessionRequest1,sessionRequest2);
  LocalSessionPool pool=new LocalSessionPool(ioreactor,2,2);
  Future<LocalPoolEntry> future1=pool.lease("somehost",null);
  Future<LocalPoolEntry> future2=pool.lease("somehost",null);
  pool.requestCompleted(sessionRequest1);
  pool.requestCompleted(sessionRequest2);
  Assert.assertTrue(future1.isDone());
  LocalPoolEntry entry1=future1.get();
  Assert.assertNotNull(entry1);
  Assert.assertTrue(future2.isDone());
  LocalPoolEntry entry2=future2.get();
  Assert.assertNotNull(entry2);
  entry1.updateExpiry(1,TimeUnit.MILLISECONDS);
  pool.release(entry1,true);
  Thread.sleep(200);
  entry2.updateExpiry(1000,TimeUnit.SECONDS);
  pool.release(entry2,true);
  pool.closeExpired();
  Mockito.verify(iosession1).close();
  Mockito.verify(iosession2,Mockito.never()).close();
  PoolStats totals=pool.getTotalStats();
  Assert.assertEquals(1,totals.getAvailable());
  Assert.assertEquals(0,totals.getLeased());
  Assert.assertEquals(0,totals.getPending());
  PoolStats stats=pool.getStats("somehost");
  Assert.assertEquals(1,stats.getAvailable());
  Assert.assertEquals(0,stats.getLeased());
  Assert.assertEquals(0,stats.getPending());
}
