MasterSlave consistency and old mode compatibility with shard names
This commit is contained in:
@@ -240,5 +240,63 @@ public class ShardedJedisTest extends Assert {
|
||||
assertTrue(shard_6380 > 300 && shard_6380 < 400);
|
||||
assertTrue(shard_6381 > 300 && shard_6381 < 400);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMasterSlaveShardingConsistency() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(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<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
|
||||
shards, Hashing.MURMUR_HASH);
|
||||
|
||||
List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(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<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testMasterSlaveShardingConsistencyWithShardNaming() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(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<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
|
||||
shards, Hashing.MURMUR_HASH);
|
||||
|
||||
List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(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<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user