Add U test for fragmented processBulkReply patch.
This commit is contained in:
committed by
Jonathan Leibiusky
parent
de5030e13f
commit
97e2a50f60
@@ -0,0 +1,30 @@
|
|||||||
|
package redis.clients.jedis.tests;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class the fragment a byte array for testing purpose.
|
||||||
|
*/
|
||||||
|
public class FragmentedByteArrayInputStream extends ByteArrayInputStream {
|
||||||
|
private int readMethodCallCount = 0;
|
||||||
|
public FragmentedByteArrayInputStream(final byte[] buf) {
|
||||||
|
super(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized int read(final byte[] b, final int off, final int len) {
|
||||||
|
readMethodCallCount++;
|
||||||
|
if (len <= 10) {
|
||||||
|
// if the len <= 10, return as usual ..
|
||||||
|
return super.read(b, off, len);
|
||||||
|
} else {
|
||||||
|
// else return the first half ..
|
||||||
|
return super.read(b, off, len / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getReadMethodCallCount() {
|
||||||
|
return readMethodCallCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -47,6 +47,16 @@ public class ProtocolTest extends Assert {
|
|||||||
assertEquals("foobar", response);
|
assertEquals("foobar", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
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));
|
||||||
|
assertEquals("012345678901234567890123456789", response);
|
||||||
|
assertEquals(3, fis.getReadMethodCallCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nullBulkReply() {
|
public void nullBulkReply() {
|
||||||
InputStream is = new ByteArrayInputStream("$-1\r\n".getBytes());
|
InputStream is = new ByteArrayInputStream("$-1\r\n".getBytes());
|
||||||
|
|||||||
Reference in New Issue
Block a user