Move Jedis CRC16 util as it's being used in the project.

Changed Makefile to cleanup redis cluster node configuration before running tests
Add cleanup to ClusterCommandTest.
This commit is contained in:
Marcos Nils
2014-01-14 15:57:53 -03:00
parent 33716e237c
commit 4ab8ea2ef7
5 changed files with 45 additions and 8 deletions

View File

@@ -145,7 +145,7 @@ export REDIS_CLUSTER_NODE1_CONF
export REDIS_CLUSTER_NODE2_CONF
export REDIS_CLUSTER_NODE3_CONF
start:
start: cleanup
echo "$$REDIS1_CONF" | redis-server -
echo "$$REDIS2_CONF" | redis-server -
echo "$$REDIS3_CONF" | redis-server -
@@ -161,6 +161,9 @@ start:
echo "$$REDIS_CLUSTER_NODE2_CONF" | redis-server -
echo "$$REDIS_CLUSTER_NODE3_CONF" | redis-server -
cleanup:
rm -vf /tmp/redis_cluster_node*.conf
stop:
kill `cat /tmp/redis1.pid`
kill `cat /tmp/redis2.pid`

View File

@@ -3,7 +3,7 @@ package redis.clients.jedis;
import redis.clients.jedis.exceptions.JedisAskDataException;
import redis.clients.jedis.exceptions.JedisClusterException;
import redis.clients.jedis.exceptions.JedisMovedDataException;
import redis.clients.jedis.tests.utils.JedisClusterCRC16;
import redis.clients.util.JedisClusterCRC16;
public abstract class JedisClusterCommand<T> {

View File

@@ -1,4 +1,4 @@
package redis.clients.jedis.tests.utils;
package redis.clients.util;
public class JedisClusterCRC16 {
public final static int polynomial = 0x1021; // Represents x^16+x^12+x^5+1

View File

@@ -15,7 +15,7 @@ import redis.clients.jedis.Pipeline;
import redis.clients.jedis.exceptions.JedisAskDataException;
import redis.clients.jedis.exceptions.JedisClusterException;
import redis.clients.jedis.exceptions.JedisMovedDataException;
import redis.clients.jedis.tests.utils.JedisClusterCRC16;
import redis.clients.util.JedisClusterCRC16;
public class JedisClusterTest extends Assert {
private Jedis node1;
@@ -174,7 +174,7 @@ public class JedisClusterTest extends Assert {
node3.clusterInfo().split("\n")[0].contains("ok") ) {
clusterOk = true;
}
Thread.sleep(100);
Thread.sleep(50);
}
}

View File

@@ -3,6 +3,7 @@ package redis.clients.jedis.tests.commands;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
@@ -12,8 +13,8 @@ import redis.clients.jedis.tests.HostAndPortUtil;
import redis.clients.jedis.tests.JedisTestBase;
public class ClusterCommandsTest extends JedisTestBase {
private Jedis node1;
private Jedis node2;
private static Jedis node1;
private static Jedis node2;
private HostAndPort nodeInfo1 = HostAndPortUtil.getClusterServers().get(0);
private HostAndPort nodeInfo2 = HostAndPortUtil.getClusterServers().get(1);
@@ -35,8 +36,41 @@ public class ClusterCommandsTest extends JedisTestBase {
node1.disconnect();
node2.disconnect();
}
@AfterClass
public static void removeSlots() throws InterruptedException {
//This is to wait for gossip to replicate data.
waitForEqualClusterSize();
System.out.println(node1.clusterInfo());
System.out.println(node2.clusterInfo());
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);
node1.clusterDelSlots(6000);
node2.clusterDelSlots(6000,1,2,3,4,5,500,5000);
System.out.println(node1.clusterNodes());
System.out.println(node2.clusterNodes());
}
@Test
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 int getClusterAttribute(String clusterInfo, String attributeName) {
for (String infoElement: clusterInfo.split("\n")) {
if (infoElement.contains(attributeName)) {
return Integer.valueOf(infoElement.split(":")[1].trim());
}
}
return 0;
}
@Test
public void clusterNodes() {
String nodes = node1.clusterNodes();
assertTrue(nodes.split("\n").length > 0);