Search in sources :

Example 6 with ShardedJedis

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

the class ShardedJedisPoolTest method checkCloseableConnections.

@Test
public void checkCloseableConnections() throws Exception {
    ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
    ShardedJedis jedis = pool.getResource();
    jedis.set("foo", "bar");
    assertEquals("bar", jedis.get("foo"));
    jedis.close();
    pool.close();
    assertTrue(pool.isClosed());
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedis(redis.clients.jedis.ShardedJedis) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) Test(org.junit.Test)

Example 7 with ShardedJedis

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

the class ShardedJedisPoolTest method checkFailedJedisServer.

@Test
public void checkFailedJedisServer() {
    ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
    ShardedJedis jedis = pool.getResource();
    jedis.incr("foo");
    jedis.close();
    pool.destroy();
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedis(redis.clients.jedis.ShardedJedis) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) Test(org.junit.Test)

Example 8 with ShardedJedis

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

the class ShardedJedisPoolTest method shouldNotShareInstances.

@Test
public void shouldNotShareInstances() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(2);
    ShardedJedisPool pool = new ShardedJedisPool(config, shards);
    ShardedJedis j1 = pool.getResource();
    ShardedJedis j2 = pool.getResource();
    assertNotSame(j1.getShard("foo"), j2.getShard("foo"));
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedis(redis.clients.jedis.ShardedJedis) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) Test(org.junit.Test)

Example 9 with ShardedJedis

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

the class ShardedJedisPoolTest method checkJedisIsReusedWhenReturned.

@Test
public void checkJedisIsReusedWhenReturned() {
    ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
    ShardedJedis jedis = pool.getResource();
    jedis.set("foo", "0");
    jedis.close();
    jedis = pool.getResource();
    jedis.incr("foo");
    jedis.close();
    pool.destroy();
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedis(redis.clients.jedis.ShardedJedis) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) Test(org.junit.Test)

Example 10 with ShardedJedis

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

the class ShardedJedisPoolTest method checkConnections.

@Test
public void checkConnections() {
    ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
    ShardedJedis jedis = pool.getResource();
    jedis.set("foo", "bar");
    assertEquals("bar", jedis.get("foo"));
    jedis.close();
    pool.destroy();
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedis(redis.clients.jedis.ShardedJedis) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) Test(org.junit.Test)

Aggregations

ShardedJedis (redis.clients.jedis.ShardedJedis)45 Test (org.junit.Test)36 JedisShardInfo (redis.clients.jedis.JedisShardInfo)24 ArrayList (java.util.ArrayList)22 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)22 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)22 Jedis (redis.clients.jedis.Jedis)14 URI (java.net.URI)4 ShardedJedisPipeline (redis.clients.jedis.ShardedJedisPipeline)4 Serializable (java.io.Serializable)2 Before (org.junit.Before)2