@Test(expected=IllegalArgumentException.class) public void testGetStatsInvalid() throws Exception { final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2); pool.getStats(null); }
@Test public void testCreateNewIfExpired() throws Exception { final HttpConnection conn1 = Mockito.mock(HttpConnection.class); final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2); final Future<PoolEntry<String, HttpConnection>> future1 = pool.lease("somehost", null); Assert.assertTrue(future1.isDone()); final PoolEntry<String, HttpConnection> entry1 = future1.get(); Assert.assertNotNull(entry1); entry1.assignConnection(conn1); entry1.updateExpiry(TimeValue.of(1, TimeUnit.MILLISECONDS)); pool.release(entry1, true); Thread.sleep(200L); final Future<PoolEntry<String, HttpConnection>> future2 = pool.lease("somehost", null); Assert.assertTrue(future2.isDone()); Mockito.verify(conn1).close(CloseMode.GRACEFUL); final PoolStats totals = pool.getTotalStats(); Assert.assertEquals(0, totals.getAvailable()); Assert.assertEquals(1, totals.getLeased()); Assert.assertEquals(Collections.singleton("somehost"), pool.getRoutes()); final PoolStats stats = pool.getStats("somehost"); Assert.assertEquals(0, stats.getAvailable()); Assert.assertEquals(1, stats.getLeased()); }
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, 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, totals.getLeased()); Assert.assertEquals(0, totals.getPending()); stats = pool.getStats("somehost"); Assert.assertEquals(0, stats.getAvailable()); Assert.assertEquals(0, stats.getLeased());
@Test public void testEmptyPool() throws Exception { final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2); final PoolStats totals = pool.getTotalStats(); Assert.assertEquals(0, totals.getAvailable()); Assert.assertEquals(0, totals.getLeased()); Assert.assertEquals(0, totals.getPending()); Assert.assertEquals(0, totals.getMax()); Assert.assertEquals(Collections.emptySet(), pool.getRoutes()); final PoolStats stats = pool.getStats("somehost"); Assert.assertEquals(0, stats.getAvailable()); Assert.assertEquals(0, stats.getLeased()); Assert.assertEquals(0, stats.getPending()); Assert.assertEquals(2, stats.getMax()); Assert.assertEquals("[leased: 0][available: 0][pending: 0]", pool.toString()); }