Improve JedsClusterTest setup speed
This commit is contained in:
@@ -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;
|
||||||
@@ -49,21 +48,22 @@ 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();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user