Apply "Format" to all files, Closes #765
This commit is contained in:
@@ -10,35 +10,35 @@ import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
|
||||
public class ConnectionCloseTest extends Assert {
|
||||
|
||||
private Connection client;
|
||||
private Connection client;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
client = new Connection();
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
client = new Connection();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
client.close();
|
||||
}
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
client.close();
|
||||
}
|
||||
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
public void checkUnkownHost() {
|
||||
client.setHost("someunknownhost");
|
||||
client.connect();
|
||||
}
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
public void checkUnkownHost() {
|
||||
client.setHost("someunknownhost");
|
||||
client.connect();
|
||||
}
|
||||
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
public void checkWrongPort() {
|
||||
client.setHost("localhost");
|
||||
client.setPort(55665);
|
||||
client.connect();
|
||||
}
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
public void checkWrongPort() {
|
||||
client.setHost("localhost");
|
||||
client.setPort(55665);
|
||||
client.connect();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectIfNotConnectedWhenSettingTimeoutInfinite() {
|
||||
client.setHost("localhost");
|
||||
client.setPort(6379);
|
||||
client.setTimeoutInfinite();
|
||||
}
|
||||
@Test
|
||||
public void connectIfNotConnectedWhenSettingTimeoutInfinite() {
|
||||
client.setHost("localhost");
|
||||
client.setPort(6379);
|
||||
client.setTimeoutInfinite();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,18 +12,29 @@ public class HostAndPortUtil {
|
||||
private static List<HostAndPort> clusterHostAndPortList = new ArrayList<HostAndPort>();
|
||||
|
||||
static {
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 1));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 2));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 3));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 4));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 5));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 6));
|
||||
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 1));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 2));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 3));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT + 1));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT + 2));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT + 3));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT + 4));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT + 5));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT + 6));
|
||||
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_SENTINEL_PORT));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_SENTINEL_PORT + 1));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_SENTINEL_PORT + 2));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_SENTINEL_PORT + 3));
|
||||
|
||||
clusterHostAndPortList.add(new HostAndPort("localhost", 7379));
|
||||
clusterHostAndPortList.add(new HostAndPort("localhost", 7380));
|
||||
|
||||
@@ -3,6 +3,7 @@ package redis.clients.jedis.tests;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.util.ClusterNodeInformation;
|
||||
import redis.clients.util.ClusterNodeInformationParser;
|
||||
|
||||
@@ -5,14 +5,13 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.After;
|
||||
@@ -40,14 +39,14 @@ public class JedisClusterTest extends Assert {
|
||||
private static Jedis node2;
|
||||
private static Jedis node3;
|
||||
private static Jedis node4;
|
||||
private String localHost = "127.0.0.1";
|
||||
private String localHost = "127.0.0.1";
|
||||
|
||||
private HostAndPort nodeInfo1 = HostAndPortUtil.getClusterServers().get(0);
|
||||
private HostAndPort nodeInfo2 = HostAndPortUtil.getClusterServers().get(1);
|
||||
private HostAndPort nodeInfo3 = HostAndPortUtil.getClusterServers().get(2);
|
||||
private HostAndPort nodeInfo4 = HostAndPortUtil.getClusterServers().get(3);
|
||||
protected Logger log = Logger.getLogger(getClass().getName());
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws InterruptedException {
|
||||
node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort());
|
||||
@@ -61,7 +60,7 @@ public class JedisClusterTest extends Assert {
|
||||
node3 = new Jedis(nodeInfo3.getHost(), nodeInfo3.getPort());
|
||||
node3.connect();
|
||||
node3.flushAll();
|
||||
|
||||
|
||||
node4 = new Jedis(nodeInfo4.getHost(), nodeInfo4.getPort());
|
||||
node4.connect();
|
||||
node4.flushAll();
|
||||
@@ -71,13 +70,13 @@ public class JedisClusterTest extends Assert {
|
||||
// add nodes to cluster
|
||||
node1.clusterMeet(localHost, nodeInfo2.getPort());
|
||||
node1.clusterMeet(localHost, nodeInfo3.getPort());
|
||||
|
||||
|
||||
// split available slots across the three nodes
|
||||
int slotsPerNode = JedisCluster.HASHSLOTS / 3;
|
||||
int[] node1Slots = new int[slotsPerNode];
|
||||
int[] node2Slots = new int[slotsPerNode+1];
|
||||
int[] node2Slots = new int[slotsPerNode + 1];
|
||||
int[] node3Slots = new int[slotsPerNode];
|
||||
for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0 ; i < JedisCluster.HASHSLOTS; i++) {
|
||||
for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0; i < JedisCluster.HASHSLOTS; i++) {
|
||||
if (i < slotsPerNode) {
|
||||
node1Slots[slot1++] = i;
|
||||
} else if (i > slotsPerNode * 2) {
|
||||
@@ -86,14 +85,14 @@ public class JedisClusterTest extends Assert {
|
||||
node2Slots[slot2++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
node1.clusterAddSlots(node1Slots);
|
||||
node2.clusterAddSlots(node2Slots);
|
||||
node3.clusterAddSlots(node3Slots);
|
||||
|
||||
|
||||
JedisClusterTestUtil.waitForClusterReady(node1, node2, node3);
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
node1.flushDB();
|
||||
@@ -155,13 +154,12 @@ public class JedisClusterTest extends Assert {
|
||||
assertEquals("bar", node3.get("foo"));
|
||||
assertEquals("test", node2.get("test"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* slot->nodes
|
||||
* 15363 node3 e
|
||||
* slot->nodes 15363 node3 e
|
||||
*/
|
||||
@Test
|
||||
public void testMigrate(){
|
||||
public void testMigrate() {
|
||||
log.info("test migrate slot");
|
||||
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
|
||||
jedisClusterNode.add(nodeInfo1);
|
||||
@@ -170,50 +168,52 @@ public class JedisClusterTest extends Assert {
|
||||
String node2Id = JedisClusterTestUtil.getNodeId(node2.clusterNodes());
|
||||
node3.clusterSetSlotMigrating(15363, node2Id);
|
||||
node2.clusterSetSlotImporting(15363, node3Id);
|
||||
try{
|
||||
try {
|
||||
node2.set("e", "e");
|
||||
}catch(JedisMovedDataException jme){
|
||||
assertEquals(15363, jme.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), jme.getTargetNode());
|
||||
} catch (JedisMovedDataException jme) {
|
||||
assertEquals(15363, jme.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()),
|
||||
jme.getTargetNode());
|
||||
}
|
||||
|
||||
try{
|
||||
|
||||
try {
|
||||
node3.set("e", "e");
|
||||
}catch(JedisAskDataException jae){
|
||||
assertEquals(15363, jae.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo2.getPort()), jae.getTargetNode());
|
||||
} catch (JedisAskDataException jae) {
|
||||
assertEquals(15363, jae.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo2.getPort()),
|
||||
jae.getTargetNode());
|
||||
}
|
||||
|
||||
|
||||
jc.set("e", "e");
|
||||
|
||||
try{
|
||||
|
||||
try {
|
||||
node2.get("e");
|
||||
}catch(JedisMovedDataException jme){
|
||||
assertEquals(15363, jme.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), jme.getTargetNode());
|
||||
} catch (JedisMovedDataException jme) {
|
||||
assertEquals(15363, jme.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()),
|
||||
jme.getTargetNode());
|
||||
}
|
||||
try{
|
||||
try {
|
||||
node3.get("e");
|
||||
}catch(JedisAskDataException jae){
|
||||
assertEquals(15363, jae.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo2.getPort()), jae.getTargetNode());
|
||||
} catch (JedisAskDataException jae) {
|
||||
assertEquals(15363, jae.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo2.getPort()),
|
||||
jae.getTargetNode());
|
||||
}
|
||||
|
||||
|
||||
assertEquals("e", jc.get("e"));
|
||||
|
||||
|
||||
node2.clusterSetSlotNode(15363, node2Id);
|
||||
node3.clusterSetSlotNode(15363, node2Id);
|
||||
//assertEquals("e", jc.get("e"));
|
||||
// assertEquals("e", jc.get("e"));
|
||||
assertEquals("e", node2.get("e"));
|
||||
|
||||
//assertEquals("e", node3.get("e"));
|
||||
|
||||
|
||||
|
||||
|
||||
// assertEquals("e", node3.get("e"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMigrateToNewNode() throws InterruptedException{
|
||||
public void testMigrateToNewNode() throws InterruptedException {
|
||||
log.info("test migrate slot to new node");
|
||||
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
|
||||
jedisClusterNode.add(nodeInfo1);
|
||||
@@ -221,48 +221,52 @@ public class JedisClusterTest extends Assert {
|
||||
node4.clusterMeet(localHost, nodeInfo1.getPort());
|
||||
|
||||
String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes());
|
||||
String node4Id = JedisClusterTestUtil.getNodeId(node4.clusterNodes());
|
||||
JedisClusterTestUtil.waitForClusterReady(node4);
|
||||
String node4Id = JedisClusterTestUtil.getNodeId(node4.clusterNodes());
|
||||
JedisClusterTestUtil.waitForClusterReady(node4);
|
||||
node3.clusterSetSlotMigrating(15363, node4Id);
|
||||
node4.clusterSetSlotImporting(15363, node3Id);
|
||||
try{
|
||||
try {
|
||||
node4.set("e", "e");
|
||||
}catch(JedisMovedDataException jme){
|
||||
assertEquals(15363, jme.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), jme.getTargetNode());
|
||||
} catch (JedisMovedDataException jme) {
|
||||
assertEquals(15363, jme.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()),
|
||||
jme.getTargetNode());
|
||||
}
|
||||
|
||||
try{
|
||||
|
||||
try {
|
||||
node3.set("e", "e");
|
||||
}catch(JedisAskDataException jae){
|
||||
assertEquals(15363, jae.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo4.getPort()), jae.getTargetNode());
|
||||
} catch (JedisAskDataException jae) {
|
||||
assertEquals(15363, jae.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo4.getPort()),
|
||||
jae.getTargetNode());
|
||||
}
|
||||
|
||||
jc.set("e", "e");
|
||||
|
||||
try{
|
||||
|
||||
jc.set("e", "e");
|
||||
|
||||
try {
|
||||
node4.get("e");
|
||||
}catch(JedisMovedDataException jme){
|
||||
assertEquals(15363, jme.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), jme.getTargetNode());
|
||||
} catch (JedisMovedDataException jme) {
|
||||
assertEquals(15363, jme.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()),
|
||||
jme.getTargetNode());
|
||||
}
|
||||
try{
|
||||
try {
|
||||
node3.get("e");
|
||||
}catch(JedisAskDataException jae){
|
||||
assertEquals(15363, jae.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo4.getPort()), jae.getTargetNode());
|
||||
} catch (JedisAskDataException jae) {
|
||||
assertEquals(15363, jae.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo4.getPort()),
|
||||
jae.getTargetNode());
|
||||
}
|
||||
|
||||
|
||||
assertEquals("e", jc.get("e"));
|
||||
|
||||
|
||||
node4.clusterSetSlotNode(15363, node4Id);
|
||||
node3.clusterSetSlotNode(15363, node4Id);
|
||||
//assertEquals("e", jc.get("e"));
|
||||
// assertEquals("e", jc.get("e"));
|
||||
assertEquals("e", node4.get("e"));
|
||||
|
||||
//assertEquals("e", node3.get("e"));
|
||||
|
||||
|
||||
// assertEquals("e", node3.get("e"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -286,8 +290,10 @@ public class JedisClusterTest extends Assert {
|
||||
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
|
||||
JedisCluster jc = new JedisCluster(jedisClusterNode);
|
||||
int slot51 = JedisClusterCRC16.getSlot("51");
|
||||
node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
|
||||
node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
|
||||
node3.clusterSetSlotImporting(slot51,
|
||||
JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
|
||||
node2.clusterSetSlotMigrating(slot51,
|
||||
JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
|
||||
jc.set("51", "foo");
|
||||
assertEquals("foo", jc.get("51"));
|
||||
}
|
||||
@@ -307,56 +313,61 @@ public class JedisClusterTest extends Assert {
|
||||
JedisCluster jc = new JedisCluster(jedisClusterNode);
|
||||
int slot51 = JedisClusterCRC16.getSlot("51");
|
||||
// This will cause an infinite redirection loop
|
||||
node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
|
||||
node2.clusterSetSlotMigrating(slot51,
|
||||
JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
|
||||
jc.set("51", "foo");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRedisHashtag() {
|
||||
assertEquals(JedisClusterCRC16.getSlot("{bar"), JedisClusterCRC16.getSlot("foo{{bar}}zap"));
|
||||
assertEquals(JedisClusterCRC16.getSlot("{user1000}.following"), JedisClusterCRC16.getSlot("{user1000}.followers"));
|
||||
assertNotEquals(JedisClusterCRC16.getSlot("foo{}{bar}"), JedisClusterCRC16.getSlot("bar"));
|
||||
assertEquals(JedisClusterCRC16.getSlot("foo{bar}{zap}"), JedisClusterCRC16.getSlot("bar"));
|
||||
assertEquals(JedisClusterCRC16.getSlot("{bar"),
|
||||
JedisClusterCRC16.getSlot("foo{{bar}}zap"));
|
||||
assertEquals(JedisClusterCRC16.getSlot("{user1000}.following"),
|
||||
JedisClusterCRC16.getSlot("{user1000}.followers"));
|
||||
assertNotEquals(JedisClusterCRC16.getSlot("foo{}{bar}"),
|
||||
JedisClusterCRC16.getSlot("bar"));
|
||||
assertEquals(JedisClusterCRC16.getSlot("foo{bar}{zap}"),
|
||||
JedisClusterCRC16.getSlot("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClusterForgetNode() throws InterruptedException {
|
||||
// at first, join node4 to cluster
|
||||
node1.clusterMeet("127.0.0.1", nodeInfo4.getPort());
|
||||
|
||||
|
||||
String node7Id = JedisClusterTestUtil.getNodeId(node4.clusterNodes());
|
||||
|
||||
|
||||
JedisClusterTestUtil.assertNodeIsKnown(node3, node7Id, 1000);
|
||||
JedisClusterTestUtil.assertNodeIsKnown(node2, node7Id, 1000);
|
||||
JedisClusterTestUtil.assertNodeIsKnown(node1, node7Id, 1000);
|
||||
|
||||
|
||||
assertNodeHandshakeEnded(node3, 1000);
|
||||
assertNodeHandshakeEnded(node2, 1000);
|
||||
assertNodeHandshakeEnded(node1, 1000);
|
||||
|
||||
|
||||
assertEquals(4, node1.clusterNodes().split("\n").length);
|
||||
assertEquals(4, node2.clusterNodes().split("\n").length);
|
||||
assertEquals(4, node3.clusterNodes().split("\n").length);
|
||||
|
||||
|
||||
// do cluster forget
|
||||
node1.clusterForget(node7Id);
|
||||
node2.clusterForget(node7Id);
|
||||
node3.clusterForget(node7Id);
|
||||
|
||||
JedisClusterTestUtil.assertNodeIsUnknown(node1, node7Id, 1000);
|
||||
JedisClusterTestUtil.assertNodeIsUnknown(node2, node7Id, 1000);
|
||||
JedisClusterTestUtil.assertNodeIsUnknown(node3, node7Id, 1000);
|
||||
|
||||
assertEquals(3, node1.clusterNodes().split("\n").length);
|
||||
assertEquals(3, node2.clusterNodes().split("\n").length);
|
||||
assertEquals(3, node3.clusterNodes().split("\n").length);
|
||||
node1.clusterForget(node7Id);
|
||||
node2.clusterForget(node7Id);
|
||||
node3.clusterForget(node7Id);
|
||||
|
||||
JedisClusterTestUtil.assertNodeIsUnknown(node1, node7Id, 1000);
|
||||
JedisClusterTestUtil.assertNodeIsUnknown(node2, node7Id, 1000);
|
||||
JedisClusterTestUtil.assertNodeIsUnknown(node3, node7Id, 1000);
|
||||
|
||||
assertEquals(3, node1.clusterNodes().split("\n").length);
|
||||
assertEquals(3, node2.clusterNodes().split("\n").length);
|
||||
assertEquals(3, node3.clusterNodes().split("\n").length);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testClusterFlushSlots() {
|
||||
String slotRange = getNodeServingSlotRange(node1.clusterNodes());
|
||||
String slotRange = getNodeServingSlotRange(node1.clusterNodes());
|
||||
assertNotNull(slotRange);
|
||||
|
||||
|
||||
try {
|
||||
node1.clusterFlushSlots();
|
||||
assertNull(getNodeServingSlotRange(node1.clusterNodes()));
|
||||
@@ -365,73 +376,81 @@ public class JedisClusterTest extends Assert {
|
||||
String[] rangeInfo = slotRange.split("-");
|
||||
int lower = Integer.parseInt(rangeInfo[0]);
|
||||
int upper = Integer.parseInt(rangeInfo[1]);
|
||||
|
||||
|
||||
int[] node1Slots = new int[upper - lower + 1];
|
||||
for (int i = 0 ; lower <= upper ; ) {
|
||||
for (int i = 0; lower <= upper;) {
|
||||
node1Slots[i++] = lower++;
|
||||
}
|
||||
node1.clusterAddSlots(node1Slots);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testClusterKeySlot() {
|
||||
// It assumes JedisClusterCRC16 is correctly implemented
|
||||
assertEquals(node1.clusterKeySlot("foo{bar}zap}").intValue(), JedisClusterCRC16.getSlot("foo{bar}zap"));
|
||||
assertEquals(node1.clusterKeySlot("{user1000}.following").intValue(), JedisClusterCRC16.getSlot("{user1000}.following"));
|
||||
assertEquals(node1.clusterKeySlot("foo{bar}zap}").intValue(),
|
||||
JedisClusterCRC16.getSlot("foo{bar}zap"));
|
||||
assertEquals(node1.clusterKeySlot("{user1000}.following").intValue(),
|
||||
JedisClusterCRC16.getSlot("{user1000}.following"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testClusterCountKeysInSlot() {
|
||||
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
|
||||
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
|
||||
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1
|
||||
.getPort()));
|
||||
JedisCluster jc = new JedisCluster(jedisClusterNode);
|
||||
|
||||
for (int index = 0 ; index < 5 ; index++) {
|
||||
|
||||
for (int index = 0; index < 5; index++) {
|
||||
jc.set("foo{bar}" + index, "hello");
|
||||
}
|
||||
|
||||
|
||||
int slot = JedisClusterCRC16.getSlot("foo{bar}");
|
||||
assertEquals(5, node1.clusterCountKeysInSlot(slot).intValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified() throws InterruptedException {
|
||||
public void testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified()
|
||||
throws InterruptedException {
|
||||
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
|
||||
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
|
||||
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1
|
||||
.getPort()));
|
||||
JedisCluster jc = new JedisCluster(jedisClusterNode);
|
||||
|
||||
|
||||
int slot51 = JedisClusterCRC16.getSlot("51");
|
||||
jc.set("51", "foo");
|
||||
// node2 is responsible of taking care of slot51 (7186)
|
||||
|
||||
node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
|
||||
|
||||
node3.clusterSetSlotImporting(slot51,
|
||||
JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
|
||||
assertEquals("foo", jc.get("51"));
|
||||
node3.clusterSetSlotStable(slot51);
|
||||
assertEquals("foo", jc.get("51"));
|
||||
|
||||
node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
|
||||
//assertEquals("foo", jc.get("51")); // it leads Max Redirections
|
||||
|
||||
node2.clusterSetSlotMigrating(slot51,
|
||||
JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
|
||||
// assertEquals("foo", jc.get("51")); // it leads Max Redirections
|
||||
node2.clusterSetSlotStable(slot51);
|
||||
assertEquals("foo", jc.get("51"));
|
||||
}
|
||||
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
public void testIfPoolConfigAppliesToClusterPools() {
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
config.setMaxTotal(0);
|
||||
config.setMaxWaitMillis(2000);
|
||||
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
|
||||
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
|
||||
JedisCluster jc = new JedisCluster(jedisClusterNode, config);
|
||||
jc.set("52", "poolTestValue");
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
config.setMaxTotal(0);
|
||||
config.setMaxWaitMillis(2000);
|
||||
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
|
||||
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
|
||||
JedisCluster jc = new JedisCluster(jedisClusterNode, config);
|
||||
jc.set("52", "poolTestValue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloseable() {
|
||||
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
|
||||
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
|
||||
|
||||
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1
|
||||
.getPort()));
|
||||
|
||||
JedisCluster jc = null;
|
||||
try {
|
||||
jc = new JedisCluster(jedisClusterNode);
|
||||
@@ -442,7 +461,8 @@ public class JedisClusterTest extends Assert {
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<JedisPool> poolIterator = jc.getClusterNodes().values().iterator();
|
||||
Iterator<JedisPool> poolIterator = jc.getClusterNodes().values()
|
||||
.iterator();
|
||||
while (poolIterator.hasNext()) {
|
||||
JedisPool pool = poolIterator.next();
|
||||
try {
|
||||
@@ -453,21 +473,24 @@ public class JedisClusterTest extends Assert {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testJedisClusterRunsWithMultithreaded() throws InterruptedException, ExecutionException {
|
||||
public void testJedisClusterRunsWithMultithreaded()
|
||||
throws InterruptedException, ExecutionException {
|
||||
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
|
||||
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
|
||||
final JedisCluster jc = new JedisCluster(jedisClusterNode);
|
||||
jc.set("foo", "bar");
|
||||
|
||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
|
||||
|
||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 0,
|
||||
TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
|
||||
List<Future<String>> futures = new ArrayList<Future<String>>();
|
||||
for (int i = 0 ; i < 50 ; i++) {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
executor.submit(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
// FIXME : invalidate slot cache from JedisCluster to test random connection also does work
|
||||
// FIXME : invalidate slot cache from JedisCluster to test
|
||||
// random connection also does work
|
||||
return jc.get("foo");
|
||||
}
|
||||
});
|
||||
@@ -477,12 +500,13 @@ public class JedisClusterTest extends Assert {
|
||||
String value = future.get();
|
||||
assertEquals("bar", value);
|
||||
}
|
||||
|
||||
|
||||
jc.close();
|
||||
}
|
||||
|
||||
|
||||
private static String getNodeServingSlotRange(String infoOutput) {
|
||||
// f4f3dc4befda352a4e0beccf29f5e8828438705d 127.0.0.1:7380 master - 0 1394372400827 0 connected 5461-10922
|
||||
// f4f3dc4befda352a4e0beccf29f5e8828438705d 127.0.0.1:7380 master - 0
|
||||
// 1394372400827 0 connected 5461-10922
|
||||
for (String infoLine : infoOutput.split("\n")) {
|
||||
if (infoLine.contains("myself")) {
|
||||
try {
|
||||
@@ -494,23 +518,23 @@ public class JedisClusterTest extends Assert {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private void assertNodeHandshakeEnded(Jedis node, int timeoutMs) {
|
||||
int sleepInterval = 100;
|
||||
for (int sleepTime = 0 ; sleepTime <= timeoutMs ; sleepTime += sleepInterval) {
|
||||
for (int sleepTime = 0; sleepTime <= timeoutMs; sleepTime += sleepInterval) {
|
||||
boolean isHandshaking = isAnyNodeHandshaking(node);
|
||||
if (!isHandshaking)
|
||||
return;
|
||||
|
||||
|
||||
try {
|
||||
Thread.sleep(sleepInterval);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
throw new JedisException("Node handshaking is not ended");
|
||||
}
|
||||
|
||||
|
||||
private boolean isAnyNodeHandshaking(Jedis node) {
|
||||
String infoOutput = node.clusterNodes();
|
||||
for (String infoLine : infoOutput.split("\n")) {
|
||||
|
||||
@@ -33,7 +33,7 @@ public class JedisPoolTest extends Assert {
|
||||
@Test
|
||||
public void checkCloseableConnections() throws Exception {
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort(), 2000);
|
||||
hnp.getPort(), 2000);
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
@@ -270,37 +270,37 @@ public class JedisPoolTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void getNumActiveIsNegativeWhenPoolIsClosed() {
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort(), 2000, "foobared", 0, "my_shiny_client_name");
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort(), 2000, "foobared", 0, "my_shiny_client_name");
|
||||
|
||||
pool.destroy();
|
||||
assertTrue(pool.getNumActive() < 0);
|
||||
pool.destroy();
|
||||
assertTrue(pool.getNumActive() < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNumActiveReturnsTheCorrectNumber() {
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort(), 2000);
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort(), 2000);
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
|
||||
assertEquals(1, pool.getNumActive());
|
||||
assertEquals(1, pool.getNumActive());
|
||||
|
||||
Jedis jedis2 = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
Jedis jedis2 = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
|
||||
assertEquals(2, pool.getNumActive());
|
||||
assertEquals(2, pool.getNumActive());
|
||||
|
||||
pool.returnResource(jedis);
|
||||
assertEquals(1, pool.getNumActive());
|
||||
pool.returnResource(jedis);
|
||||
assertEquals(1, pool.getNumActive());
|
||||
|
||||
pool.returnResource(jedis2);
|
||||
pool.returnResource(jedis2);
|
||||
|
||||
assertEquals(0, pool.getNumActive());
|
||||
assertEquals(0, pool.getNumActive());
|
||||
|
||||
pool.destroy();
|
||||
pool.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package redis.clients.jedis.tests;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.Before;
|
||||
@@ -27,7 +26,7 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
protected static HostAndPort sentinel1 = HostAndPortUtil
|
||||
.getSentinelServers().get(1);
|
||||
protected static HostAndPort sentinel2 = HostAndPortUtil
|
||||
.getSentinelServers().get(3);
|
||||
.getSentinelServers().get(3);
|
||||
|
||||
protected static Jedis sentinelJedis1;
|
||||
protected static Jedis sentinelJedis2;
|
||||
@@ -42,31 +41,32 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
sentinelJedis1 = new Jedis(sentinel1.getHost(), sentinel1.getPort());
|
||||
sentinelJedis2 = new Jedis(sentinel2.getHost(), sentinel2.getPort());
|
||||
}
|
||||
|
||||
@Test(expected=JedisConnectionException.class)
|
||||
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
public void initializeWithNotAvailableSentinelsShouldThrowException() {
|
||||
Set<String> wrongSentinels = new HashSet<String>();
|
||||
wrongSentinels.add(new HostAndPort("localhost", 65432).toString());
|
||||
wrongSentinels.add(new HostAndPort("localhost", 65431).toString());
|
||||
|
||||
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, wrongSentinels);
|
||||
|
||||
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME,
|
||||
wrongSentinels);
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test(expected=JedisException.class)
|
||||
|
||||
@Test(expected = JedisException.class)
|
||||
public void initializeWithNotMonitoredMasterNameShouldThrowException() {
|
||||
final String wrongMasterName = "wrongMasterName";
|
||||
JedisSentinelPool pool = new JedisSentinelPool(wrongMasterName,
|
||||
sentinels);
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void checkCloseableConnections() throws Exception {
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
|
||||
JedisSentinelPool pool = new JedisSentinelPool(
|
||||
MASTER_NAME, sentinels, config, 1000, "foobared", 2);
|
||||
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
|
||||
config, 1000, "foobared", 2);
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
@@ -82,13 +82,14 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
new GenericObjectPoolConfig(), 1000, "foobared", 2);
|
||||
|
||||
forceFailover(pool);
|
||||
// after failover sentinel needs a bit of time to stabilize before a new failover
|
||||
// after failover sentinel needs a bit of time to stabilize before a new
|
||||
// failover
|
||||
Thread.sleep(100);
|
||||
forceFailover(pool);
|
||||
|
||||
// you can test failover as much as possible
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void returnResourceShouldResetState() {
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
@@ -99,13 +100,13 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
|
||||
Jedis jedis = pool.getResource();
|
||||
Jedis jedis2 = null;
|
||||
|
||||
|
||||
try {
|
||||
jedis.set("hello", "jedis");
|
||||
Transaction t = jedis.multi();
|
||||
t.set("hello", "world");
|
||||
pool.returnResource(jedis);
|
||||
|
||||
|
||||
jedis2 = pool.getResource();
|
||||
|
||||
assertTrue(jedis == jedis2);
|
||||
@@ -118,11 +119,11 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
} finally {
|
||||
if (jedis2 != null)
|
||||
pool.returnResource(jedis2);
|
||||
|
||||
|
||||
pool.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void checkResourceIsCloseable() {
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
@@ -184,9 +185,10 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
|
||||
Jedis afterFailoverJedis = pool.getResource();
|
||||
assertEquals("PONG", afterFailoverJedis.ping());
|
||||
assertEquals("foobared", afterFailoverJedis.configGet("requirepass").get(1));
|
||||
assertEquals("foobared", afterFailoverJedis.configGet("requirepass")
|
||||
.get(1));
|
||||
assertEquals(2, afterFailoverJedis.getDB().intValue());
|
||||
|
||||
|
||||
// returning both connections to the pool should not throw
|
||||
beforeFailoverJedis.close();
|
||||
afterFailoverJedis.close();
|
||||
@@ -194,8 +196,8 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
|
||||
private void waitForFailover(JedisSentinelPool pool, HostAndPort oldMaster)
|
||||
throws InterruptedException {
|
||||
HostAndPort newMaster = JedisSentinelTestUtil
|
||||
.waitForNewPromotedMaster(MASTER_NAME, sentinelJedis1, sentinelJedis2);
|
||||
HostAndPort newMaster = JedisSentinelTestUtil.waitForNewPromotedMaster(
|
||||
MASTER_NAME, sentinelJedis1, sentinelJedis2);
|
||||
|
||||
waitForJedisSentinelPoolRecognizeNewMaster(pool, newMaster);
|
||||
}
|
||||
@@ -216,5 +218,5 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -22,8 +22,8 @@ public class JedisSentinelTest extends JedisTestBase {
|
||||
|
||||
protected static HostAndPort master = HostAndPortUtil.getRedisServers()
|
||||
.get(0);
|
||||
protected static HostAndPort slave = HostAndPortUtil.getRedisServers()
|
||||
.get(4);
|
||||
protected static HostAndPort slave = HostAndPortUtil.getRedisServers().get(
|
||||
4);
|
||||
protected static HostAndPort sentinel = HostAndPortUtil
|
||||
.getSentinelServers().get(0);
|
||||
|
||||
@@ -86,15 +86,17 @@ public class JedisSentinelTest extends JedisTestBase {
|
||||
Jedis j = new Jedis(sentinelForFailover.getHost(),
|
||||
sentinelForFailover.getPort());
|
||||
Jedis j2 = new Jedis(sentinelForFailover.getHost(),
|
||||
sentinelForFailover.getPort());
|
||||
sentinelForFailover.getPort());
|
||||
|
||||
try {
|
||||
List<String> masterHostAndPort = j
|
||||
.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
|
||||
HostAndPort currentMaster = new HostAndPort(masterHostAndPort.get(0),
|
||||
HostAndPort currentMaster = new HostAndPort(
|
||||
masterHostAndPort.get(0),
|
||||
Integer.parseInt(masterHostAndPort.get(1)));
|
||||
|
||||
JedisSentinelTestUtil.waitForNewPromotedMaster(FAILOVER_MASTER_NAME, j, j2);
|
||||
JedisSentinelTestUtil.waitForNewPromotedMaster(
|
||||
FAILOVER_MASTER_NAME, j, j2);
|
||||
|
||||
masterHostAndPort = j
|
||||
.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
|
||||
@@ -204,5 +206,5 @@ public class JedisSentinelTest extends JedisTestBase {
|
||||
j.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public class JedisTest extends JedisCommandTestBase {
|
||||
assertEquals(jedis.getClient().getHost(), "localhost");
|
||||
assertEquals(jedis.getClient().getPort(), 6380);
|
||||
assertEquals(jedis.getDB(), (Long) 0L);
|
||||
|
||||
|
||||
jedis = new Jedis("redis://localhost:6380/");
|
||||
jedis.auth("foobared");
|
||||
assertEquals(jedis.getClient().getHost(), "localhost");
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
package redis.clients.jedis.tests;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import redis.clients.jedis.*;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.*;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.Tuple;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
public class PipeliningTest extends Assert {
|
||||
private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
|
||||
@@ -42,9 +53,9 @@ public class PipeliningTest extends Assert {
|
||||
jedis.hset("hash", "foo", "bar");
|
||||
jedis.zadd("zset", 1, "foo");
|
||||
jedis.sadd("set", "foo");
|
||||
jedis.setrange("setrange", 0, "0123456789");
|
||||
byte[] bytesForSetRange = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
jedis.setrange("setrangebytes".getBytes(), 0, bytesForSetRange);
|
||||
jedis.setrange("setrange", 0, "0123456789");
|
||||
byte[] bytesForSetRange = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
jedis.setrange("setrangebytes".getBytes(), 0, bytesForSetRange);
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<String> string = p.get("string");
|
||||
@@ -61,10 +72,11 @@ public class PipeliningTest extends Assert {
|
||||
p.sadd("set", "foo");
|
||||
Response<Set<String>> smembers = p.smembers("set");
|
||||
Response<Set<Tuple>> zrangeWithScores = p.zrangeWithScores("zset", 0,
|
||||
-1);
|
||||
Response<String> getrange = p.getrange("setrange", 1, 3);
|
||||
Response<byte[]> getrangeBytes = p.getrange("setrangebytes".getBytes(), 6, 8);
|
||||
p.sync();
|
||||
-1);
|
||||
Response<String> getrange = p.getrange("setrange", 1, 3);
|
||||
Response<byte[]> getrangeBytes = p.getrange("setrangebytes".getBytes(),
|
||||
6, 8);
|
||||
p.sync();
|
||||
|
||||
assertEquals("foo", string.get());
|
||||
assertEquals("foo", list.get());
|
||||
@@ -78,9 +90,9 @@ public class PipeliningTest extends Assert {
|
||||
assertNotNull(hgetAll.get().get("foo"));
|
||||
assertEquals(1, smembers.get().size());
|
||||
assertEquals(1, zrangeWithScores.get().size());
|
||||
assertEquals("123", getrange.get());
|
||||
byte[] expectedGetRangeBytes = {6, 7, 8};
|
||||
assertArrayEquals(expectedGetRangeBytes, getrangeBytes.get());
|
||||
assertEquals("123", getrange.get());
|
||||
byte[] expectedGetRangeBytes = { 6, 7, 8 };
|
||||
assertArrayEquals(expectedGetRangeBytes, getrangeBytes.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -261,7 +273,7 @@ public class PipeliningTest extends Assert {
|
||||
p.exec();
|
||||
Response<String> r3 = p.get("hello");
|
||||
p.sync();
|
||||
|
||||
|
||||
// before multi
|
||||
assertEquals("foo", r1.get());
|
||||
// It should be readable whether exec's response was built or not
|
||||
@@ -375,75 +387,74 @@ public class PipeliningTest extends Assert {
|
||||
@Test
|
||||
public void testPipelinedTransactionResponse() {
|
||||
|
||||
String key1 = "key1";
|
||||
String val1 = "val1";
|
||||
String key1 = "key1";
|
||||
String val1 = "val1";
|
||||
|
||||
String key2 = "key2";
|
||||
String val2 = "val2";
|
||||
String key2 = "key2";
|
||||
String val2 = "val2";
|
||||
|
||||
String key3 = "key3";
|
||||
String field1 = "field1";
|
||||
String field2 = "field2";
|
||||
String field3 = "field3";
|
||||
String field4 = "field4";
|
||||
String key3 = "key3";
|
||||
String field1 = "field1";
|
||||
String field2 = "field2";
|
||||
String field3 = "field3";
|
||||
String field4 = "field4";
|
||||
|
||||
String value1 = "value1";
|
||||
String value2 = "value2";
|
||||
String value3 = "value3";
|
||||
String value4 = "value4";
|
||||
String value1 = "value1";
|
||||
String value2 = "value2";
|
||||
String value3 = "value3";
|
||||
String value4 = "value4";
|
||||
|
||||
Map<String, String> hashMap = new HashMap<String, String>();
|
||||
hashMap.put(field1, value1);
|
||||
hashMap.put(field2, value2);
|
||||
Map<String, String> hashMap = new HashMap<String, String>();
|
||||
hashMap.put(field1, value1);
|
||||
hashMap.put(field2, value2);
|
||||
|
||||
String key4 = "key4";
|
||||
Map<String, String> hashMap1 = new HashMap<String, String>();
|
||||
hashMap1.put(field3, value3);
|
||||
hashMap1.put(field4, value4);
|
||||
String key4 = "key4";
|
||||
Map<String, String> hashMap1 = new HashMap<String, String>();
|
||||
hashMap1.put(field3, value3);
|
||||
hashMap1.put(field4, value4);
|
||||
|
||||
jedis.set(key1, val1);
|
||||
jedis.set(key2, val2);
|
||||
jedis.hmset(key3, hashMap);
|
||||
jedis.hmset(key4, hashMap1);
|
||||
|
||||
jedis.set(key1, val1);
|
||||
jedis.set(key2, val2);
|
||||
jedis.hmset(key3, hashMap);
|
||||
jedis.hmset(key4, hashMap1);
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
pipeline.multi();
|
||||
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
pipeline.multi();
|
||||
pipeline.get(key1);
|
||||
pipeline.hgetAll(key2);
|
||||
pipeline.hgetAll(key3);
|
||||
pipeline.get(key4);
|
||||
|
||||
pipeline.get(key1);
|
||||
pipeline.hgetAll(key2);
|
||||
pipeline.hgetAll(key3);
|
||||
pipeline.get(key4);
|
||||
Response<List<Object>> response = pipeline.exec();
|
||||
pipeline.sync();
|
||||
|
||||
Response<List<Object> > response = pipeline.exec();
|
||||
pipeline.sync();
|
||||
List<Object> result = response.get();
|
||||
|
||||
List<Object> result = response.get();
|
||||
assertEquals(4, result.size());
|
||||
|
||||
assertEquals(4, result.size());
|
||||
assertEquals("val1", result.get(0));
|
||||
|
||||
assertEquals("val1", result.get(0));
|
||||
assertTrue(result.get(1) instanceof JedisDataException);
|
||||
|
||||
assertTrue(result.get(1) instanceof JedisDataException);
|
||||
Map<String, String> hashMapReceived = (Map<String, String>) result
|
||||
.get(2);
|
||||
Iterator<String> iterator = hashMapReceived.keySet().iterator();
|
||||
String mapKey1 = iterator.next();
|
||||
String mapKey2 = iterator.next();
|
||||
assertFalse(iterator.hasNext());
|
||||
verifyHasBothValues(mapKey1, mapKey2, field1, field2);
|
||||
String mapValue1 = hashMapReceived.get(mapKey1);
|
||||
String mapValue2 = hashMapReceived.get(mapKey2);
|
||||
verifyHasBothValues(mapValue1, mapValue2, value1, value2);
|
||||
|
||||
Map<String, String> hashMapReceived = (Map<String, String>)result.get(2);
|
||||
Iterator<String> iterator = hashMapReceived.keySet().iterator();
|
||||
String mapKey1 = iterator.next();
|
||||
String mapKey2 = iterator.next();
|
||||
assertFalse(iterator.hasNext());
|
||||
verifyHasBothValues(mapKey1, mapKey2, field1, field2);
|
||||
String mapValue1 = hashMapReceived.get(mapKey1);
|
||||
String mapValue2 = hashMapReceived.get(mapKey2);
|
||||
verifyHasBothValues(mapValue1, mapValue2, value1, value2);
|
||||
|
||||
assertTrue(result.get(3) instanceof JedisDataException);
|
||||
assertTrue(result.get(3) instanceof JedisDataException);
|
||||
}
|
||||
|
||||
private void verifyHasBothValues(String firstKey, String secondKey, String value1, String value2) {
|
||||
assertFalse(firstKey.equals(secondKey));
|
||||
assertTrue(firstKey.equals(value1)
|
||||
|| firstKey.equals(value2));
|
||||
assertTrue(secondKey.equals(value1)
|
||||
|| secondKey.equals(value2));
|
||||
private void verifyHasBothValues(String firstKey, String secondKey,
|
||||
String value1, String value2) {
|
||||
assertFalse(firstKey.equals(secondKey));
|
||||
assertTrue(firstKey.equals(value1) || firstKey.equals(value2));
|
||||
assertTrue(secondKey.equals(value1) || secondKey.equals(value2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,26 +39,26 @@ public class ProtocolTest extends JedisTestBase {
|
||||
|
||||
assertEquals(expectedCommand, sb.toString());
|
||||
}
|
||||
|
||||
@Test(expected=IOException.class)
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void writeOverflow() throws IOException {
|
||||
RedisOutputStream ros = new RedisOutputStream(new OutputStream() {
|
||||
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
throw new IOException("thrown exception");
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ros.write(new byte[8191]);
|
||||
|
||||
|
||||
try {
|
||||
ros.write((byte)'*');
|
||||
} catch (IOException ioe) {}
|
||||
|
||||
|
||||
ros.write((byte)'*');
|
||||
ros.write((byte) '*');
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
|
||||
ros.write((byte) '*');
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,9 @@ import redis.clients.util.JedisClusterCRC16;
|
||||
public class CRC16Benchmark {
|
||||
private static final int TOTAL_OPERATIONS = 100000000;
|
||||
|
||||
private static String[] TEST_SET = {
|
||||
"", "123456789", "sfger132515", "hae9Napahngaikeethievubaibogiech",
|
||||
"AAAAAAAAAAAAAAAAAAAAAA", "Hello, World!"
|
||||
};
|
||||
private static String[] TEST_SET = { "", "123456789", "sfger132515",
|
||||
"hae9Napahngaikeethievubaibogiech", "AAAAAAAAAAAAAAAAAAAAAA",
|
||||
"Hello, World!" };
|
||||
|
||||
public static void main(String[] args) {
|
||||
long begin = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -10,8 +13,6 @@ import redis.clients.jedis.ScanParams;
|
||||
import redis.clients.jedis.ScanResult;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -523,14 +524,14 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
|
||||
// binary
|
||||
ScanResult<byte[]> bResult = jedis.scan(SCAN_POINTER_START_BINARY);
|
||||
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void scanMatch() {
|
||||
ScanParams params = new ScanParams();
|
||||
@@ -543,7 +544,7 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.match(bfoostar);
|
||||
@@ -551,9 +552,10 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.set(bfoo1, bbar);
|
||||
jedis.set(bfoo2, bbar);
|
||||
jedis.set(bfoo3, bbar);
|
||||
|
||||
ScanResult<byte[]> bResult = jedis.scan(SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
|
||||
ScanResult<byte[]> bResult = jedis.scan(SCAN_POINTER_START_BINARY,
|
||||
params);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
@@ -570,7 +572,7 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
ScanResult<String> result = jedis.scan(SCAN_POINTER_START, params);
|
||||
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.count(2);
|
||||
@@ -578,9 +580,10 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.set(bfoo1, bbar);
|
||||
jedis.set(bfoo2, bbar);
|
||||
jedis.set(bfoo3, bbar);
|
||||
|
||||
ScanResult<byte[]> bResult = jedis.scan(SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
|
||||
ScanResult<byte[]> bResult = jedis.scan(SCAN_POINTER_START_BINARY,
|
||||
params);
|
||||
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ public class BitCommandsTest extends JedisCommandTestBase {
|
||||
jedis.setbit(foo, 7, true);
|
||||
jedis.setbit(foo, 13, true);
|
||||
jedis.setbit(foo, 39, true);
|
||||
|
||||
|
||||
/*
|
||||
* byte: 0 1 2 3 4
|
||||
* bit: 00010001 / 00000100 / 00000000 / 00000000 / 00000001
|
||||
* byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 /
|
||||
* 00000001
|
||||
*/
|
||||
long offset = jedis.bitpos(foo, true);
|
||||
assertEquals(2, offset);
|
||||
@@ -69,8 +69,8 @@ public class BitCommandsTest extends JedisCommandTestBase {
|
||||
jedis.setbit(bfoo, 39, true);
|
||||
|
||||
/*
|
||||
* byte: 0 1 2 3 4
|
||||
* bit: 00010001 / 00000100 / 00000000 / 00000000 / 00000001
|
||||
* byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 /
|
||||
* 00000001
|
||||
*/
|
||||
long offset = jedis.bitpos(bfoo, true);
|
||||
assertEquals(2, offset);
|
||||
@@ -101,8 +101,7 @@ public class BitCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
/*
|
||||
* byte: 0
|
||||
* bit: 11111111
|
||||
* byte: 0 bit: 11111111
|
||||
*/
|
||||
long offset = jedis.bitpos(foo, false);
|
||||
// offset should be last index + 1
|
||||
@@ -119,8 +118,8 @@ public class BitCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
/*
|
||||
* byte: 0 1 2 3 4
|
||||
* bit: 11111111 / 11111111 / 11111111 / 11111111 / 11111111
|
||||
* byte: 0 1 2 3 4 bit: 11111111 / 11111111 / 11111111 / 11111111 /
|
||||
* 11111111
|
||||
*/
|
||||
long offset = jedis.bitpos(foo, false, new BitPosParams(2, 3));
|
||||
// offset should be -1
|
||||
|
||||
@@ -47,12 +47,12 @@ public class ClusterCommandsTest extends JedisTestBase {
|
||||
|
||||
@Test
|
||||
public void testClusterSoftReset() {
|
||||
node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
|
||||
assertTrue(node1.clusterNodes().split("\n").length > 1);
|
||||
node1.clusterReset(Reset.SOFT);
|
||||
assertEquals(1, node1.clusterNodes().split("\n").length);
|
||||
node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
|
||||
assertTrue(node1.clusterNodes().split("\n").length > 1);
|
||||
node1.clusterReset(Reset.SOFT);
|
||||
assertEquals(1, node1.clusterNodes().split("\n").length);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testClusterHardReset() {
|
||||
String nodeId = JedisClusterTestUtil.getNodeId(node1.clusterNodes());
|
||||
@@ -60,7 +60,7 @@ public class ClusterCommandsTest extends JedisTestBase {
|
||||
String newNodeId = JedisClusterTestUtil.getNodeId(node1.clusterNodes());
|
||||
assertNotEquals(nodeId, newNodeId);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void clusterSetSlotImporting() {
|
||||
node2.clusterAddSlots(6000);
|
||||
@@ -124,7 +124,7 @@ public class ClusterCommandsTest extends JedisTestBase {
|
||||
String status = node1.clusterSetSlotMigrating(5000, nodeId);
|
||||
assertEquals("OK", status);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void clusterSlots() {
|
||||
// please see cluster slot output format from below commit
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -9,24 +12,22 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.ScanParams;
|
||||
import redis.clients.jedis.ScanResult;
|
||||
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||
final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C };
|
||||
|
||||
|
||||
final byte[] bbar1 = { 0x05, 0x06, 0x07, 0x08, 0x0A };
|
||||
final byte[] bbar2 = { 0x05, 0x06, 0x07, 0x08, 0x0B };
|
||||
final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C };
|
||||
final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' };
|
||||
|
||||
|
||||
@Test
|
||||
public void hset() {
|
||||
long status = jedis.hset("foo", "bar", "car");
|
||||
@@ -157,20 +158,20 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void hincrByFloat() {
|
||||
Double value = jedis.hincrByFloat("foo", "bar", 1.5d);
|
||||
assertEquals((Double) 1.5d, value);
|
||||
value = jedis.hincrByFloat("foo", "bar", -1.5d);
|
||||
assertEquals((Double) 0d, value);
|
||||
value = jedis.hincrByFloat("foo", "bar", -10.7d);
|
||||
assertEquals(Double.compare(-10.7d, value), 0);
|
||||
Double value = jedis.hincrByFloat("foo", "bar", 1.5d);
|
||||
assertEquals((Double) 1.5d, value);
|
||||
value = jedis.hincrByFloat("foo", "bar", -1.5d);
|
||||
assertEquals((Double) 0d, value);
|
||||
value = jedis.hincrByFloat("foo", "bar", -10.7d);
|
||||
assertEquals(Double.compare(-10.7d, value), 0);
|
||||
|
||||
// Binary
|
||||
double bvalue = jedis.hincrByFloat(bfoo, bbar, 1.5d);
|
||||
assertEquals(Double.compare(1.5d, bvalue), 0);
|
||||
bvalue = jedis.hincrByFloat(bfoo, bbar, -1.5d);
|
||||
assertEquals(Double.compare(0d, bvalue), 0);
|
||||
bvalue = jedis.hincrByFloat(bfoo, bbar, -10.7d);
|
||||
assertEquals(Double.compare(-10.7d, value), 0);
|
||||
// Binary
|
||||
double bvalue = jedis.hincrByFloat(bfoo, bbar, 1.5d);
|
||||
assertEquals(Double.compare(1.5d, bvalue), 0);
|
||||
bvalue = jedis.hincrByFloat(bfoo, bbar, -1.5d);
|
||||
assertEquals(Double.compare(0d, bvalue), 0);
|
||||
bvalue = jedis.hincrByFloat(bfoo, bbar, -10.7d);
|
||||
assertEquals(Double.compare(-10.7d, value), 0);
|
||||
|
||||
}
|
||||
|
||||
@@ -339,16 +340,18 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.hset("foo", "b", "b");
|
||||
jedis.hset("foo", "a", "a");
|
||||
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", SCAN_POINTER_START);
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo",
|
||||
SCAN_POINTER_START);
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
|
||||
// binary
|
||||
jedis.hset(bfoo, bbar, bcar);
|
||||
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo, SCAN_POINTER_START_BINARY);
|
||||
|
||||
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
@@ -361,23 +364,24 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.hset("foo", "b", "b");
|
||||
jedis.hset("foo", "a", "a");
|
||||
jedis.hset("foo", "aa", "aa");
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo",
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo",
|
||||
SCAN_POINTER_START, params);
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.match(bbarstar);
|
||||
|
||||
|
||||
jedis.hset(bfoo, bbar, bcar);
|
||||
jedis.hset(bfoo, bbar1, bcar);
|
||||
jedis.hset(bfoo, bbar2, bcar);
|
||||
jedis.hset(bfoo, bbar3, bcar);
|
||||
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
@@ -391,22 +395,23 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.hset("foo", "a" + i, "a" + i);
|
||||
}
|
||||
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo",
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo",
|
||||
SCAN_POINTER_START, params);
|
||||
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.count(2);
|
||||
|
||||
|
||||
jedis.hset(bfoo, bbar, bcar);
|
||||
jedis.hset(bfoo, bbar1, bcar);
|
||||
jedis.hset(bfoo, bbar2, bcar);
|
||||
jedis.hset(bfoo, bbar3, bcar);
|
||||
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,61 +10,60 @@ public class HyperLogLogCommandsTest extends JedisCommandTestBase {
|
||||
public void pfadd() {
|
||||
long status = jedis.pfadd("foo", "a");
|
||||
assertEquals(1, status);
|
||||
|
||||
|
||||
status = jedis.pfadd("foo", "a");
|
||||
assertEquals(0, status);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void pfaddBinary() {
|
||||
byte[] bFoo = SafeEncoder.encode("foo");
|
||||
byte[] bBar = SafeEncoder.encode("bar");
|
||||
byte[] bBar2 = SafeEncoder.encode("bar2");
|
||||
|
||||
|
||||
long status = jedis.pfadd(bFoo, bBar, bBar2);
|
||||
assertEquals(1, status);
|
||||
|
||||
|
||||
status = jedis.pfadd(bFoo, bBar, bBar2);
|
||||
assertEquals(0, status);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void pfcount() {
|
||||
long status = jedis.pfadd("hll", "foo", "bar", "zap");
|
||||
assertEquals(1, status);
|
||||
|
||||
|
||||
status = jedis.pfadd("hll", "zap", "zap", "zap");
|
||||
assertEquals(0, status);
|
||||
|
||||
|
||||
status = jedis.pfadd("hll", "foo", "bar");
|
||||
assertEquals(0, status);
|
||||
|
||||
|
||||
status = jedis.pfcount("hll");
|
||||
assertEquals(3, status);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void pfcounts() {
|
||||
long status = jedis.pfadd("hll_1", "foo", "bar", "zap");
|
||||
assertEquals(1, status);
|
||||
status = jedis.pfadd("hll_2", "foo", "bar", "zap");
|
||||
assertEquals(1, status);
|
||||
status = jedis.pfadd("hll_2", "foo", "bar", "zap");
|
||||
assertEquals(1, status);
|
||||
|
||||
status = jedis.pfadd("hll_3", "foo", "bar", "baz");
|
||||
assertEquals(1, status);
|
||||
status = jedis.pfcount("hll_1");
|
||||
assertEquals(3, status);
|
||||
status = jedis.pfcount("hll_2");
|
||||
assertEquals(3, status);
|
||||
status = jedis.pfcount("hll_3");
|
||||
assertEquals(3, status);
|
||||
assertEquals(1, status);
|
||||
status = jedis.pfcount("hll_1");
|
||||
assertEquals(3, status);
|
||||
status = jedis.pfcount("hll_2");
|
||||
assertEquals(3, status);
|
||||
status = jedis.pfcount("hll_3");
|
||||
assertEquals(3, status);
|
||||
|
||||
status = jedis.pfcount("hll_1", "hll_2");
|
||||
assertEquals(3, status);
|
||||
|
||||
status = jedis.pfcount("hll_1", "hll_2", "hll_3");
|
||||
assertEquals(4, status);
|
||||
status = jedis.pfcount("hll_1", "hll_2");
|
||||
assertEquals(3, status);
|
||||
|
||||
status = jedis.pfcount("hll_1", "hll_2", "hll_3");
|
||||
assertEquals(4, status);
|
||||
|
||||
}
|
||||
|
||||
@@ -74,35 +73,35 @@ public class HyperLogLogCommandsTest extends JedisCommandTestBase {
|
||||
byte[] bFoo = SafeEncoder.encode("foo");
|
||||
byte[] bBar = SafeEncoder.encode("bar");
|
||||
byte[] bZap = SafeEncoder.encode("zap");
|
||||
|
||||
|
||||
long status = jedis.pfadd(bHll, bFoo, bBar, bZap);
|
||||
assertEquals(1, status);
|
||||
|
||||
|
||||
status = jedis.pfadd(bHll, bZap, bZap, bZap);
|
||||
assertEquals(0, status);
|
||||
|
||||
|
||||
status = jedis.pfadd(bHll, bFoo, bBar);
|
||||
assertEquals(0, status);
|
||||
|
||||
|
||||
status = jedis.pfcount(bHll);
|
||||
assertEquals(3, status);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void pfmerge() {
|
||||
long status = jedis.pfadd("hll1", "foo", "bar", "zap", "a");
|
||||
assertEquals(1, status);
|
||||
|
||||
|
||||
status = jedis.pfadd("hll2", "a", "b", "c", "foo");
|
||||
assertEquals(1, status);
|
||||
|
||||
|
||||
String mergeStatus = jedis.pfmerge("hll3", "hll1", "hll2");
|
||||
assertEquals("OK", mergeStatus);
|
||||
|
||||
|
||||
status = jedis.pfcount("hll3");
|
||||
assertEquals(6, status);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void pfmergeBinary() {
|
||||
byte[] bHll1 = SafeEncoder.encode("hll1");
|
||||
@@ -114,16 +113,16 @@ public class HyperLogLogCommandsTest extends JedisCommandTestBase {
|
||||
byte[] bA = SafeEncoder.encode("a");
|
||||
byte[] bB = SafeEncoder.encode("b");
|
||||
byte[] bC = SafeEncoder.encode("c");
|
||||
|
||||
|
||||
long status = jedis.pfadd(bHll1, bFoo, bBar, bZap, bA);
|
||||
assertEquals(1, status);
|
||||
|
||||
|
||||
status = jedis.pfadd(bHll2, bA, bB, bC, bFoo);
|
||||
assertEquals(1, status);
|
||||
|
||||
|
||||
String mergeStatus = jedis.pfmerge(bHll3, bHll1, bHll2);
|
||||
assertEquals("OK", mergeStatus);
|
||||
|
||||
|
||||
status = jedis.pfcount("hll3");
|
||||
assertEquals(6, status);
|
||||
}
|
||||
|
||||
@@ -64,64 +64,68 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
}, "foo");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void pubSubChannels(){
|
||||
final List<String> expectedActiveChannels = Arrays.asList("testchan1", "testchan2", "testchan3");
|
||||
public void pubSubChannels() {
|
||||
final List<String> expectedActiveChannels = Arrays.asList("testchan1",
|
||||
"testchan2", "testchan3");
|
||||
jedis.subscribe(new JedisPubSub() {
|
||||
private int count = 0;
|
||||
|
||||
@Override
|
||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscribe(String channel, int subscribedChannels) {
|
||||
count++;
|
||||
//All channels are subscribed
|
||||
if (count == 3) {
|
||||
Jedis otherJedis = createJedis();
|
||||
List<String> activeChannels = otherJedis.pubsubChannels("test*");
|
||||
assertTrue(expectedActiveChannels.containsAll(activeChannels));
|
||||
unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPMessage(String pattern, String channel, String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String channel, String message) {
|
||||
}
|
||||
}, "testchan1", "testchan2", "testchan3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pubSubNumPat(){
|
||||
jedis.psubscribe(new JedisPubSub() {
|
||||
private int count=0;
|
||||
private int count = 0;
|
||||
|
||||
@Override
|
||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSubscribe(String channel, int subscribedChannels) {
|
||||
count++;
|
||||
// All channels are subscribed
|
||||
if (count == 3) {
|
||||
Jedis otherJedis = createJedis();
|
||||
List<String> activeChannels = otherJedis
|
||||
.pubsubChannels("test*");
|
||||
assertTrue(expectedActiveChannels
|
||||
.containsAll(activeChannels));
|
||||
unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPMessage(String pattern, String channel,
|
||||
String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String channel, String message) {
|
||||
}
|
||||
}, "testchan1", "testchan2", "testchan3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pubSubNumPat() {
|
||||
jedis.psubscribe(new JedisPubSub() {
|
||||
private int count = 0;
|
||||
|
||||
@Override
|
||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscribe(String channel, int subscribedChannels) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||
count++;
|
||||
@@ -132,51 +136,55 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
punsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPMessage(String pattern, String channel, String message) {
|
||||
public void onPMessage(String pattern, String channel,
|
||||
String message) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onMessage(String channel, String message) {
|
||||
}
|
||||
}, "test*", "test*", "chan*");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void pubSubNumSub(){
|
||||
public void pubSubNumSub() {
|
||||
final Map<String, String> expectedNumSub = new HashMap<String, String>();
|
||||
expectedNumSub.put("testchannel2", "1");
|
||||
expectedNumSub.put("testchannel1", "1");
|
||||
jedis.subscribe(new JedisPubSub() {
|
||||
private int count=0;
|
||||
private int count = 0;
|
||||
|
||||
@Override
|
||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSubscribe(String channel, int subscribedChannels) {
|
||||
count++;
|
||||
if (count == 2) {
|
||||
Jedis otherJedis = createJedis();
|
||||
Map<String, String> numSub = otherJedis.pubsubNumSub("testchannel1", "testchannel2");
|
||||
Map<String, String> numSub = otherJedis.pubsubNumSub(
|
||||
"testchannel1", "testchannel2");
|
||||
assertEquals(expectedNumSub, numSub);
|
||||
unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPMessage(String pattern, String channel, String message) {
|
||||
public void onPMessage(String pattern, String channel,
|
||||
String message) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onMessage(String channel, String message) {
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Test;
|
||||
import redis.clients.jedis.BinaryJedis;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.BinaryJedis;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@@ -183,7 +184,8 @@ public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||
@Test
|
||||
public void scriptEvalReturnNullValues() {
|
||||
String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}";
|
||||
List<String> results = (List<String>) jedis.eval(script, 2, "key1", "key2", "1", "2");
|
||||
List<String> results = (List<String>) jedis.eval(script, 2, "key1",
|
||||
"key2", "1", "2");
|
||||
assertEquals("key1", results.get(0));
|
||||
assertEquals("key2", results.get(1));
|
||||
assertEquals("1", results.get(2));
|
||||
@@ -194,7 +196,8 @@ public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||
public void scriptEvalShaReturnNullValues() {
|
||||
String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}";
|
||||
String sha = jedis.scriptLoad(script);
|
||||
List<String> results = (List<String>) jedis.evalsha(sha, 2, "key1", "key2", "1", "2");
|
||||
List<String> results = (List<String>) jedis.evalsha(sha, 2, "key1",
|
||||
"key2", "1", "2");
|
||||
assertEquals("key1", results.get(0));
|
||||
assertEquals("key2", results.get(1));
|
||||
assertEquals("1", results.get(2));
|
||||
@@ -202,6 +205,6 @@ public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
private <T> Matcher<Iterable<? super T>> listWithItem(T expected) {
|
||||
return CoreMatchers.<T>hasItem(equalTo(expected));
|
||||
return CoreMatchers.<T> hasItem(equalTo(expected));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -8,8 +11,6 @@ import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.ScanParams;
|
||||
import redis.clients.jedis.ScanResult;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
public class SetCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -20,7 +21,7 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bc = { 0x0C };
|
||||
final byte[] bd = { 0x0D };
|
||||
final byte[] bx = { 0x42 };
|
||||
|
||||
|
||||
final byte[] bbar1 = { 0x05, 0x06, 0x07, 0x08, 0x0A };
|
||||
final byte[] bbar2 = { 0x05, 0x06, 0x07, 0x08, 0x0B };
|
||||
final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C };
|
||||
@@ -468,11 +469,12 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
|
||||
// binary
|
||||
jedis.sadd(bfoo, ba, bb);
|
||||
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo, SCAN_POINTER_START_BINARY);
|
||||
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
@@ -484,17 +486,19 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
params.match("a*");
|
||||
|
||||
jedis.sadd("foo", "b", "a", "aa");
|
||||
ScanResult<String> result = jedis.sscan("foo", SCAN_POINTER_START, params);
|
||||
ScanResult<String> result = jedis.sscan("foo", SCAN_POINTER_START,
|
||||
params);
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.match(bbarstar);
|
||||
|
||||
jedis.sadd(bfoo, bbar1, bbar2, bbar3);
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
@@ -507,16 +511,18 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
jedis.sadd("foo", "a1", "a2", "a3", "a4", "a5");
|
||||
|
||||
ScanResult<String> result = jedis.sscan("foo", SCAN_POINTER_START, params);
|
||||
ScanResult<String> result = jedis.sscan("foo", SCAN_POINTER_START,
|
||||
params);
|
||||
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.count(2);
|
||||
|
||||
|
||||
jedis.sadd(bfoo, bbar1, bbar2, bbar3);
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -10,8 +13,6 @@ import redis.clients.jedis.ScanResult;
|
||||
import redis.clients.jedis.Tuple;
|
||||
import redis.clients.jedis.ZParams;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -20,11 +21,11 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] ba = { 0x0A };
|
||||
final byte[] bb = { 0x0B };
|
||||
final byte[] bc = { 0x0C };
|
||||
final byte[] bInclusiveB = { 0x5B, 0x0B };
|
||||
final byte[] bExclusiveC = { 0x28, 0x0C };
|
||||
final byte[] bInclusiveB = { 0x5B, 0x0B };
|
||||
final byte[] bExclusiveC = { 0x28, 0x0C };
|
||||
final byte[] bLexMinusInf = { 0x2D };
|
||||
final byte[] bLexPlusInf = { 0x2B };
|
||||
|
||||
|
||||
final byte[] bbar1 = { 0x05, 0x06, 0x07, 0x08, 0x0A };
|
||||
final byte[] bbar2 = { 0x05, 0x06, 0x07, 0x08, 0x0B };
|
||||
final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C };
|
||||
@@ -58,7 +59,7 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals(0, bstatus);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void zrange() {
|
||||
jedis.zadd("foo", 1d, "a");
|
||||
@@ -95,29 +96,29 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals(bexpected, brange);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void zrangeByLex() {
|
||||
jedis.zadd("foo", 1, "aa");
|
||||
jedis.zadd("foo", 1, "c");
|
||||
jedis.zadd("foo", 1, "bb");
|
||||
jedis.zadd("foo", 1, "d");
|
||||
|
||||
|
||||
Set<String> expected = new LinkedHashSet<String>();
|
||||
expected.add("bb");
|
||||
expected.add("c");
|
||||
|
||||
|
||||
// exclusive aa ~ inclusive c
|
||||
assertEquals(expected, jedis.zrangeByLex("foo", "(aa", "[c"));
|
||||
|
||||
|
||||
expected.clear();
|
||||
expected.add("bb");
|
||||
expected.add("c");
|
||||
|
||||
|
||||
// with LIMIT
|
||||
assertEquals(expected, jedis.zrangeByLex("foo", "-", "+", 1, 2));
|
||||
assertEquals(expected, jedis.zrangeByLex("foo", "-", "+", 1, 2));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void zrangeByLexBinary() {
|
||||
// binary
|
||||
@@ -128,56 +129,60 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
Set<byte[]> bExpected = new LinkedHashSet<byte[]>();
|
||||
bExpected.add(bb);
|
||||
|
||||
assertEquals(bExpected, jedis.zrangeByLex(bfoo, bInclusiveB, bExclusiveC));
|
||||
assertEquals(bExpected,
|
||||
jedis.zrangeByLex(bfoo, bInclusiveB, bExclusiveC));
|
||||
|
||||
bExpected.clear();
|
||||
bExpected.add(ba);
|
||||
bExpected.add(bb);
|
||||
|
||||
// with LIMIT
|
||||
assertEquals(bExpected, jedis.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf, 0, 2));
|
||||
// with LIMIT
|
||||
assertEquals(bExpected,
|
||||
jedis.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf, 0, 2));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void zrevrangeByLex() {
|
||||
jedis.zadd("foo", 1, "aa");
|
||||
jedis.zadd("foo", 1, "c");
|
||||
jedis.zadd("foo", 1, "bb");
|
||||
jedis.zadd("foo", 1, "d");
|
||||
|
||||
|
||||
Set<String> expected = new LinkedHashSet<String>();
|
||||
expected.add("c");
|
||||
expected.add("bb");
|
||||
|
||||
|
||||
// exclusive aa ~ inclusive c
|
||||
assertEquals(expected, jedis.zrevrangeByLex("foo", "[c", "(aa"));
|
||||
|
||||
|
||||
expected.clear();
|
||||
expected.add("c");
|
||||
expected.add("bb");
|
||||
|
||||
|
||||
// with LIMIT
|
||||
assertEquals(expected, jedis.zrevrangeByLex("foo", "+", "-", 1, 2));
|
||||
assertEquals(expected, jedis.zrevrangeByLex("foo", "+", "-", 1, 2));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void zrevrangeByLexBinary() {
|
||||
// binary
|
||||
jedis.zadd(bfoo, 1, ba);
|
||||
jedis.zadd(bfoo, 1, bc);
|
||||
jedis.zadd(bfoo, 1, bb);
|
||||
|
||||
|
||||
Set<byte[]> bExpected = new LinkedHashSet<byte[]>();
|
||||
bExpected.add(bb);
|
||||
|
||||
assertEquals(bExpected, jedis.zrevrangeByLex(bfoo, bExclusiveC, bInclusiveB));
|
||||
|
||||
|
||||
assertEquals(bExpected,
|
||||
jedis.zrevrangeByLex(bfoo, bExclusiveC, bInclusiveB));
|
||||
|
||||
bExpected.clear();
|
||||
bExpected.add(bb);
|
||||
bExpected.add(ba);
|
||||
|
||||
// with LIMIT
|
||||
assertEquals(bExpected, jedis.zrevrangeByLex(bfoo, bLexPlusInf, bLexMinusInf, 0, 2));
|
||||
|
||||
// with LIMIT
|
||||
assertEquals(bExpected,
|
||||
jedis.zrevrangeByLex(bfoo, bLexPlusInf, bLexMinusInf, 0, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -489,7 +494,7 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(3, bresult);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void zlexcount() {
|
||||
jedis.zadd("foo", 1, "a");
|
||||
@@ -502,14 +507,14 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
result = jedis.zlexcount("foo", "-", "+");
|
||||
assertEquals(4, result);
|
||||
|
||||
|
||||
result = jedis.zlexcount("foo", "-", "(c");
|
||||
assertEquals(3, result);
|
||||
|
||||
|
||||
result = jedis.zlexcount("foo", "[aa", "+");
|
||||
assertEquals(3, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void zlexcountBinary() {
|
||||
// Binary
|
||||
@@ -861,7 +866,7 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(bexpected, jedis.zrange(bfoo, 0, 100));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void zremrangeByLex() {
|
||||
jedis.zadd("foo", 1, "a");
|
||||
@@ -879,22 +884,23 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(expected, jedis.zrangeByLex("foo", "-", "+"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void zremrangeByLexBinary() {
|
||||
jedis.zadd(bfoo, 1, ba);
|
||||
jedis.zadd(bfoo, 1, bc);
|
||||
jedis.zadd(bfoo, 1, bb);
|
||||
|
||||
|
||||
long bresult = jedis.zremrangeByLex(bfoo, bInclusiveB, bExclusiveC);
|
||||
|
||||
|
||||
assertEquals(1, bresult);
|
||||
|
||||
|
||||
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||
bexpected.add(ba);
|
||||
bexpected.add(bc);
|
||||
|
||||
assertEquals(bexpected, jedis.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf));
|
||||
|
||||
assertEquals(bexpected,
|
||||
jedis.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1062,12 +1068,13 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
|
||||
// binary
|
||||
jedis.zadd(bfoo, 1, ba);
|
||||
jedis.zadd(bfoo, 1, bb);
|
||||
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo, SCAN_POINTER_START_BINARY);
|
||||
|
||||
ScanResult<Tuple> bResult = jedis
|
||||
.zscan(bfoo, SCAN_POINTER_START_BINARY);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
@@ -1081,11 +1088,12 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
jedis.zadd("foo", 2, "b");
|
||||
jedis.zadd("foo", 1, "a");
|
||||
jedis.zadd("foo", 11, "aa");
|
||||
ScanResult<Tuple> result = jedis.zscan("foo", SCAN_POINTER_START, params);
|
||||
ScanResult<Tuple> result = jedis.zscan("foo", SCAN_POINTER_START,
|
||||
params);
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.match(bbarstar);
|
||||
@@ -1093,11 +1101,12 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
jedis.zadd(bfoo, 2, bbar1);
|
||||
jedis.zadd(bfoo, 1, bbar2);
|
||||
jedis.zadd(bfoo, 11, bbar3);
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1111,19 +1120,21 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
jedis.zadd("foo", 4, "a4");
|
||||
jedis.zadd("foo", 5, "a5");
|
||||
|
||||
ScanResult<Tuple> result = jedis.zscan("foo", SCAN_POINTER_START, params);
|
||||
ScanResult<Tuple> result = jedis.zscan("foo", SCAN_POINTER_START,
|
||||
params);
|
||||
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.count(2);
|
||||
|
||||
|
||||
jedis.zadd(bfoo, 2, bbar1);
|
||||
jedis.zadd(bfoo, 1, bbar2);
|
||||
jedis.zadd(bfoo, 11, bbar3);
|
||||
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@@ -125,8 +125,8 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void incrByFloatWrongValue() {
|
||||
jedis.set("foo", "bar");
|
||||
jedis.incrByFloat("foo", 2d);
|
||||
jedis.set("foo", "bar");
|
||||
jedis.incrByFloat("foo", 2d);
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
|
||||
@@ -16,16 +16,19 @@ public class JedisClusterCRC16Test {
|
||||
@Test
|
||||
public void testGetCRC16() throws Exception {
|
||||
Map<String, Integer> solutions = prepareSolutionSet();
|
||||
|
||||
|
||||
for (Entry<String, Integer> entry : solutions.entrySet()) {
|
||||
// string version
|
||||
assertEquals(entry.getValue().intValue(), JedisClusterCRC16.getCRC16(entry.getKey()));
|
||||
|
||||
assertEquals(entry.getValue().intValue(),
|
||||
JedisClusterCRC16.getCRC16(entry.getKey()));
|
||||
|
||||
// byte array version
|
||||
assertEquals(entry.getValue().intValue(), JedisClusterCRC16.getCRC16(SafeEncoder.encode(entry.getKey())));
|
||||
assertEquals(entry.getValue().intValue(),
|
||||
JedisClusterCRC16.getCRC16(SafeEncoder.encode(entry
|
||||
.getKey())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetSlot() {
|
||||
assertEquals(7186, JedisClusterCRC16.getSlot("51"));
|
||||
|
||||
@@ -5,7 +5,8 @@ import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
public class JedisClusterTestUtil {
|
||||
public static void waitForClusterReady(Jedis...nodes) throws InterruptedException {
|
||||
public static void waitForClusterReady(Jedis... nodes)
|
||||
throws InterruptedException {
|
||||
boolean clusterOk = false;
|
||||
while (!clusterOk) {
|
||||
boolean isOk = true;
|
||||
@@ -15,7 +16,7 @@ public class JedisClusterTestUtil {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isOk) {
|
||||
clusterOk = true;
|
||||
}
|
||||
@@ -23,7 +24,7 @@ public class JedisClusterTestUtil {
|
||||
Thread.sleep(50);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getNodeId(String infoOutput) {
|
||||
for (String infoLine : infoOutput.split("\n")) {
|
||||
if (infoLine.contains("myself")) {
|
||||
@@ -32,9 +33,9 @@ public class JedisClusterTestUtil {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String getNodeId(String infoOutput,HostAndPort node){
|
||||
|
||||
|
||||
public static String getNodeId(String infoOutput, HostAndPort node) {
|
||||
|
||||
for (String infoLine : infoOutput.split("\n")) {
|
||||
if (infoLine.contains(node.toString())) {
|
||||
return infoLine.split(" ")[0];
|
||||
@@ -42,31 +43,34 @@ public class JedisClusterTestUtil {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void assertNodeIsKnown(Jedis node, String targetNodeId, int timeoutMs) {
|
||||
|
||||
public static void assertNodeIsKnown(Jedis node, String targetNodeId,
|
||||
int timeoutMs) {
|
||||
assertNodeRecognizedStatus(node, targetNodeId, true, timeoutMs);
|
||||
}
|
||||
|
||||
public static void assertNodeIsUnknown(Jedis node, String targetNodeId, int timeoutMs) {
|
||||
public static void assertNodeIsUnknown(Jedis node, String targetNodeId,
|
||||
int timeoutMs) {
|
||||
assertNodeRecognizedStatus(node, targetNodeId, false, timeoutMs);
|
||||
}
|
||||
|
||||
private static void assertNodeRecognizedStatus(Jedis node, String targetNodeId, boolean shouldRecognized, int timeoutMs) {
|
||||
|
||||
private static void assertNodeRecognizedStatus(Jedis node,
|
||||
String targetNodeId, boolean shouldRecognized, int timeoutMs) {
|
||||
int sleepInterval = 100;
|
||||
for (int sleepTime = 0 ; sleepTime <= timeoutMs ; sleepTime += sleepInterval) {
|
||||
for (int sleepTime = 0; sleepTime <= timeoutMs; sleepTime += sleepInterval) {
|
||||
boolean known = isKnownNode(node, targetNodeId);
|
||||
if (shouldRecognized == known)
|
||||
return;
|
||||
|
||||
|
||||
try {
|
||||
Thread.sleep(sleepInterval);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
throw new JedisException("Node recognize check error");
|
||||
}
|
||||
|
||||
|
||||
private static boolean isKnownNode(Jedis node, String nodeId) {
|
||||
String infoOutput = node.clusterNodes();
|
||||
for (String infoLine : infoOutput.split("\n")) {
|
||||
@@ -76,6 +80,5 @@ public class JedisClusterTestUtil {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,13 +5,12 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.tests.utils.FailoverAbortedException;
|
||||
|
||||
public class JedisSentinelTestUtil {
|
||||
public static HostAndPort waitForNewPromotedMaster(final String masterName,
|
||||
final Jedis sentinelJedis, final Jedis commandJedis)
|
||||
public static HostAndPort waitForNewPromotedMaster(final String masterName,
|
||||
final Jedis sentinelJedis, final Jedis commandJedis)
|
||||
throws InterruptedException {
|
||||
|
||||
|
||||
final AtomicReference<String> newmaster = new AtomicReference<String>(
|
||||
"");
|
||||
|
||||
@@ -29,8 +28,9 @@ public class JedisSentinelTestUtil {
|
||||
punsubscribe();
|
||||
} else if (channel.startsWith("-failover-abort")) {
|
||||
punsubscribe();
|
||||
throw new FailoverAbortedException("Unfortunately sentinel cannot failover... reason(channel) : " +
|
||||
channel + " / message : " + message);
|
||||
throw new FailoverAbortedException(
|
||||
"Unfortunately sentinel cannot failover... reason(channel) : "
|
||||
+ channel + " / message : " + message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class JedisSentinelTestUtil {
|
||||
|
||||
@Override
|
||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||
commandJedis.sentinelFailover(masterName);
|
||||
commandJedis.sentinelFailover(masterName);
|
||||
}
|
||||
}, "*");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user