Search in sources :

Example 56 with HostAndPort

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

the class JedisClusterTest method testJedisClusterTimeout.

@Test
public void testJedisClusterTimeout() {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
    JedisCluster jc = new JedisCluster(jedisClusterNode, 4000, 4000, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
    for (JedisPool pool : jc.getClusterNodes().values()) {
        Jedis jedis = pool.getResource();
        assertEquals(jedis.getClient().getConnectionTimeout(), 4000);
        assertEquals(jedis.getClient().getSoTimeout(), 4000);
        jedis.close();
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) Jedis(redis.clients.jedis.Jedis) JedisCluster(redis.clients.jedis.JedisCluster) JedisPool(redis.clients.jedis.JedisPool) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 57 with HostAndPort

use of redis.clients.jedis.HostAndPort 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 58 with HostAndPort

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

the class JedisClusterTest method testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified.

@Test
public void testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified() throws InterruptedException {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
    JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
    int slot51 = JedisClusterCRC16.getSlot("51");
    jc.set("51", "foo");
    // node2 is responsible of taking care of slot51 (7186)
    node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
    assertEquals("foo", jc.get("51"));
    node3.clusterSetSlotStable(slot51);
    assertEquals("foo", jc.get("51"));
    node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
    // assertEquals("foo", jc.get("51")); // it leads Max Redirections
    node2.clusterSetSlotStable(slot51);
    assertEquals("foo", jc.get("51"));
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 59 with HostAndPort

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

the class JedisClusterTest method testDiscoverNodesAutomatically.

@Test
public void testDiscoverNodesAutomatically() {
    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", DEFAULT_CONFIG);
    assertEquals(3, jc.getClusterNodes().size());
    JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 7379), DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
    assertEquals(3, jc2.getClusterNodes().size());
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 60 with HostAndPort

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

the class JedisClusterTest method testInvalidStartNodeNotAdded.

@Test
public void testInvalidStartNodeNotAdded() {
    HostAndPort invalidHost = new HostAndPort("not-a-real-host", 7379);
    Set<HostAndPort> jedisClusterNode = new LinkedHashSet<HostAndPort>();
    jedisClusterNode.add(invalidHost);
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    JedisPoolConfig config = DEFAULT_CONFIG;
    config.setMaxTotal(1);
    JedisCluster jc = new JedisCluster(jedisClusterNode, 0, 2, DEFAULT_REDIRECTIONS, "cluster", config);
    Map<String, JedisPool> clusterNodes = jc.getClusterNodes();
    assertEquals(3, clusterNodes.size());
    assertFalse(clusterNodes.containsKey(JedisClusterInfoCache.getNodeKey(invalidHost)));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Test(org.junit.Test)

Aggregations

HostAndPort (redis.clients.jedis.HostAndPort)102 Test (org.junit.Test)42 HashSet (java.util.HashSet)35 JedisCluster (redis.clients.jedis.JedisCluster)35 Jedis (redis.clients.jedis.Jedis)25 LinkedHashSet (java.util.LinkedHashSet)18 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)12 Before (org.junit.Before)9 JedisPool (redis.clients.jedis.JedisPool)9 ArrayList (java.util.ArrayList)8 ClusterNodeInformation (redis.clients.util.ClusterNodeInformation)6 AppDesc (com.sohu.cache.entity.AppDesc)5 InstanceInfo (com.sohu.cache.entity.InstanceInfo)5 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)5 IOException (java.io.IOException)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 JedisPubSub (redis.clients.jedis.JedisPubSub)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Properties (java.util.Properties)3