Closes #656. Add a getNumActive() method to JedisPool to provide access to the current state of the internal pool.
This commit is contained in:
@@ -98,4 +98,12 @@ public class JedisPool extends Pool<Jedis> {
|
|||||||
returnResourceObject(resource);
|
returnResourceObject(resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumActive() {
|
||||||
|
if (this.internalPool == null || this.internalPool.isClosed()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.internalPool.getNumActive();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,4 +238,35 @@ public class JedisPoolTest extends Assert {
|
|||||||
pool.returnResource(null);
|
pool.returnResource(null);
|
||||||
pool.returnResourceObject(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