diff --git a/src/main/java/redis/clients/util/Pool.java b/src/main/java/redis/clients/util/Pool.java index c0a13face8..637b4d73fe 100644 --- a/src/main/java/redis/clients/util/Pool.java +++ b/src/main/java/redis/clients/util/Pool.java @@ -1,6 +1,7 @@ package redis.clients.util; import java.io.Closeable; +import java.util.NoSuchElementException; import org.apache.commons.pool2.PooledObjectFactory; import org.apache.commons.pool2.impl.GenericObjectPool; @@ -46,6 +47,8 @@ public void initPool(final GenericObjectPoolConfig poolConfig, PooledObjectFacto public T getResource() { try { return internalPool.borrowObject(); + } catch (NoSuchElementException nse) { + throw new JedisException("Could not get a resource from the pool", nse); } catch (Exception e) { throw new JedisConnectionException("Could not get a resource from the pool", e); } diff --git a/src/test/java/redis/clients/jedis/tests/JedisClusterTest.java b/src/test/java/redis/clients/jedis/tests/JedisClusterTest.java index 246428dc18..fb287ef5a3 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisClusterTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisClusterTest.java @@ -425,7 +425,7 @@ public void testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified() assertEquals("foo", jc.get("51")); } - @Test(expected = JedisConnectionException.class) + @Test(expected = JedisException.class) public void testIfPoolConfigAppliesToClusterPools() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(0); diff --git a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java index 1b18d630ec..5ea8f80bf1 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java @@ -92,7 +92,7 @@ public void checkPoolRepairedWhenJedisIsBroken() { assertTrue(pool.isClosed()); } - @Test(expected = JedisConnectionException.class) + @Test(expected = JedisException.class) public void checkPoolOverflow() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(1); diff --git a/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java b/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java index 0f108a77fb..7cd46516d9 100644 --- a/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java @@ -17,6 +17,7 @@ import redis.clients.jedis.ShardedJedisPipeline; import redis.clients.jedis.ShardedJedisPool; import redis.clients.jedis.exceptions.JedisConnectionException; +import redis.clients.jedis.exceptions.JedisException; public class ShardedJedisPoolTest extends Assert { private static HostAndPort redis1 = HostAndPortUtil.getRedisServers().get(0); @@ -99,7 +100,7 @@ public void checkPoolRepairedWhenJedisIsBroken() { pool.destroy(); } - @Test(expected = JedisConnectionException.class) + @Test(expected = JedisException.class) public void checkPoolOverflow() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(1);