Improve JedsClusterTest setup speed

This commit is contained in:
Marcos Nils
2014-02-13 22:15:28 -03:00
parent 1f7d1fda00
commit 1d0290d000

View File

@@ -11,7 +11,6 @@ import org.junit.Test;
import redis.clients.jedis.HostAndPort; import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster; import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.exceptions.JedisAskDataException; import redis.clients.jedis.exceptions.JedisAskDataException;
import redis.clients.jedis.exceptions.JedisClusterException; import redis.clients.jedis.exceptions.JedisClusterException;
import redis.clients.jedis.exceptions.JedisClusterMaxRedirectionsException; import redis.clients.jedis.exceptions.JedisClusterMaxRedirectionsException;
@@ -26,7 +25,7 @@ public class JedisClusterTest extends Assert {
private HostAndPort nodeInfo1 = HostAndPortUtil.getClusterServers().get(0); private HostAndPort nodeInfo1 = HostAndPortUtil.getClusterServers().get(0);
private HostAndPort nodeInfo2 = HostAndPortUtil.getClusterServers().get(1); private HostAndPort nodeInfo2 = HostAndPortUtil.getClusterServers().get(1);
private HostAndPort nodeInfo3 = HostAndPortUtil.getClusterServers().get(2); private HostAndPort nodeInfo3 = HostAndPortUtil.getClusterServers().get(2);
@Before @Before
public void setUp() throws InterruptedException { public void setUp() throws InterruptedException {
node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort()); node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort());
@@ -49,22 +48,23 @@ public class JedisClusterTest extends Assert {
// split available slots across the three nodes // split available slots across the three nodes
int slotsPerNode = JedisCluster.HASHSLOTS / 3; int slotsPerNode = JedisCluster.HASHSLOTS / 3;
Pipeline pipeline1 = node1.pipelined(); int[] node1Slots = new int[slotsPerNode];
Pipeline pipeline2 = node2.pipelined(); int[] node2Slots = new int[slotsPerNode+1];
Pipeline pipeline3 = node3.pipelined(); int[] node3Slots = new int[slotsPerNode];
for (int i = 0; i < JedisCluster.HASHSLOTS; i++) { for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0 ; i < JedisCluster.HASHSLOTS; i++) {
if (i < slotsPerNode) { if (i < slotsPerNode) {
pipeline1.clusterAddSlots(i); node1Slots[slot1++] = i;
} else if (i > slotsPerNode * 2) { } else if (i > slotsPerNode * 2) {
pipeline3.clusterAddSlots(i); node3Slots[slot3++] = i;
} else { } else {
pipeline2.clusterAddSlots(i); node2Slots[slot2++] = i;
} }
} }
pipeline1.sync();
pipeline2.sync(); node1.clusterAddSlots(node1Slots);
pipeline3.sync(); node2.clusterAddSlots(node2Slots);
node3.clusterAddSlots(node3Slots);
waitForClusterReady(); waitForClusterReady();
} }