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);
}
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);
}
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);
}
}
}
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()))));
}
}
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());
}
}
Aggregations