Search in sources :

Example 46 with GenericObjectPoolConfig

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

the class JedisSentinelPoolTest method checkResourceIsCloseable.

@Test
public void checkResourceIsCloseable() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(1);
    config.setBlockWhenExhausted(false);
    JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000, "foobared", 2);
    Jedis jedis = pool.getResource();
    try {
        jedis.set("hello", "jedis");
    } finally {
        jedis.close();
    }
    Jedis jedis2 = pool.getResource();
    try {
        assertEquals(jedis, jedis2);
    } finally {
        jedis2.close();
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisSentinelPool(redis.clients.jedis.JedisSentinelPool) Test(org.junit.Test)

Example 47 with GenericObjectPoolConfig

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

the class JedisSentinelPoolTest method ensureSafeTwiceFailover.

@Test
public void ensureSafeTwiceFailover() throws InterruptedException {
    JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, new GenericObjectPoolConfig(), 1000, "foobared", 2);
    forceFailover(pool);
    // after failover sentinel needs a bit of time to stabilize before a new
    // failover
    Thread.sleep(100);
    forceFailover(pool);
// you can test failover as much as possible
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisSentinelPool(redis.clients.jedis.JedisSentinelPool) Test(org.junit.Test)

Example 48 with GenericObjectPoolConfig

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

the class PipelineClusterTest method before.

@Before
public void before() {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxWaitMillis(2 * 1000L);
    Set<HostAndPort> nodes = new HashSet<HostAndPort>();
    //test mHgetAll
    nodes.add(new HostAndPort("127.0.0.1", 6386));
    nodes.add(new HostAndPort("127.0.0.1", 6386));
    nodes.add(new HostAndPort("127.0.0.1", 7642));
    nodes.add(new HostAndPort("127.0.0.1", 7643));
    nodes.add(new HostAndPort("127.0.0.1", 7644));
    nodes.add(new HostAndPort("127.0.0.1", 6392));
    pipelineCluster = new PipelineCluster(poolConfig, nodes);
    for (int i = 1; i < 10; i++) {
        String key = "key:" + i;
        keys.add(key);
    }
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) Before(org.junit.Before)

Example 49 with GenericObjectPoolConfig

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

the class JedisClusterTest method testIfPoolConfigAppliesToClusterPools.

@Test(expected = JedisConnectionException.class)
public void testIfPoolConfigAppliesToClusterPools() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(0);
    config.setMaxWaitMillis(2000);
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    JedisCluster jc = new JedisCluster(jedisClusterNode, config);
    jc.set("52", "poolTestValue");
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig)

Example 50 with GenericObjectPoolConfig

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

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

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