diff --git a/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java b/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java index 03763cd..5444f84 100644 --- a/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java @@ -116,71 +116,55 @@ public class ShardedJedisPoolTest extends Assert { assertNotSame(j1.getShard("foo"), j2.getShard("foo")); } - public void checkConnectionsWithNoServers() { - shards = new ArrayList(); - shards.add(new JedisShardInfo("localhost", 6379, "ssa")); - shards.add(new JedisShardInfo("localhost", 6380, "ssa")); - Config redisConfig = new Config(); - redisConfig.testOnBorrow = false; // deactivated for now - redisConfig.testOnReturn = true; - redisConfig.maxActive = 200; // nro threads + margen de seguridad? - redisConfig.minIdle = 200; - ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards); - ShardedJedis jedis = pool.getResource(); - pool.returnResource(jedis); - pool.destroy(); - } - - @Test - public void checkFailedJedisServer() { - ShardedJedisPool pool = new ShardedJedisPool(new Config(), shards); - ShardedJedis jedis = pool.getResource(); - jedis.incr("foo"); - pool.returnResource(jedis); - pool.destroy(); - } - - @Test - public void shouldReturnActiveShardsWhenOneGoesOffline() { - Config redisConfig = new Config(); - redisConfig.testOnBorrow = 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"); - } - pool.returnResource(jedis); - // check quantity for each shard - Jedis j = new Jedis(shards.get(0)); - j.connect(); - Long c1 = j.dbSize(); - j.disconnect(); - j = new Jedis(shards.get(1)); - j.connect(); - Long c2 = j.dbSize(); - j.disconnect(); - // shutdown shard 2 and check thay the pool returns an instance with c1 - // items on one shard - // alter shard 1 and recreate pool - pool.destroy(); - shards.set(1, new JedisShardInfo("nohost", 1234)); - pool = new ShardedJedisPool(redisConfig, shards); - jedis = pool.getResource(); - Long actual = new Long(0); - Long fails = new Long(0); - for (int i = 0; i < 1000; i++) { - try { - jedis.get("a-test-" + i); - actual++; - } catch (RuntimeException e) { - fails++; - } - } - pool.returnResource(jedis); - pool.destroy(); - assertEquals(actual, c1); - assertEquals(fails, c2); - } + @Test + public void checkFailedJedisServer() { + ShardedJedisPool pool = new ShardedJedisPool(new Config(), shards); + ShardedJedis jedis = pool.getResource(); + jedis.incr("foo"); + pool.returnResource(jedis); + pool.destroy(); + } + @Test + public void shouldReturnActiveShardsWhenOneGoesOffline() { + Config redisConfig = new Config(); + redisConfig.testOnBorrow = 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"); + } + pool.returnResource(jedis); + // check quantity for each shard + Jedis j = new Jedis(shards.get(0)); + j.connect(); + Long c1 = j.dbSize(); + j.disconnect(); + j = new Jedis(shards.get(1)); + j.connect(); + Long c2 = j.dbSize(); + j.disconnect(); + // shutdown shard 2 and check thay the pool returns an instance with c1 + // items on one shard + // alter shard 1 and recreate pool + pool.destroy(); + shards.set(1, new JedisShardInfo("nohost", 1234)); + pool = new ShardedJedisPool(redisConfig, shards); + jedis = pool.getResource(); + Long actual = new Long(0); + Long fails = new Long(0); + for (int i = 0; i < 1000; i++) { + try { + jedis.get("a-test-" + i); + actual++; + } catch (RuntimeException e) { + fails++; + } + } + pool.returnResource(jedis); + pool.destroy(); + assertEquals(actual, c1); + assertEquals(fails, c2); + } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/ShardedJedisTest.java b/src/test/java/redis/clients/jedis/tests/ShardedJedisTest.java index 5d73696..e04a998 100644 --- a/src/test/java/redis/clients/jedis/tests/ShardedJedisTest.java +++ b/src/test/java/redis/clients/jedis/tests/ShardedJedisTest.java @@ -23,10 +23,10 @@ public class ShardedJedisTest extends Assert { .get(1); private List getKeysDifferentShard(ShardedJedis jedis) { - List ret = new ArrayList (); + List ret = new ArrayList(); JedisShardInfo first = jedis.getShardInfo("a0"); ret.add("a0"); - for (int i =1; i < 100; ++i) { + for (int i = 1; i < 100; ++i) { JedisShardInfo actual = jedis.getShardInfo("a" + i); if (actual != first) { ret.add("a" + i); @@ -135,8 +135,8 @@ public class ShardedJedisTest extends Assert { assertEquals(jedis2.getKeyTag("foo"), "foo"); assertNotSame(jedis2.getKeyTag("foo{bar}"), "bar"); - JedisShardInfo s5 = jedis2.getShardInfo(keys.get(0)+"{bar}"); - JedisShardInfo s6 = jedis2.getShardInfo(keys.get(1)+"{bar}"); + JedisShardInfo s5 = jedis2.getShardInfo(keys.get(0) + "{bar}"); + JedisShardInfo s6 = jedis2.getShardInfo(keys.get(1) + "{bar}"); assertNotSame(s5, s6); } @@ -241,62 +241,63 @@ public class ShardedJedisTest extends Assert { assertTrue(shard_6381 > 300 && shard_6381 < 400); } - @Test - public void testMasterSlaveShardingConsistency() { - List shards = new ArrayList(3); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT)); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1)); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2)); - Sharded sharded = new Sharded( - shards, Hashing.MURMUR_HASH); + @Test + public void testMasterSlaveShardingConsistency() { + List shards = new ArrayList(3); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT)); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1)); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2)); + Sharded sharded = new Sharded( + shards, Hashing.MURMUR_HASH); - List otherShards = new ArrayList(3); - otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT)); - otherShards.add(new JedisShardInfo("otherhost", - Protocol.DEFAULT_PORT + 1)); - otherShards.add(new JedisShardInfo("otherhost", - Protocol.DEFAULT_PORT + 2)); - Sharded sharded2 = new Sharded( - otherShards, Hashing.MURMUR_HASH); + List otherShards = new ArrayList(3); + otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT)); + otherShards.add(new JedisShardInfo("otherhost", + Protocol.DEFAULT_PORT + 1)); + otherShards.add(new JedisShardInfo("otherhost", + Protocol.DEFAULT_PORT + 2)); + Sharded sharded2 = new Sharded( + otherShards, Hashing.MURMUR_HASH); - for (int i = 0; i < 1000; i++) { - JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer - .toString(i)); - JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer - .toString(i)); - assertEquals(shards.indexOf(jedisShardInfo), - otherShards.indexOf(jedisShardInfo2)); - } + for (int i = 0; i < 1000; i++) { + JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer + .toString(i)); + JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer + .toString(i)); + assertEquals(shards.indexOf(jedisShardInfo), otherShards + .indexOf(jedisShardInfo2)); + } - } - @Test - public void testMasterSlaveShardingConsistencyWithShardNaming() { - List shards = new ArrayList(3); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT, "HOST1:1234")); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1,"HOST2:1234")); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2, "HOST3:1234")); - Sharded sharded = new Sharded( - shards, Hashing.MURMUR_HASH); + } - List otherShards = new ArrayList(3); - otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT, "HOST2:1234")); - otherShards.add(new JedisShardInfo("otherhost", - Protocol.DEFAULT_PORT + 1, "HOST3:1234")); - otherShards.add(new JedisShardInfo("otherhost", - Protocol.DEFAULT_PORT + 2, "HOST1:1234")); - Sharded sharded2 = new Sharded( - otherShards, Hashing.MURMUR_HASH); + @Test + public void testMasterSlaveShardingConsistencyWithShardNaming() { + List shards = new ArrayList(3); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT, + "HOST1:1234")); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1, + "HOST2:1234")); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2, + "HOST3:1234")); + Sharded sharded = new Sharded( + shards, Hashing.MURMUR_HASH); - for (int i = 0; i < 1000; i++) { - JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer - .toString(i)); - JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer - .toString(i)); - assertEquals(jedisShardInfo.getName(), - jedisShardInfo2.getName()); - } - - } - -} + List otherShards = new ArrayList(3); + otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT, + "HOST2:1234")); + otherShards.add(new JedisShardInfo("otherhost", + Protocol.DEFAULT_PORT + 1, "HOST3:1234")); + otherShards.add(new JedisShardInfo("otherhost", + Protocol.DEFAULT_PORT + 2, "HOST1:1234")); + Sharded sharded2 = new Sharded( + otherShards, Hashing.MURMUR_HASH); + for (int i = 0; i < 1000; i++) { + JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer + .toString(i)); + JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer + .toString(i)); + assertEquals(jedisShardInfo.getName(), jedisShardInfo2.getName()); + } + } +} \ No newline at end of file