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

@@ -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];

View File

@@ -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;
}
}
}