Skip to content

Commit

Permalink
Don't return JedisConnectionException if pool is exahusted
Browse files Browse the repository at this point in the history
Fixes #1236
  • Loading branch information
marcosnils committed Mar 10, 2016
1 parent fe2e41f commit 8cc32e6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main/java/redis/clients/util/Pool.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/redis/clients/jedis/tests/JedisPoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8cc32e6

Please sign in to comment.