Improve Jedis Cluster tests and cleanup son they run much faster and reliable

This commit is contained in:
Marcos Nils
2014-02-14 05:31:16 -03:00
parent 1d0290d000
commit b2fa6b6c40
3 changed files with 26 additions and 17 deletions

View File

@@ -143,6 +143,7 @@ endef
define REDIS_CLUSTER_NODE1_CONF define REDIS_CLUSTER_NODE1_CONF
daemonize yes daemonize yes
port 7379 port 7379
cluster-node-timeout 50
pidfile /tmp/redis_cluster_node1.pid pidfile /tmp/redis_cluster_node1.pid
logfile /tmp/redis_cluster_node1.log logfile /tmp/redis_cluster_node1.log
save "" save ""
@@ -154,6 +155,7 @@ endef
define REDIS_CLUSTER_NODE2_CONF define REDIS_CLUSTER_NODE2_CONF
daemonize yes daemonize yes
port 7380 port 7380
cluster-node-timeout 50
pidfile /tmp/redis_cluster_node2.pid pidfile /tmp/redis_cluster_node2.pid
logfile /tmp/redis_cluster_node2.log logfile /tmp/redis_cluster_node2.log
save "" save ""
@@ -165,6 +167,7 @@ endef
define REDIS_CLUSTER_NODE3_CONF define REDIS_CLUSTER_NODE3_CONF
daemonize yes daemonize yes
port 7381 port 7381
cluster-node-timeout 50
pidfile /tmp/redis_cluster_node3.pid pidfile /tmp/redis_cluster_node3.pid
logfile /tmp/redis_cluster_node3.log logfile /tmp/redis_cluster_node3.log
save "" save ""

View File

@@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -19,8 +20,8 @@ import redis.clients.util.JedisClusterCRC16;
public class JedisClusterTest extends Assert { public class JedisClusterTest extends Assert {
private Jedis node1; private Jedis node1;
private Jedis node2; private static Jedis node2;
private Jedis node3; private static Jedis node3;
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);
@@ -67,6 +68,16 @@ public class JedisClusterTest extends Assert {
waitForClusterReady(); 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 @After
public void tearDown() { public void tearDown() {
@@ -179,7 +190,7 @@ public class JedisClusterTest extends Assert {
assertEquals(JedisClusterCRC16.getSlot("foo{bar}{zap}"), JedisClusterCRC16.getSlot("bar")); 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")) { for (String infoLine : infoOutput.split("\n")) {
if (infoLine.contains("myself")) { if (infoLine.contains("myself")) {
return infoLine.split(" ")[0]; return infoLine.split(" ")[0];

View File

@@ -40,29 +40,24 @@ public class ClusterCommandsTest extends JedisTestBase {
@AfterClass @AfterClass
public static void removeSlots() throws InterruptedException { public static void removeSlots() throws InterruptedException {
// This is to wait for gossip to replicate data.
waitForEqualClusterSize();
String[] nodes = node1.clusterNodes().split("\n"); String[] nodes = node1.clusterNodes().split("\n");
String node1Id = nodes[0].split(" ")[0]; String node1Id = nodes[0].split(" ")[0];
node1.clusterDelSlots(1, 2, 3, 4, 5, 500); node1.clusterDelSlots(1, 2, 3, 4, 5, 500);
node1.clusterSetSlotNode(5000, node1Id); node1.clusterSetSlotNode(5000, node1Id);
node1.clusterDelSlots(5000, 10000); node1.clusterDelSlots(5000, 10000);
node2.clusterDelSlots(6000, 1, 2, 3, 4, 5, 500, 5000);
node1.clusterAddSlots(6000); node1.clusterAddSlots(6000);
node1.clusterDelSlots(6000); node1.clusterDelSlots(6000);
try { waitForGossip();
node2.clusterDelSlots(10000); node2.clusterDelSlots(6000);
} catch (JedisDataException jde) { node1.clusterDelSlots(6000);
// Do nothing, slot may or may not be assigned depending on gossip
}
} }
private static void waitForEqualClusterSize() throws InterruptedException { private static void waitForGossip() {
boolean notEqualSize = true; boolean notReady = true;
while (notEqualSize) { while (notReady) {
notEqualSize = getClusterAttribute(node1.clusterInfo(), if (node1.clusterNodes().contains("6000")) {
"cluster_known_nodes") == getClusterAttribute( notReady = false;
node2.clusterInfo(), "cluster_size") ? false : true; }
} }
} }