add support for java 1.5
This commit is contained in:
@@ -9,6 +9,7 @@ import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
import redis.clients.jedis.Protocol;
|
||||
import redis.clients.jedis.tests.commands.JedisCommandTestBase;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class JedisTest extends JedisCommandTestBase {
|
||||
@Test
|
||||
@@ -25,7 +26,7 @@ public class JedisTest extends JedisCommandTestBase {
|
||||
bigdata[b] = (byte) ((byte) b % 255);
|
||||
}
|
||||
Map<String, String> hash = new HashMap<String, String>();
|
||||
hash.put("data", new String(bigdata, Protocol.UTF8));
|
||||
hash.put("data", SafeEncoder.encode(bigdata));
|
||||
|
||||
String status = jedis.hmset("foo", hash);
|
||||
assertEquals("OK", status);
|
||||
|
||||
@@ -37,7 +37,7 @@ public class PipeliningTest extends Assert {
|
||||
});
|
||||
|
||||
assertEquals(2, results.size());
|
||||
assertArrayEquals("OK".getBytes(Protocol.UTF8), (byte[])results.get(0));
|
||||
assertArrayEquals("bar".getBytes(Protocol.UTF8), (byte[])results.get(1));
|
||||
assertArrayEquals("OK".getBytes(Protocol.CHARSET), (byte[])results.get(0));
|
||||
assertArrayEquals("bar".getBytes(Protocol.CHARSET), (byte[])results.get(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.junit.Test;
|
||||
import redis.clients.jedis.Protocol;
|
||||
import redis.clients.util.RedisInputStream;
|
||||
import redis.clients.util.RedisOutputStream;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class ProtocolTest extends JedisTestBase {
|
||||
@Test
|
||||
@@ -24,7 +25,7 @@ public class ProtocolTest extends JedisTestBase {
|
||||
|
||||
Protocol protocol = new Protocol();
|
||||
protocol.sendCommand(new RedisOutputStream(pos), Protocol.Command.GET,
|
||||
"SOMEKEY".getBytes(Protocol.UTF8));
|
||||
"SOMEKEY".getBytes(Protocol.CHARSET));
|
||||
|
||||
pos.close();
|
||||
String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n";
|
||||
@@ -43,7 +44,7 @@ public class ProtocolTest extends JedisTestBase {
|
||||
InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
byte[] response = (byte[]) protocol.read(new RedisInputStream(is));
|
||||
assertArrayEquals("foobar".getBytes(Protocol.UTF8), response);
|
||||
assertArrayEquals(SafeEncoder.encode("foobar"), response);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,8 +53,8 @@ public class ProtocolTest extends JedisTestBase {
|
||||
"$30\r\n012345678901234567890123456789\r\n".getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
byte[] response = (byte[]) protocol.read(new RedisInputStream(fis));
|
||||
assertArrayEquals("012345678901234567890123456789"
|
||||
.getBytes(Protocol.UTF8), response);
|
||||
assertArrayEquals(SafeEncoder.encode("012345678901234567890123456789"),
|
||||
response);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,7 +70,7 @@ public class ProtocolTest extends JedisTestBase {
|
||||
InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
byte[] response = (byte[]) protocol.read(new RedisInputStream(is));
|
||||
assertArrayEquals("OK".getBytes(Protocol.UTF8), response);
|
||||
assertArrayEquals(SafeEncoder.encode("OK"), response);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,10 +91,10 @@ public class ProtocolTest extends JedisTestBase {
|
||||
List<byte[]> response = (List<byte[]>) protocol
|
||||
.read(new RedisInputStream(is));
|
||||
List<byte[]> expected = new ArrayList<byte[]>();
|
||||
expected.add("foo".getBytes(Protocol.UTF8));
|
||||
expected.add("bar".getBytes(Protocol.UTF8));
|
||||
expected.add("Hello".getBytes(Protocol.UTF8));
|
||||
expected.add("World".getBytes(Protocol.UTF8));
|
||||
expected.add(SafeEncoder.encode("foo"));
|
||||
expected.add(SafeEncoder.encode("bar"));
|
||||
expected.add(SafeEncoder.encode("Hello"));
|
||||
expected.add(SafeEncoder.encode("World"));
|
||||
|
||||
assertEquals(expected, response);
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
import redis.clients.jedis.Protocol;
|
||||
import redis.clients.jedis.ShardedJedis;
|
||||
import redis.clients.jedis.ShardedJedisPipeline;
|
||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||
import redis.clients.util.Hashing;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class ShardedJedisTest extends Assert {
|
||||
private static HostAndPort redis1 = HostAndPortUtil.getRedisServers()
|
||||
@@ -143,11 +143,11 @@ public class ShardedJedisTest extends Assert {
|
||||
});
|
||||
|
||||
List<Object> expected = new ArrayList<Object>(2);
|
||||
expected.add("a".getBytes(Protocol.UTF8));
|
||||
expected.add("b".getBytes(Protocol.UTF8));
|
||||
expected.add(SafeEncoder.encode("a"));
|
||||
expected.add(SafeEncoder.encode("b"));
|
||||
|
||||
assertEquals(2, results.size());
|
||||
assertArrayEquals("a".getBytes(Protocol.UTF8), (byte[]) results.get(0));
|
||||
assertArrayEquals("b".getBytes(Protocol.UTF8), (byte[]) results.get(1));
|
||||
assertArrayEquals(SafeEncoder.encode("a"), (byte[]) results.get(0));
|
||||
assertArrayEquals(SafeEncoder.encode("b"), (byte[]) results.get(1));
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import java.util.Set;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.JedisException;
|
||||
import redis.clients.jedis.Protocol;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -447,8 +447,8 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals("hello world", result);
|
||||
|
||||
// Binary
|
||||
byte[] bresult = jedis.echo("hello world".getBytes(Protocol.UTF8));
|
||||
assertArrayEquals("hello world".getBytes(Protocol.UTF8), bresult);
|
||||
byte[] bresult = jedis.echo(SafeEncoder.encode("hello world"));
|
||||
assertArrayEquals(SafeEncoder.encode("hello world"), bresult);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Protocol;
|
||||
import redis.clients.jedis.Tuple;
|
||||
import redis.clients.jedis.ZParams;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -359,7 +359,7 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
bscore = jedis.zscore(bfoo, bc);
|
||||
assertEquals((Double) 0.1d, bscore);
|
||||
|
||||
bscore = jedis.zscore(bfoo, "s".getBytes(Protocol.UTF8));
|
||||
bscore = jedis.zscore(bfoo, SafeEncoder.encode("s"));
|
||||
assertNull(bscore);
|
||||
|
||||
}
|
||||
@@ -440,8 +440,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals(bexpected, brange);
|
||||
|
||||
brange = jedis.zrangeByScore(bfoo, 0d, 2d, 1, 1);
|
||||
Set<byte[]> brange2 = jedis.zrangeByScore(bfoo, "-inf"
|
||||
.getBytes(Protocol.UTF8), "(2".getBytes(Protocol.UTF8));
|
||||
Set<byte[]> brange2 = jedis.zrangeByScore(bfoo, SafeEncoder
|
||||
.encode("-inf"), SafeEncoder.encode("(2"));
|
||||
assertEquals(bexpected, brange2);
|
||||
|
||||
bexpected = new LinkedHashSet<byte[]>();
|
||||
@@ -601,8 +601,7 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
jedis.zadd(bbar, 2, ba);
|
||||
jedis.zadd(bbar, 2, bb);
|
||||
|
||||
int bresult = jedis.zunionstore("dst".getBytes(Protocol.UTF8), bfoo,
|
||||
bbar);
|
||||
int bresult = jedis.zunionstore(SafeEncoder.encode("dst"), bfoo, bbar);
|
||||
|
||||
assertEquals(2, bresult);
|
||||
|
||||
@@ -610,8 +609,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
bexpected.add(new Tuple(bb, new Double(4)));
|
||||
bexpected.add(new Tuple(ba, new Double(3)));
|
||||
|
||||
assertEquals(bexpected, jedis.zrangeWithScores("dst"
|
||||
.getBytes(Protocol.UTF8), 0, 100));
|
||||
assertEquals(bexpected, jedis.zrangeWithScores(SafeEncoder
|
||||
.encode("dst"), 0, 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -643,7 +642,7 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
ZParams bparams = new ZParams();
|
||||
bparams.weights(2, 2);
|
||||
bparams.aggregate(ZParams.Aggregate.SUM);
|
||||
int bresult = jedis.zunionstore("dst".getBytes(Protocol.UTF8), bparams,
|
||||
int bresult = jedis.zunionstore(SafeEncoder.encode("dst"), bparams,
|
||||
bfoo, bbar);
|
||||
|
||||
assertEquals(2, bresult);
|
||||
@@ -652,8 +651,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
bexpected.add(new Tuple(bb, new Double(8)));
|
||||
bexpected.add(new Tuple(ba, new Double(6)));
|
||||
|
||||
assertEquals(bexpected, jedis.zrangeWithScores("dst"
|
||||
.getBytes(Protocol.UTF8), 0, 100));
|
||||
assertEquals(bexpected, jedis.zrangeWithScores(SafeEncoder
|
||||
.encode("dst"), 0, 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -676,16 +675,15 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
jedis.zadd(bfoo, 2, bb);
|
||||
jedis.zadd(bbar, 2, ba);
|
||||
|
||||
int bresult = jedis.zinterstore("dst".getBytes(Protocol.UTF8), bfoo,
|
||||
bbar);
|
||||
int bresult = jedis.zinterstore(SafeEncoder.encode("dst"), bfoo, bbar);
|
||||
|
||||
assertEquals(1, bresult);
|
||||
|
||||
Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
|
||||
bexpected.add(new Tuple(ba, new Double(3)));
|
||||
|
||||
assertEquals(bexpected, jedis.zrangeWithScores("dst"
|
||||
.getBytes(Protocol.UTF8), 0, 100));
|
||||
assertEquals(bexpected, jedis.zrangeWithScores(SafeEncoder
|
||||
.encode("dst"), 0, 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -714,7 +712,7 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
ZParams bparams = new ZParams();
|
||||
bparams.weights(2, 2);
|
||||
bparams.aggregate(ZParams.Aggregate.SUM);
|
||||
int bresult = jedis.zinterstore("dst".getBytes(Protocol.UTF8), bparams,
|
||||
int bresult = jedis.zinterstore(SafeEncoder.encode("dst"), bparams,
|
||||
bfoo, bbar);
|
||||
|
||||
assertEquals(1, bresult);
|
||||
@@ -722,7 +720,7 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
|
||||
bexpected.add(new Tuple(ba, new Double(6)));
|
||||
|
||||
assertEquals(bexpected, jedis.zrangeWithScores("dst"
|
||||
.getBytes(Protocol.UTF8), 0, 100));
|
||||
assertEquals(bexpected, jedis.zrangeWithScores(SafeEncoder
|
||||
.encode("dst"), 0, 100));
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
t.set("mykey", val);
|
||||
List<Object> resp = t.exec();
|
||||
assertEquals(1, resp.size());
|
||||
assertArrayEquals(Keyword.OK.name().getBytes(Protocol.UTF8),
|
||||
assertArrayEquals(Keyword.OK.name().getBytes(Protocol.CHARSET),
|
||||
(byte[]) resp.get(0));
|
||||
|
||||
// Binary
|
||||
@@ -188,7 +188,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
t.set(bmykey, bval);
|
||||
resp = t.exec();
|
||||
assertEquals(1, resp.size());
|
||||
assertArrayEquals(Keyword.OK.name().getBytes(Protocol.UTF8),
|
||||
assertArrayEquals(Keyword.OK.name().getBytes(Protocol.CHARSET),
|
||||
(byte[]) resp.get(0));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user