Closes #656. Add a getNumActive() method to JedisPool to provide access to the current state of the internal pool.

This commit is contained in:
Ethan Urie
2014-09-02 14:54:36 -04:00
parent ebaba79119
commit a201e29d88
2 changed files with 39 additions and 0 deletions

View File

@@ -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();
}
}