This class is intended to be thread-safe.
106107108109110111112113114115116117118
pool.destroy(); } @Test(expected = JedisConnectionException.class) public void checkPoolOverflow() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(1); config.setBlockWhenExhausted(false); ShardedJedisPool pool = new ShardedJedisPool(config, shards); ShardedJedis jedis = pool.getResource(); jedis.set("foo", "0");
121122123124125126127128129130131132
newJedis.incr("foo"); } @Test public void shouldNotShareInstances() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(2); ShardedJedisPool pool = new ShardedJedisPool(config, shards); ShardedJedis j1 = pool.getResource(); ShardedJedis j2 = pool.getResource();
135136137138139140141142143144145
} @Test public void checkFailedJedisServer() { ShardedJedisPool pool = new ShardedJedisPool( new GenericObjectPoolConfig(), shards); ShardedJedis jedis = pool.getResource(); jedis.incr("foo"); pool.returnResource(jedis); pool.destroy(); }
144145146147148149150151152153154155
pool.destroy(); } @Test public void shouldReturnActiveShardsWhenOneGoesOffline() { GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig(); redisConfig.setTestOnBorrow(false); ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards); ShardedJedis jedis = pool.getResource(); // fill the shards for (int i = 0; i < 1000; i++) { jedis.set("a-test-" + i, "0");
199200201202203204205206207208209
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(); shards.add(new JedisShardInfo("redis://:foobared@localhost:6380")); shards.add(new JedisShardInfo("redis://:foobared@localhost:6379")); GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig(); ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards); Jedis[] jedises = pool.getResource().getAllShards() .toArray(new Jedis[2]);
230231232233234235236237238239240
shards.add(new JedisShardInfo(new URI( "redis://:foobared@localhost:6380"))); shards.add(new JedisShardInfo(new URI( "redis://:foobared@localhost:6379"))); GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig(); ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards); Jedis[] jedises = pool.getResource().getAllShards() .toArray(new Jedis[2]);
247248249250251252253254255256257258259
assertEquals("bar", jedis.get("foo")); } @Test public void returnResourceShouldResetState() throws URISyntaxException { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(1); config.setBlockWhenExhausted(false); List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(); shards.add(new JedisShardInfo(new URI( "redis://:foobared@localhost:6380"))); shards.add(new JedisShardInfo(new URI(
282283284285286287288289290291292293294
pool.destroy(); } @Test public void checkResourceIsCloseable() throws URISyntaxException { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(1); config.setBlockWhenExhausted(false); List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(); shards.add(new JedisShardInfo(new URI( "redis://:foobared@localhost:6380"))); shards.add(new JedisShardInfo(new URI(
3233343536373839
this(masterName, sentinels, poolConfig, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE); } public JedisSentinelPool(String masterName, Set<String> sentinels) { this(masterName, sentinels, new GenericObjectPoolConfig(), Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE); }
3839404142434445
Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE); } public JedisSentinelPool(String masterName, Set<String> sentinels, String password) { this(masterName, sentinels, new GenericObjectPoolConfig(), Protocol.DEFAULT_TIMEOUT, password); }