From b2fa6b6c405db7cb0a27167524e21f541fa79b47 Mon Sep 17 00:00:00 2001 From: Marcos Nils Date: Fri, 14 Feb 2014 05:31:16 -0300 Subject: [PATCH] Improve Jedis Cluster tests and cleanup son they run much faster and reliable --- Makefile | 3 +++ .../clients/jedis/tests/JedisClusterTest.java | 17 +++++++++++--- .../tests/commands/ClusterCommandsTest.java | 23 ++++++++----------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 6a4a77d..3485047 100644 --- a/Makefile +++ b/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 "" diff --git a/src/test/java/redis/clients/jedis/tests/JedisClusterTest.java b/src/test/java/redis/clients/jedis/tests/JedisClusterTest.java index 2913403..c138e8d 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisClusterTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisClusterTest.java @@ -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]; diff --git a/src/test/java/redis/clients/jedis/tests/commands/ClusterCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ClusterCommandsTest.java index fb6264f..03ebc89 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ClusterCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ClusterCommandsTest.java @@ -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; + } } }