Fix Lettuce and SRP blpop/brpop issues

- DATAREDIS-127 Fix Lettuce NPE on timeout

- DATAREDIS-128 Fix SRP arg array conversion and NPE
on timeout
This commit is contained in:
Jennifer Hickey
2013-03-20 15:07:42 -07:00
parent 9642b7ea72
commit 8553552d2b
4 changed files with 54 additions and 9 deletions

View File

@@ -151,6 +151,9 @@ abstract class LettuceUtils {
}
static List<byte[]> toList(KeyValue<byte[], byte[]> blpop) {
if(blpop == null) {
return null;
}
List<byte[]> list = new ArrayList<byte[]>(2);
list.add(blpop.key);
list.add(blpop.value);

View File

@@ -17,7 +17,6 @@
package org.springframework.data.redis.connection.srp;
import java.io.StringReader;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
@@ -83,6 +82,9 @@ abstract class SrpUtils {
}
static List<byte[]> toBytesList(Reply[] replies) {
if(replies == null) {
return null;
}
List<byte[]> list = new ArrayList<byte[]>(replies.length);
for (Reply reply : replies) {
Object data = reply.data();
@@ -149,19 +151,15 @@ abstract class SrpUtils {
}
static Object[] convert(int timeout, byte[]... keys) {
int length = (keys != null ? keys.length : 0);
// add the int representation
length = 1;
int length = (keys != null ? keys.length + 1 : 1);
Object[] args = new Object[length];
if (keys != null) {
for (int i = 0; i < args.length - 1; i++) {
for (int i = 0; i < keys.length; i++) {
args[i] = keys[i];
}
}
ByteBuffer bb = ByteBuffer.allocate(4);
bb.putInt(timeout);
args[args.length - 1] = bb.array();
args[length-1] = String.valueOf(timeout).getBytes();
return args;
}

View File

@@ -377,6 +377,30 @@ public abstract class AbstractConnectionIntegrationTests {
assertEquals(new String(value), new String((byte[])results.get(1)));
}
@Test
public void testBlPopTimeout() {
assertNull(connection.bLPop(1, "lclist"));
}
@Test
public void testBlPop() {
connection.lPush("poplist", "foo");
connection.lPush("poplist", "bar");
assertEquals(Arrays.asList(new String[] {"poplist", "bar"}), connection.bLPop(1, "poplist", "otherlist"));
}
@Test
public void testBRPop() {
connection.rPush("rpoplist", "bar");
connection.rPush("rpoplist", "foo");
assertEquals(Arrays.asList(new String[] {"rpoplist", "foo"}), connection.bRPop(1, "rpoplist"));
}
@Test
public void testBRPopTimeout() {
assertNull(connection.bRPop(1, "rclist"));
}
private boolean isAsync() {
return (getConnectionFactory() instanceof LettuceConnectionFactory) ||
(getConnectionFactory() instanceof SrpConnectionFactory);

View File

@@ -97,4 +97,24 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
public void testExecuteNativeWithPipeline() throws Exception {
super.testExecuteNativeWithPipeline();
}
@Test(expected = UnsupportedOperationException.class)
public void testBlPopTimeout() {
super.testBlPopTimeout();
}
@Test(expected = UnsupportedOperationException.class)
public void testBlPop() {
super.testBlPop();
}
@Test(expected = UnsupportedOperationException.class)
public void testBRPop() {
super.testBRPop();
}
@Test(expected = UnsupportedOperationException.class)
public void testBRPopTimeout() {
super.testBRPopTimeout();
}
}