Search in sources :

Example 71 with GenericObjectPoolConfig

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project jedis by xetorthio.

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

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project jedis by xetorthio.

the class JedisSentinelPoolTest method returnResourceShouldResetState.

@Test
public void returnResourceShouldResetState() {
    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();
    Jedis jedis2 = null;
    try {
        jedis.set("hello", "jedis");
        Transaction t = jedis.multi();
        t.set("hello", "world");
        jedis.close();
        jedis2 = pool.getResource();
        assertTrue(jedis == jedis2);
        assertEquals("jedis", jedis2.get("hello"));
    } catch (JedisConnectionException e) {
        if (jedis2 != null) {
            jedis2 = null;
        }
    } finally {
        jedis2.close();
        pool.destroy();
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisSentinelPool(redis.clients.jedis.JedisSentinelPool) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Test(org.junit.Test)

Example 73 with GenericObjectPoolConfig

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project jedis by xetorthio.

the class JedisClusterTest method testIfPoolConfigAppliesToClusterPools.

@Test(expected = JedisExhaustedPoolException.class)
public void testIfPoolConfigAppliesToClusterPools() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(0);
    config.setMaxWaitMillis(DEFAULT_TIMEOUT);
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", config);
    jc.set("52", "poolTestValue");
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisCluster(redis.clients.jedis.JedisCluster) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 74 with GenericObjectPoolConfig

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project jedis by xetorthio.

the class JedisPoolTest method returnResourceShouldResetState.

@Test
public void returnResourceShouldResetState() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(1);
    config.setBlockWhenExhausted(false);
    JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000, "foobared");
    Jedis jedis = pool.getResource();
    try {
        jedis.set("hello", "jedis");
        Transaction t = jedis.multi();
        t.set("hello", "world");
    } finally {
        jedis.close();
    }
    Jedis jedis2 = pool.getResource();
    try {
        assertTrue(jedis == jedis2);
        assertEquals("jedis", jedis2.get("hello"));
    } finally {
        jedis2.close();
    }
    pool.destroy();
    assertTrue(pool.isClosed());
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisPool(redis.clients.jedis.JedisPool) Test(org.junit.Test)

Example 75 with GenericObjectPoolConfig

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project jedis by xetorthio.

the class JedisPoolTest method checkPoolOverflow.

@Test(expected = JedisExhaustedPoolException.class)
public void checkPoolOverflow() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(1);
    config.setBlockWhenExhausted(false);
    JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort());
    Jedis jedis = pool.getResource();
    jedis.auth("foobared");
    jedis.set("foo", "0");
    Jedis newJedis = pool.getResource();
    newJedis.auth("foobared");
    newJedis.incr("foo");
}
Also used : Jedis(redis.clients.jedis.Jedis) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisPool(redis.clients.jedis.JedisPool) Test(org.junit.Test)

Aggregations

GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)127 Test (org.junit.Test)77 Jedis (redis.clients.jedis.Jedis)41 ShardedJedis (redis.clients.jedis.ShardedJedis)40 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)40 JedisPool (redis.clients.jedis.JedisPool)31 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)19 ArrayList (java.util.ArrayList)15 JedisShardInfo (redis.clients.jedis.JedisShardInfo)15 URI (java.net.URI)11 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)9 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 BaseTest (com.sohu.tv.test.base.BaseTest)6 IOException (java.io.IOException)6 Transaction (redis.clients.jedis.Transaction)6 PoolableConnectionFactory (org.apache.commons.dbcp2.PoolableConnectionFactory)5 PooledObject (org.apache.commons.pool2.PooledObject)5 DefaultPooledObject (org.apache.commons.pool2.impl.DefaultPooledObject)5 Test (org.testng.annotations.Test)5