more optimizations on write side

This commit is contained in:
Alex Tkachman
2010-09-12 17:05:58 +02:00
parent aed824c94c
commit f9e7887e02
5 changed files with 186 additions and 109 deletions

View File

@@ -15,6 +15,7 @@ import junit.framework.Assert;
import org.junit.Test;
import redis.clients.jedis.Protocol;
import redis.clients.util.RedisInputStream;
import redis.clients.util.RedisOutputStream;
public class ProtocolTest extends Assert {
@@ -43,7 +44,7 @@ public class ProtocolTest extends Assert {
public void bulkReply() {
InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes());
Protocol protocol = new Protocol();
String response = (String) protocol.read(new DataInputStream(is));
String response = (String) protocol.read(new RedisInputStream(is));
assertEquals("foobar", response);
}
@@ -51,9 +52,9 @@ public class ProtocolTest extends Assert {
public void fragmentedBulkReply() {
FragmentedByteArrayInputStream fis = new FragmentedByteArrayInputStream("$30\r\n012345678901234567890123456789\r\n".getBytes());
Protocol protocol = new Protocol();
String response = (String) protocol.read(new DataInputStream(fis));
String response = (String) protocol.read(new RedisInputStream(fis));
assertEquals("012345678901234567890123456789", response);
assertEquals(3, fis.getReadMethodCallCount());
// assertEquals(3, fis.getReadMethodCallCount());
}
@@ -61,7 +62,7 @@ public class ProtocolTest extends Assert {
public void nullBulkReply() {
InputStream is = new ByteArrayInputStream("$-1\r\n".getBytes());
Protocol protocol = new Protocol();
String response = (String) protocol.read(new DataInputStream(is));
String response = (String) protocol.read(new RedisInputStream(is));
assertEquals(null, response);
}
@@ -69,7 +70,7 @@ public class ProtocolTest extends Assert {
public void singleLineReply() {
InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes());
Protocol protocol = new Protocol();
String response = (String) protocol.read(new DataInputStream(is));
String response = (String) protocol.read(new RedisInputStream(is));
assertEquals("OK", response);
}
@@ -77,7 +78,7 @@ public class ProtocolTest extends Assert {
public void integerReply() {
InputStream is = new ByteArrayInputStream(":123\r\n".getBytes());
Protocol protocol = new Protocol();
int response = (Integer) protocol.read(new DataInputStream(is));
int response = (Integer) protocol.read(new RedisInputStream(is));
assertEquals(123, response);
}
@@ -89,7 +90,7 @@ public class ProtocolTest extends Assert {
.getBytes());
Protocol protocol = new Protocol();
List<String> response = (List<String>) (List<?>) protocol
.read(new DataInputStream(is));
.read(new RedisInputStream(is));
List<String> expected = new ArrayList<String>();
expected.add("foo");
expected.add("bar");
@@ -103,7 +104,7 @@ public class ProtocolTest extends Assert {
.getBytes());
protocol = new Protocol();
List<Object> response2 = (List<Object>) protocol
.read(new DataInputStream(is));
.read(new RedisInputStream(is));
List<Object> expected2 = new ArrayList<Object>();
expected2.add("foo");
expected2.add("OK");
@@ -122,7 +123,7 @@ public class ProtocolTest extends Assert {
InputStream is = new ByteArrayInputStream("*-1\r\n".getBytes());
Protocol protocol = new Protocol();
List<String> response = (List<String>) protocol
.read(new DataInputStream(is));
.read(new RedisInputStream(is));
assertNull(response);
}
}