Search in sources :

Example 51 with GenericObjectPoolConfig

use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project cachecloud by sohutv.

the class ShardedJedisPoolTest method startWithUrl.

@Test
public void startWithUrl() throws URISyntaxException {
    Jedis j = new Jedis("localhost", 6380);
    j.auth("foobared");
    j.set("foo", "bar");
    j = new Jedis("localhost", 6379);
    j.auth("foobared");
    j.set("foo", "bar");
    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")));
    GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig();
    ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
    Jedis[] jedises = pool.getResource().getAllShards().toArray(new Jedis[2]);
    Jedis jedis = jedises[0];
    assertEquals("PONG", jedis.ping());
    assertEquals("bar", jedis.get("foo"));
    jedis = jedises[1];
    assertEquals("PONG", jedis.ping());
    assertEquals("bar", jedis.get("foo"));
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) URI(java.net.URI) Test(org.junit.Test)

Example 52 with GenericObjectPoolConfig

use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project cachecloud by sohutv.

the class ShardedJedisPoolTest method checkConnectionWithDefaultPort.

@Test
public void checkConnectionWithDefaultPort() {
    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)

Example 53 with GenericObjectPoolConfig

use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project cachecloud by sohutv.

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 54 with GenericObjectPoolConfig

use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project jedis by xetorthio.

the class ShardedJedisPoolTest method checkConnectionWithDefaultPort.

@Test
public void checkConnectionWithDefaultPort() {
    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)

Example 55 with GenericObjectPoolConfig

use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project jedis by xetorthio.

the class ShardedJedisPoolTest method startWithUrl.

@Test
public void startWithUrl() throws URISyntaxException {
    Jedis j = new Jedis("localhost", 6380);
    j.auth("foobared");
    j.set("foo", "bar");
    j = new Jedis("localhost", 6379);
    j.auth("foobared");
    j.set("foo", "bar");
    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")));
    GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig();
    ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
    Jedis[] jedises = pool.getResource().getAllShards().toArray(new Jedis[2]);
    Jedis jedis = jedises[0];
    assertEquals("PONG", jedis.ping());
    assertEquals("bar", jedis.get("foo"));
    jedis = jedises[1];
    assertEquals("PONG", jedis.ping());
    assertEquals("bar", jedis.get("foo"));
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) URI(java.net.URI) Test(org.junit.Test)

Aggregations

GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)69 Test (org.junit.Test)50 Jedis (redis.clients.jedis.Jedis)26 ShardedJedis (redis.clients.jedis.ShardedJedis)26 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)26 JedisPool (redis.clients.jedis.JedisPool)17 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)12 ArrayList (java.util.ArrayList)10 JedisShardInfo (redis.clients.jedis.JedisShardInfo)10 URI (java.net.URI)7 Test (org.testng.annotations.Test)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Transaction (redis.clients.jedis.Transaction)4 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)4 BaseTest (com.sohu.tv.test.base.BaseTest)3 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)3 LoadingCacheTest (com.alicp.jetcache.LoadingCacheTest)2 RefreshCacheTest (com.alicp.jetcache.RefreshCacheTest)2 AbstractExternalCacheTest (com.alicp.jetcache.test.external.AbstractExternalCacheTest)2 URISyntaxException (java.net.URISyntaxException)2