Search in sources :

Example 36 with JedisPoolConfig

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

the class JedisClusterTest method testLocalhostNodeNotAddedWhen127Present.

@Test
public void testLocalhostNodeNotAddedWhen127Present() {
    HostAndPort localhost = new HostAndPort("localhost", 7379);
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    // cluster node is defined as 127.0.0.1; adding localhost should work,
    // but shouldn't show up.
    jedisClusterNode.add(localhost);
    JedisPoolConfig config = DEFAULT_CONFIG;
    config.setMaxTotal(1);
    JedisCluster jc = new JedisCluster(jedisClusterNode, 0, 2, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
    Map<String, JedisPool> clusterNodes = jc.getClusterNodes();
    assertEquals(3, clusterNodes.size());
    assertFalse(clusterNodes.containsKey(JedisClusterInfoCache.getNodeKey(localhost)));
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 37 with JedisPoolConfig

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

the class JedisPoolTest method nonDefaultDatabase.

@Test
public void nonDefaultDatabase() {
    JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "foobared");
    Jedis jedis0 = pool0.getResource();
    jedis0.set("foo", "bar");
    assertEquals("bar", jedis0.get("foo"));
    jedis0.close();
    pool0.destroy();
    assertTrue(pool0.isClosed());
    JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "foobared", 1);
    Jedis jedis1 = pool1.getResource();
    assertNull(jedis1.get("foo"));
    jedis1.close();
    pool1.destroy();
    assertTrue(pool1.isClosed());
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Test(org.junit.Test)

Example 38 with JedisPoolConfig

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

the class JedisPoolTest method checkPoolRepairedWhenJedisIsBroken.

@Test
public void checkPoolRepairedWhenJedisIsBroken() {
    JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
    Jedis jedis = pool.getResource();
    jedis.auth("foobared");
    jedis.quit();
    jedis.close();
    jedis = pool.getResource();
    jedis.auth("foobared");
    jedis.incr("foo");
    jedis.close();
    pool.destroy();
    assertTrue(pool.isClosed());
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Test(org.junit.Test)

Example 39 with JedisPoolConfig

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

the class JedisPoolTest method getNumActiveReturnsTheCorrectNumber.

@Test
public void getNumActiveReturnsTheCorrectNumber() {
    JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
    Jedis jedis = pool.getResource();
    jedis.auth("foobared");
    jedis.set("foo", "bar");
    assertEquals("bar", jedis.get("foo"));
    assertEquals(1, pool.getNumActive());
    Jedis jedis2 = pool.getResource();
    jedis.auth("foobared");
    jedis.set("foo", "bar");
    assertEquals(2, pool.getNumActive());
    jedis.close();
    assertEquals(1, pool.getNumActive());
    jedis2.close();
    assertEquals(0, pool.getNumActive());
    pool.destroy();
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Test(org.junit.Test)

Example 40 with JedisPoolConfig

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

the class JedisPoolTest method testCloseConnectionOnMakeObject.

@Test
public void testCloseConnectionOnMakeObject() {
    JedisPoolConfig config = new JedisPoolConfig();
    config.setTestOnBorrow(true);
    JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "wrong pass");
    Jedis jedis = new Jedis("redis://:foobared@localhost:6379/");
    int currentClientCount = getClientCount(jedis.clientList());
    try {
        pool.getResource();
        fail("Should throw exception as password is incorrect.");
    } catch (Exception e) {
        assertEquals(currentClientCount, getClientCount(jedis.clientList()));
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) URISyntaxException(java.net.URISyntaxException) JedisException(redis.clients.jedis.exceptions.JedisException) InvalidURIException(redis.clients.jedis.exceptions.InvalidURIException) JedisExhaustedPoolException(redis.clients.jedis.exceptions.JedisExhaustedPoolException) Test(org.junit.Test)

Aggregations

JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)55 JedisPool (redis.clients.jedis.JedisPool)40 Test (org.junit.Test)31 Jedis (redis.clients.jedis.Jedis)29 HostAndPort (redis.clients.jedis.HostAndPort)7 JedisCluster (redis.clients.jedis.JedisCluster)7 LinkedHashSet (java.util.LinkedHashSet)4 HashSet (java.util.HashSet)3 RedisTicketRegistryProperties (org.apereo.cas.configuration.model.support.redis.RedisTicketRegistryProperties)3 URISyntaxException (java.net.URISyntaxException)2 Before (org.junit.Before)2 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)2 InvalidURIException (redis.clients.jedis.exceptions.InvalidURIException)2 JedisException (redis.clients.jedis.exceptions.JedisException)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 JedisPool (io.leopard.redis.JedisPool)1 RedisConnectionListener (io.leopard.redis.RedisConnectionListener)1 IOException (java.io.IOException)1 BeanWrapper (org.springframework.beans.BeanWrapper)1 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)1