Search in sources :

Example 36 with HostAndPort

use of redis.clients.jedis.HostAndPort in project cachecloud by sohutv.

the class ClusterScriptingCommandsTest method setUp.

@Before
public void setUp() throws InterruptedException {
    node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort());
    node1.connect();
    node1.flushAll();
    node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort());
    node2.connect();
    node2.flushAll();
    node3 = new Jedis(nodeInfo3.getHost(), nodeInfo3.getPort());
    node3.connect();
    node3.flushAll();
    // ---- configure cluster
    // add nodes to cluster
    node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
    node1.clusterMeet("127.0.0.1", nodeInfo3.getPort());
    // split available slots across the three nodes
    int slotsPerNode = JedisCluster.HASHSLOTS / 3;
    int[] node1Slots = new int[slotsPerNode];
    int[] node2Slots = new int[slotsPerNode + 1];
    int[] node3Slots = new int[slotsPerNode];
    for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0; i < JedisCluster.HASHSLOTS; i++) {
        if (i < slotsPerNode) {
            node1Slots[slot1++] = i;
        } else if (i > slotsPerNode * 2) {
            node3Slots[slot3++] = i;
        } else {
            node2Slots[slot2++] = i;
        }
    }
    node1.clusterAddSlots(node1Slots);
    node2.clusterAddSlots(node2Slots);
    node3.clusterAddSlots(node3Slots);
    waitForClusterReady();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    jedisCluster = new JedisCluster(jedisClusterNode);
}
Also used : Jedis(redis.clients.jedis.Jedis) HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) Before(org.junit.Before)

Example 37 with HostAndPort

use of redis.clients.jedis.HostAndPort in project cachecloud by sohutv.

the class ClusterBinaryJedisCommandsTest method setUp.

@Before
public void setUp() throws InterruptedException {
    node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort());
    node1.connect();
    node1.flushAll();
    node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort());
    node2.connect();
    node2.flushAll();
    node3 = new Jedis(nodeInfo3.getHost(), nodeInfo3.getPort());
    node3.connect();
    node3.flushAll();
    // ---- configure cluster
    // add nodes to cluster
    node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
    node1.clusterMeet("127.0.0.1", nodeInfo3.getPort());
    // split available slots across the three nodes
    int slotsPerNode = JedisCluster.HASHSLOTS / 3;
    int[] node1Slots = new int[slotsPerNode];
    int[] node2Slots = new int[slotsPerNode + 1];
    int[] node3Slots = new int[slotsPerNode];
    for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0; i < JedisCluster.HASHSLOTS; i++) {
        if (i < slotsPerNode) {
            node1Slots[slot1++] = i;
        } else if (i > slotsPerNode * 2) {
            node3Slots[slot3++] = i;
        } else {
            node2Slots[slot2++] = i;
        }
    }
    node1.clusterAddSlots(node1Slots);
    node2.clusterAddSlots(node2Slots);
    node3.clusterAddSlots(node3Slots);
    waitForClusterReady();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    jedisCluster = new JedisCluster(jedisClusterNode);
}
Also used : Jedis(redis.clients.jedis.Jedis) HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) Before(org.junit.Before)

Example 38 with HostAndPort

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

the class ShardedConnectionProvider method initialize.

private void initialize(List<HostAndPort> shards) {
    for (int i = 0; i < shards.size(); i++) {
        HostAndPort shard = shards.get(i);
        for (int n = 0; n < 160; n++) {
            Long hash = this.algo.hash("SHARD-" + i + "-NODE-" + n);
            nodes.put(hash, shard);
            setupNodeIfNotExist(shard);
        }
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort)

Example 39 with HostAndPort

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

the class FailoverCommandsTest method failoverToHAP.

@Test
public void failoverToHAP() throws InterruptedException {
    assumeFalse(failoverStuck);
    try (Jedis master = new Jedis(masterAddress)) {
        switching = true;
        assertEquals("OK", master.failover(FailoverParams.failoverParams().to(new HostAndPort("127.0.0.1", replicaAddress.getPort()))));
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) HostAndPort(redis.clients.jedis.HostAndPort) Test(org.junit.Test)

Example 40 with HostAndPort

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

the class ExceptionsTest method movedData.

@Test
public void movedData() {
    HostAndPort hap = new HostAndPort("", 0);
    int slot = -1;
    try {
        throw new JedisMovedDataException(MESSAGE, hap, slot);
    } catch (Exception e) {
        assertSame(JedisMovedDataException.class, e.getClass());
        assertEquals(MESSAGE, e.getMessage());
        assertNull(e.getCause());
    }
    try {
        throw new JedisMovedDataException(CAUSE, hap, slot);
    } catch (Exception e) {
        assertSame(JedisMovedDataException.class, e.getClass());
        assertEquals(CAUSE, e.getCause());
        assertEquals(CAUSE.toString(), e.getMessage());
    }
    try {
        throw new JedisMovedDataException(MESSAGE, CAUSE, hap, slot);
    } catch (Exception e) {
        assertSame(JedisMovedDataException.class, e.getClass());
        assertEquals(MESSAGE, e.getMessage());
        assertEquals(CAUSE, e.getCause());
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) Test(org.junit.Test)

Aggregations

HostAndPort (redis.clients.jedis.HostAndPort)95 Test (org.junit.Test)42 JedisCluster (redis.clients.jedis.JedisCluster)33 HashSet (java.util.HashSet)31 Jedis (redis.clients.jedis.Jedis)24 LinkedHashSet (java.util.LinkedHashSet)18 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)10 Before (org.junit.Before)9 ArrayList (java.util.ArrayList)7 JedisPool (redis.clients.jedis.JedisPool)7 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 JSONObject (com.alibaba.fastjson.JSONObject)2