Improve Jedis Cluster tests and cleanup son they run much faster and reliable
This commit is contained in:
3
Makefile
3
Makefile
@@ -143,6 +143,7 @@ endef
|
||||
define REDIS_CLUSTER_NODE1_CONF
|
||||
daemonize yes
|
||||
port 7379
|
||||
cluster-node-timeout 50
|
||||
pidfile /tmp/redis_cluster_node1.pid
|
||||
logfile /tmp/redis_cluster_node1.log
|
||||
save ""
|
||||
@@ -154,6 +155,7 @@ endef
|
||||
define REDIS_CLUSTER_NODE2_CONF
|
||||
daemonize yes
|
||||
port 7380
|
||||
cluster-node-timeout 50
|
||||
pidfile /tmp/redis_cluster_node2.pid
|
||||
logfile /tmp/redis_cluster_node2.log
|
||||
save ""
|
||||
@@ -165,6 +167,7 @@ endef
|
||||
define REDIS_CLUSTER_NODE3_CONF
|
||||
daemonize yes
|
||||
port 7381
|
||||
cluster-node-timeout 50
|
||||
pidfile /tmp/redis_cluster_node3.pid
|
||||
logfile /tmp/redis_cluster_node3.log
|
||||
save ""
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -19,8 +20,8 @@ import redis.clients.util.JedisClusterCRC16;
|
||||
|
||||
public class JedisClusterTest extends Assert {
|
||||
private Jedis node1;
|
||||
private Jedis node2;
|
||||
private Jedis node3;
|
||||
private static Jedis node2;
|
||||
private static Jedis node3;
|
||||
|
||||
private HostAndPort nodeInfo1 = HostAndPortUtil.getClusterServers().get(0);
|
||||
private HostAndPort nodeInfo2 = HostAndPortUtil.getClusterServers().get(1);
|
||||
@@ -67,6 +68,16 @@ public class JedisClusterTest extends Assert {
|
||||
|
||||
waitForClusterReady();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
int slotTest = JedisClusterCRC16.getSlot("test");
|
||||
int slot51 = JedisClusterCRC16.getSlot("51");
|
||||
String node3Id = getNodeId(node3.clusterNodes());
|
||||
node2.clusterSetSlotNode(slotTest, node3Id);
|
||||
node2.clusterSetSlotNode(slot51, node3Id);
|
||||
node2.clusterDelSlots(slotTest, slot51);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@@ -179,7 +190,7 @@ public class JedisClusterTest extends Assert {
|
||||
assertEquals(JedisClusterCRC16.getSlot("foo{bar}{zap}"), JedisClusterCRC16.getSlot("bar"));
|
||||
}
|
||||
|
||||
private String getNodeId(String infoOutput) {
|
||||
private static String getNodeId(String infoOutput) {
|
||||
for (String infoLine : infoOutput.split("\n")) {
|
||||
if (infoLine.contains("myself")) {
|
||||
return infoLine.split(" ")[0];
|
||||
|
||||
@@ -40,29 +40,24 @@ public class ClusterCommandsTest extends JedisTestBase {
|
||||
|
||||
@AfterClass
|
||||
public static void removeSlots() throws InterruptedException {
|
||||
// This is to wait for gossip to replicate data.
|
||||
waitForEqualClusterSize();
|
||||
String[] nodes = node1.clusterNodes().split("\n");
|
||||
String node1Id = nodes[0].split(" ")[0];
|
||||
node1.clusterDelSlots(1, 2, 3, 4, 5, 500);
|
||||
node1.clusterSetSlotNode(5000, node1Id);
|
||||
node1.clusterDelSlots(5000, 10000);
|
||||
node2.clusterDelSlots(6000, 1, 2, 3, 4, 5, 500, 5000);
|
||||
node1.clusterAddSlots(6000);
|
||||
node1.clusterDelSlots(6000);
|
||||
try {
|
||||
node2.clusterDelSlots(10000);
|
||||
} catch (JedisDataException jde) {
|
||||
// Do nothing, slot may or may not be assigned depending on gossip
|
||||
}
|
||||
waitForGossip();
|
||||
node2.clusterDelSlots(6000);
|
||||
node1.clusterDelSlots(6000);
|
||||
}
|
||||
|
||||
private static void waitForEqualClusterSize() throws InterruptedException {
|
||||
boolean notEqualSize = true;
|
||||
while (notEqualSize) {
|
||||
notEqualSize = getClusterAttribute(node1.clusterInfo(),
|
||||
"cluster_known_nodes") == getClusterAttribute(
|
||||
node2.clusterInfo(), "cluster_size") ? false : true;
|
||||
private static void waitForGossip() {
|
||||
boolean notReady = true;
|
||||
while (notReady) {
|
||||
if (node1.clusterNodes().contains("6000")) {
|
||||
notReady = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user