Search in sources :

Example 16 with JedisShardInfo

use of redis.clients.jedis.JedisShardInfo in project jedis by xetorthio.

the class ShardedJedisPoolTest method returnResourceShouldResetState.

@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("redis://:foobared@localhost:6379")));
    ShardedJedisPool pool = new ShardedJedisPool(config, shards);
    ShardedJedis jedis = pool.getResource();
    jedis.set("pipelined", String.valueOf(0));
    jedis.set("pipelined2", String.valueOf(0));
    ShardedJedisPipeline pipeline = jedis.pipelined();
    pipeline.incr("pipelined");
    pipeline.incr("pipelined2");
    jedis.resetState();
    pipeline = jedis.pipelined();
    pipeline.incr("pipelined");
    pipeline.incr("pipelined2");
    List<Object> results = pipeline.syncAndReturnAll();
    assertEquals(2, results.size());
    jedis.close();
    pool.destroy();
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedis(redis.clients.jedis.ShardedJedis) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) ArrayList(java.util.ArrayList) ShardedJedisPipeline(redis.clients.jedis.ShardedJedisPipeline) JedisShardInfo(redis.clients.jedis.JedisShardInfo) URI(java.net.URI) Test(org.junit.Test)

Example 17 with JedisShardInfo

use of redis.clients.jedis.JedisShardInfo in project jedis by xetorthio.

the class ShardedJedisPoolTest method shouldReturnActiveShardsWhenOneGoesOffline.

@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");
    }
    jedis.close();
    // 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("localhost", 1234));
    pool = new ShardedJedisPool(redisConfig, shards);
    jedis = pool.getResource();
    Long actual = Long.valueOf(0);
    Long fails = Long.valueOf(0);
    for (int i = 0; i < 1000; i++) {
        try {
            jedis.get("a-test-" + i);
            actual++;
        } catch (RuntimeException e) {
            fails++;
        }
    }
    jedis.close();
    pool.destroy();
    assertEquals(actual, c1);
    assertEquals(fails, c2);
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedis(redis.clients.jedis.ShardedJedis) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Test(org.junit.Test)

Example 18 with JedisShardInfo

use of redis.clients.jedis.JedisShardInfo in project jedis by xetorthio.

the class ShardedJedisPoolTest method startUp.

@Before
public void startUp() {
    shards = new ArrayList<JedisShardInfo>();
    shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
    shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
    shards.get(0).setPassword("foobared");
    shards.get(1).setPassword("foobared");
    Jedis j = new Jedis(shards.get(0));
    j.connect();
    j.flushAll();
    j.disconnect();
    j = new Jedis(shards.get(1));
    j.connect();
    j.flushAll();
    j.disconnect();
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Before(org.junit.Before)

Example 19 with JedisShardInfo

use of redis.clients.jedis.JedisShardInfo 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 20 with JedisShardInfo

use of redis.clients.jedis.JedisShardInfo in project jedis by xetorthio.

the class ShardedJedisTest method checkSharding.

@Test
public void checkSharding() {
    List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
    shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
    shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
    ShardedJedis jedis = new ShardedJedis(shards);
    List<String> keys = getKeysDifferentShard(jedis);
    JedisShardInfo s1 = jedis.getShardInfo(keys.get(0));
    JedisShardInfo s2 = jedis.getShardInfo(keys.get(1));
    assertNotSame(s1, s2);
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Test(org.junit.Test)

Aggregations

JedisShardInfo (redis.clients.jedis.JedisShardInfo)51 Test (org.junit.Test)40 ShardedJedis (redis.clients.jedis.ShardedJedis)38 ArrayList (java.util.ArrayList)36 Jedis (redis.clients.jedis.Jedis)36 URI (java.net.URI)13 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)10 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)10 Sharded (redis.clients.util.Sharded)8 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)6 Before (org.junit.Before)6 SSLParameters (javax.net.ssl.SSLParameters)5 ShardedJedisPipeline (redis.clients.jedis.ShardedJedisPipeline)4 HostnameVerifier (javax.net.ssl.HostnameVerifier)3 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)3 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)2 BinaryJedis (redis.clients.jedis.BinaryJedis)2 EndPointAccessor (com.navercorp.pinpoint.plugin.redis.EndPointAccessor)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 CertificateException (java.security.cert.CertificateException)1