Refactored to support object multi bulk reply
This commit is contained in:
@@ -58,7 +58,7 @@ public class ProtocolTest extends Assert {
|
||||
public void singleLineReply() throws JedisException {
|
||||
InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
String response = protocol.getSingleLineReply(is);
|
||||
String response = protocol.getStatusCodeReply(is);
|
||||
assertEquals("OK", response);
|
||||
}
|
||||
|
||||
@@ -70,13 +70,15 @@ public class ProtocolTest extends Assert {
|
||||
assertEquals(123, response);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void multiBulkReply() throws JedisException {
|
||||
InputStream is = new ByteArrayInputStream(
|
||||
"*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n"
|
||||
.getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
List<String> response = protocol.getMultiBulkReply(is);
|
||||
List<String> response = (List<String>) (List<?>) protocol
|
||||
.getMultiBulkReply(is);
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("foo");
|
||||
expected.add("bar");
|
||||
@@ -84,5 +86,22 @@ public class ProtocolTest extends Assert {
|
||||
expected.add("World");
|
||||
|
||||
assertEquals(expected, response);
|
||||
|
||||
is = new ByteArrayInputStream(
|
||||
"*4\r\n$3\r\nfoo\r\n+OK\r\n:1000\r\n*2\r\n$3\r\nfoo\r\n$3\r\nbar"
|
||||
.getBytes());
|
||||
protocol = new Protocol();
|
||||
List<Object> response2 = protocol.getMultiBulkReply(is);
|
||||
List<Object> expected2 = new ArrayList<Object>();
|
||||
expected2.add("foo");
|
||||
expected2.add("OK");
|
||||
expected2.add(1000);
|
||||
List<Object> sub = new ArrayList<Object>();
|
||||
sub.add("foo");
|
||||
sub.add("bar");
|
||||
expected2.add(sub);
|
||||
|
||||
assertEquals(expected2, response2);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -39,14 +42,18 @@ public class TransactionCommandsTest extends Assert {
|
||||
status = trans.scard("foo");
|
||||
assertEquals("QUEUED", status);
|
||||
|
||||
trans.exec();
|
||||
|
||||
//TODO: check for exec response
|
||||
List<Object> response = trans.exec();
|
||||
|
||||
List<Object> expected = new ArrayList<Object>();
|
||||
expected.add(1);
|
||||
expected.add(1);
|
||||
expected.add(2);
|
||||
assertEquals(expected, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiBlock() throws JedisException {
|
||||
jedis.multi(new TransactionBlock() {
|
||||
List<Object> response = jedis.multi(new TransactionBlock() {
|
||||
public void execute() throws JedisException {
|
||||
String status = sadd("foo", "a");
|
||||
assertEquals("QUEUED", status);
|
||||
@@ -58,7 +65,11 @@ public class TransactionCommandsTest extends Assert {
|
||||
assertEquals("QUEUED", status);
|
||||
}
|
||||
});
|
||||
|
||||
//TODO: check what happens when throwind an exception
|
||||
|
||||
List<Object> expected = new ArrayList<Object>();
|
||||
expected.add(1);
|
||||
expected.add(1);
|
||||
expected.add(2);
|
||||
assertEquals(expected, response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user