Added sharding benchmark and removed some imports
This commit is contained in:
@@ -12,21 +12,21 @@ import redis.clients.jedis.JedisShardInfo;
|
||||
import redis.clients.jedis.ShardedJedis;
|
||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||
import redis.clients.util.Hashing;
|
||||
import redis.clients.util.ShardInfo;
|
||||
import redis.clients.util.Sharded;
|
||||
|
||||
public class ShardedJedisTest extends Assert {
|
||||
private static HostAndPort redis1 = HostAndPortUtil.getRedisServers().get(0);
|
||||
private static HostAndPort redis2 = HostAndPortUtil.getRedisServers().get(1);
|
||||
|
||||
private static HostAndPort redis1 = HostAndPortUtil.getRedisServers()
|
||||
.get(0);
|
||||
private static HostAndPort redis2 = HostAndPortUtil.getRedisServers()
|
||||
.get(1);
|
||||
|
||||
@Test
|
||||
public void checkSharding() throws IOException {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo(redis1.host, redis1.port));
|
||||
shards.add(new JedisShardInfo(redis2.host, redis2.port));
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
ShardInfo s1 = jedis.getShardInfo("a");
|
||||
ShardInfo s2 = jedis.getShardInfo("b");
|
||||
JedisShardInfo s1 = jedis.getShardInfo("a");
|
||||
JedisShardInfo s2 = jedis.getShardInfo("b");
|
||||
assertNotSame(s1, s2);
|
||||
}
|
||||
|
||||
@@ -83,38 +83,39 @@ public class ShardedJedisTest extends Assert {
|
||||
assertEquals("bar1", j.get("b"));
|
||||
j.disconnect();
|
||||
}
|
||||
|
||||
|
||||
/** @author muriloq@gmail.com */
|
||||
@Test
|
||||
public void checkKeyTags(){
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo(redis1.host, redis1.port));
|
||||
shards.add(new JedisShardInfo(redis2.host, redis2.port));
|
||||
ShardedJedis jedis = new ShardedJedis(shards, ShardedJedis.DEFAULT_KEY_TAG_PATTERN);
|
||||
|
||||
assertEquals(jedis.getKeyTag("foo"),"foo");
|
||||
assertEquals(jedis.getKeyTag("foo{bar}"),"bar");
|
||||
assertEquals(jedis.getKeyTag("foo{bar}}"),"bar"); // default pattern is non greedy
|
||||
assertEquals(jedis.getKeyTag("{bar}foo"),"bar"); // Key tag may appear anywhere
|
||||
assertEquals(jedis.getKeyTag("f{bar}oo"),"bar"); // Key tag may appear anywhere
|
||||
|
||||
ShardInfo s1 = jedis.getShardInfo("abc{bar}");
|
||||
ShardInfo s2 = jedis.getShardInfo("foo{bar}");
|
||||
assertSame(s1, s2);
|
||||
|
||||
ShardInfo s3 = jedis.getShardInfo("a");
|
||||
ShardInfo s4 = jedis.getShardInfo("b");
|
||||
assertNotSame(s3, s4);
|
||||
|
||||
ShardedJedis jedis2 = new ShardedJedis(shards);
|
||||
|
||||
assertEquals(jedis2.getKeyTag("foo"),"foo");
|
||||
assertNotSame(jedis2.getKeyTag("foo{bar}"),"bar");
|
||||
|
||||
ShardInfo s5 = jedis2.getShardInfo("foo{bar}");
|
||||
ShardInfo s6 = jedis2.getShardInfo("abc{bar}");
|
||||
assertNotSame(s5, s6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkKeyTags() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo(redis1.host, redis1.port));
|
||||
shards.add(new JedisShardInfo(redis2.host, redis2.port));
|
||||
ShardedJedis jedis = new ShardedJedis(shards,
|
||||
ShardedJedis.DEFAULT_KEY_TAG_PATTERN);
|
||||
|
||||
assertEquals(jedis.getKeyTag("foo"), "foo");
|
||||
assertEquals(jedis.getKeyTag("foo{bar}"), "bar");
|
||||
assertEquals(jedis.getKeyTag("foo{bar}}"), "bar"); // default pattern is
|
||||
// non greedy
|
||||
assertEquals(jedis.getKeyTag("{bar}foo"), "bar"); // Key tag may appear
|
||||
// anywhere
|
||||
assertEquals(jedis.getKeyTag("f{bar}oo"), "bar"); // Key tag may appear
|
||||
// anywhere
|
||||
|
||||
JedisShardInfo s1 = jedis.getShardInfo("abc{bar}");
|
||||
JedisShardInfo s2 = jedis.getShardInfo("foo{bar}");
|
||||
assertSame(s1, s2);
|
||||
|
||||
JedisShardInfo s3 = jedis.getShardInfo("a");
|
||||
JedisShardInfo s4 = jedis.getShardInfo("b");
|
||||
assertNotSame(s3, s4);
|
||||
|
||||
ShardedJedis jedis2 = new ShardedJedis(shards);
|
||||
|
||||
assertEquals(jedis2.getKeyTag("foo"), "foo");
|
||||
assertNotSame(jedis2.getKeyTag("foo{bar}"), "bar");
|
||||
|
||||
JedisShardInfo s5 = jedis2.getShardInfo("foo{bar}");
|
||||
JedisShardInfo s6 = jedis2.getShardInfo("abc{bar}");
|
||||
assertNotSame(s5, s6);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user