Add support for cluster reset command. Some tests were refactored per the inclusion of the new command
This commit is contained in:
@@ -8,6 +8,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import redis.clients.jedis.JedisCluster.Reset;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
public class Client extends BinaryClient implements Commands {
|
public class Client extends BinaryClient implements Commands {
|
||||||
@@ -911,6 +912,10 @@ public class Client extends BinaryClient implements Commands {
|
|||||||
cluster(Protocol.CLUSTER_MEET, ip, String.valueOf(port));
|
cluster(Protocol.CLUSTER_MEET, ip, String.valueOf(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clusterReset(Reset resetType) {
|
||||||
|
cluster(Protocol.CLUSTER_RESET, resetType.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public void clusterAddSlots(final int... slots) {
|
public void clusterAddSlots(final int... slots) {
|
||||||
cluster(Protocol.CLUSTER_ADDSLOTS, slots);
|
cluster(Protocol.CLUSTER_ADDSLOTS, slots);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package redis.clients.jedis;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import redis.clients.jedis.JedisCluster.Reset;
|
||||||
|
|
||||||
public interface ClusterCommands {
|
public interface ClusterCommands {
|
||||||
String clusterNodes();
|
String clusterNodes();
|
||||||
|
|
||||||
@@ -40,4 +42,6 @@ public interface ClusterCommands {
|
|||||||
String clusterFailover();
|
String clusterFailover();
|
||||||
|
|
||||||
List<Object> clusterSlots();
|
List<Object> clusterSlots();
|
||||||
|
|
||||||
|
String clusterReset(Reset resetType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,22 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
|
import redis.clients.jedis.JedisCluster.Reset;
|
||||||
import redis.clients.util.Pool;
|
import redis.clients.util.Pool;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
import redis.clients.util.Slowlog;
|
import redis.clients.util.Slowlog;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
public class Jedis extends BinaryJedis implements JedisCommands,
|
public class Jedis extends BinaryJedis implements JedisCommands,
|
||||||
MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands,
|
MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands,
|
||||||
BasicCommands, ClusterCommands {
|
BasicCommands, ClusterCommands {
|
||||||
@@ -3299,6 +3307,12 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
|||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String clusterReset(final Reset resetType) {
|
||||||
|
checkIsInMulti();
|
||||||
|
client.clusterReset(resetType);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
public String clusterAddSlots(final int... slots) {
|
public String clusterAddSlots(final int... slots) {
|
||||||
checkIsInMulti();
|
checkIsInMulti();
|
||||||
client.clusterAddSlots(slots);
|
client.clusterAddSlots(slots);
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
|||||||
private static final int DEFAULT_TIMEOUT = 1;
|
private static final int DEFAULT_TIMEOUT = 1;
|
||||||
private static final int DEFAULT_MAX_REDIRECTIONS = 5;
|
private static final int DEFAULT_MAX_REDIRECTIONS = 5;
|
||||||
|
|
||||||
|
public static enum Reset {SOFT, HARD}
|
||||||
|
|
||||||
private int timeout;
|
private int timeout;
|
||||||
private int maxRedirections;
|
private int maxRedirections;
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ public final class Protocol {
|
|||||||
|
|
||||||
public static final String CLUSTER_NODES = "nodes";
|
public static final String CLUSTER_NODES = "nodes";
|
||||||
public static final String CLUSTER_MEET = "meet";
|
public static final String CLUSTER_MEET = "meet";
|
||||||
|
public static final String CLUSTER_RESET = "reset";
|
||||||
public static final String CLUSTER_ADDSLOTS = "addslots";
|
public static final String CLUSTER_ADDSLOTS = "addslots";
|
||||||
public static final String CLUSTER_DELSLOTS = "delslots";
|
public static final String CLUSTER_DELSLOTS = "delslots";
|
||||||
public static final String CLUSTER_INFO = "info";
|
public static final String CLUSTER_INFO = "info";
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ public class HostAndPortUtil {
|
|||||||
clusterHostAndPortList.add(new HostAndPort("localhost", 7382));
|
clusterHostAndPortList.add(new HostAndPort("localhost", 7382));
|
||||||
clusterHostAndPortList.add(new HostAndPort("localhost", 7383));
|
clusterHostAndPortList.add(new HostAndPort("localhost", 7383));
|
||||||
clusterHostAndPortList.add(new HostAndPort("localhost", 7384));
|
clusterHostAndPortList.add(new HostAndPort("localhost", 7384));
|
||||||
clusterHostAndPortList.add(new HostAndPort("localhost", 7385));
|
|
||||||
|
|
||||||
String envRedisHosts = System.getProperty("redis-hosts");
|
String envRedisHosts = System.getProperty("redis-hosts");
|
||||||
String envSentinelHosts = System.getProperty("sentinel-hosts");
|
String envSentinelHosts = System.getProperty("sentinel-hosts");
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import redis.clients.jedis.HostAndPort;
|
import redis.clients.jedis.HostAndPort;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.exceptions.JedisDataException;
|
import redis.clients.jedis.JedisCluster.Reset;
|
||||||
import redis.clients.jedis.tests.HostAndPortUtil;
|
import redis.clients.jedis.tests.HostAndPortUtil;
|
||||||
import redis.clients.jedis.tests.JedisTestBase;
|
import redis.clients.jedis.tests.JedisTestBase;
|
||||||
|
import redis.clients.jedis.tests.utils.JedisClusterTestUtil;
|
||||||
|
|
||||||
public class ClusterCommandsTest extends JedisTestBase {
|
public class ClusterCommandsTest extends JedisTestBase {
|
||||||
private static Jedis node1;
|
private static Jedis node1;
|
||||||
@@ -42,16 +43,8 @@ public class ClusterCommandsTest extends JedisTestBase {
|
|||||||
public static void removeSlots() throws InterruptedException {
|
public static void removeSlots() throws InterruptedException {
|
||||||
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.clusterReset(Reset.SOFT);
|
||||||
node1.clusterSetSlotNode(5000, node1Id);
|
node2.clusterReset(Reset.SOFT);
|
||||||
node1.clusterDelSlots(5000, 10000);
|
|
||||||
node1.clusterDelSlots(3000, 3001, 3002);
|
|
||||||
node2.clusterDelSlots(4000, 4001, 4002);
|
|
||||||
node1.clusterAddSlots(6000);
|
|
||||||
node1.clusterDelSlots(6000);
|
|
||||||
waitForGossip();
|
|
||||||
node2.clusterDelSlots(6000);
|
|
||||||
node1.clusterDelSlots(6000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void waitForGossip() {
|
private static void waitForGossip() {
|
||||||
@@ -63,14 +56,20 @@ public class ClusterCommandsTest extends JedisTestBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getClusterAttribute(String clusterInfo,
|
@Test
|
||||||
String attributeName) {
|
public void testClusterSoftReset() {
|
||||||
for (String infoElement : clusterInfo.split("\n")) {
|
node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
|
||||||
if (infoElement.contains(attributeName)) {
|
assertEquals(2, node1.clusterNodes().split("\n").length);
|
||||||
return Integer.valueOf(infoElement.split(":")[1].trim());
|
node1.clusterReset(Reset.SOFT);
|
||||||
|
assertEquals(1, node1.clusterNodes().split("\n").length);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 0;
|
@Test
|
||||||
|
public void testClusterHardReset() {
|
||||||
|
String nodeId = JedisClusterTestUtil.getNodeId(node1.clusterNodes());
|
||||||
|
node1.clusterReset(Reset.HARD);
|
||||||
|
String newNodeId = JedisClusterTestUtil.getNodeId(node1.clusterNodes());
|
||||||
|
assertNotEquals(nodeId, newNodeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user