ByteArrayOutputStream os;
Reply receive;
{
os = new ByteArrayOutputStream();
String message = "OK";
new StatusReply(message).write(os);
receive = RedisProtocol.receive(new ByteArrayInputStream(os.toByteArray()));
assertTrue(receive instanceof StatusReply);
assertEquals(message, receive.data());
}
{
os = new ByteArrayOutputStream();
String message = "OK";
new ErrorReply(message).write(os);
receive = RedisProtocol.receive(new ByteArrayInputStream(os.toByteArray()));
assertTrue(receive instanceof ErrorReply);
assertEquals(message, receive.data());
}
{
os = new ByteArrayOutputStream();
String message = "OK";
new BulkReply(message.getBytes()).write(os);
receive = RedisProtocol.receive(new ByteArrayInputStream(os.toByteArray()));
assertTrue(receive instanceof BulkReply);
assertEquals(message, new String((byte[]) receive.data()));
}
{
os = new ByteArrayOutputStream();
long integer = 999;
new IntegerReply(integer).write(os);
receive = RedisProtocol.receive(new ByteArrayInputStream(os.toByteArray()));
assertTrue(receive instanceof IntegerReply);
assertEquals(integer, receive.data());
}
{
os = new ByteArrayOutputStream();
String message = "OK";
long integer = 999;
new MultiBulkReply(new Reply[] {
new StatusReply(message),
new ErrorReply(message),
new MultiBulkReply(new Reply[] { new StatusReply(message)}),
new BulkReply(message.getBytes()),
new IntegerReply(integer)}).write(os);
receive = RedisProtocol.receive(new ByteArrayInputStream(os.toByteArray()));
assertTrue(receive instanceof MultiBulkReply);
Reply[] data = (Reply[]) receive.data();