Search in sources :

Example 1 with Sharded

use of redis.clients.util.Sharded in project jedis by xetorthio.

the class ShardedJedisTest method testMasterSlaveShardingConsistency.

@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));
    }
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) Sharded(redis.clients.util.Sharded) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Test(org.junit.Test)

Example 2 with Sharded

use of redis.clients.util.Sharded in project jedis by xetorthio.

the class ShardedJedisTest method testMurmurSharding.

@Test
public void testMurmurSharding() {
    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);
    int shard_6379 = 0;
    int shard_6380 = 0;
    int shard_6381 = 0;
    for (int i = 0; i < 1000; i++) {
        JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
        switch(jedisShardInfo.getPort()) {
            case 6379:
                shard_6379++;
                break;
            case 6380:
                shard_6380++;
                break;
            case 6381:
                shard_6381++;
                break;
            default:
                fail("Attempting to use a non-defined shard!!:" + jedisShardInfo);
                break;
        }
    }
    assertTrue(shard_6379 > 300 && shard_6379 < 400);
    assertTrue(shard_6380 > 300 && shard_6380 < 400);
    assertTrue(shard_6381 > 300 && shard_6381 < 400);
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) Sharded(redis.clients.util.Sharded) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Test(org.junit.Test)

Example 3 with Sharded

use of redis.clients.util.Sharded in project cachecloud by sohutv.

the class ShardedJedisTest method testMurmurSharding.

@Test
public void testMurmurSharding() {
    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);
    int shard_6379 = 0;
    int shard_6380 = 0;
    int shard_6381 = 0;
    for (int i = 0; i < 1000; i++) {
        JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
        switch(jedisShardInfo.getPort()) {
            case 6379:
                shard_6379++;
                break;
            case 6380:
                shard_6380++;
                break;
            case 6381:
                shard_6381++;
                break;
            default:
                fail("Attempting to use a non-defined shard!!:" + jedisShardInfo);
                break;
        }
    }
    assertTrue(shard_6379 > 300 && shard_6379 < 400);
    assertTrue(shard_6380 > 300 && shard_6380 < 400);
    assertTrue(shard_6381 > 300 && shard_6381 < 400);
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) Sharded(redis.clients.util.Sharded) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Test(org.junit.Test)

Example 4 with Sharded

use of redis.clients.util.Sharded in project cachecloud by sohutv.

the class ShardedJedisTest method testMasterSlaveShardingConsistencyWithShardNaming.

@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());
    }
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) Sharded(redis.clients.util.Sharded) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Test(org.junit.Test)

Example 5 with Sharded

use of redis.clients.util.Sharded in project cachecloud by sohutv.

the class ShardedJedisTest method testMD5Sharding.

@Test
public void testMD5Sharding() {
    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.MD5);
    int shard_6379 = 0;
    int shard_6380 = 0;
    int shard_6381 = 0;
    for (int i = 0; i < 1000; i++) {
        JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
        switch(jedisShardInfo.getPort()) {
            case 6379:
                shard_6379++;
                break;
            case 6380:
                shard_6380++;
                break;
            case 6381:
                shard_6381++;
                break;
            default:
                fail("Attempting to use a non-defined shard!!:" + jedisShardInfo);
                break;
        }
    }
    assertTrue(shard_6379 > 300 && shard_6379 < 400);
    assertTrue(shard_6380 > 300 && shard_6380 < 400);
    assertTrue(shard_6381 > 300 && shard_6381 < 400);
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) Sharded(redis.clients.util.Sharded) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 Jedis (redis.clients.jedis.Jedis)8 JedisShardInfo (redis.clients.jedis.JedisShardInfo)8 ShardedJedis (redis.clients.jedis.ShardedJedis)8 Sharded (redis.clients.util.Sharded)8