Closes #656. Add a getNumActive() method to JedisPool to provide access to the current state of the internal pool.
This commit is contained in:
@@ -238,4 +238,35 @@ public class JedisPoolTest extends Assert {
|
||||
pool.returnResource(null);
|
||||
pool.returnResourceObject(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNumActiveIsNegativeWhenPoolIsClosed() {
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort(), 2000, "foobared", 0, "my_shiny_client_name");
|
||||
|
||||
pool.destroy();
|
||||
assertTrue(pool.getNumActive() < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNumActiveReturnsTheCorrectNumber() {
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort(), 2000);
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
|
||||
assertEquals(1, pool.getNumActive());
|
||||
|
||||
Jedis jedis2 = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
|
||||
assertEquals(2, pool.getNumActive());
|
||||
|
||||
pool.returnResource(jedis);
|
||||
pool.returnResource(jedis2);
|
||||
pool.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user