Search in sources :

Example 1 with RedisInputStream

use of redis.clients.util.RedisInputStream in project jedis by xetorthio.

the class ProtocolTest method busyReply.

@Test
public void busyReply() {
    final String busyMessage = "BUSY Redis is busy running a script.";
    final InputStream is = new ByteArrayInputStream(('-' + busyMessage + "\r\n").getBytes());
    try {
        Protocol.read(new RedisInputStream(is));
    } catch (final JedisBusyException e) {
        assertEquals(busyMessage, e.getMessage());
        return;
    }
    fail("Expected a JedisBusyException to be thrown.");
}
Also used : JedisBusyException(redis.clients.jedis.exceptions.JedisBusyException) ByteArrayInputStream(java.io.ByteArrayInputStream) RedisInputStream(redis.clients.util.RedisInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) RedisInputStream(redis.clients.util.RedisInputStream) Test(org.junit.Test)

Example 2 with RedisInputStream

use of redis.clients.util.RedisInputStream in project jedis by xetorthio.

the class ProtocolTest method nullMultiBulkReply.

@SuppressWarnings("unchecked")
@Test
public void nullMultiBulkReply() {
    InputStream is = new ByteArrayInputStream("*-1\r\n".getBytes());
    List<String> response = (List<String>) Protocol.read(new RedisInputStream(is));
    assertNull(response);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RedisInputStream(redis.clients.util.RedisInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) List(java.util.List) RedisInputStream(redis.clients.util.RedisInputStream) Test(org.junit.Test)

Example 3 with RedisInputStream

use of redis.clients.util.RedisInputStream in project jedis by xetorthio.

the class ProtocolTest method integerReply.

@Test
public void integerReply() {
    InputStream is = new ByteArrayInputStream(":123\r\n".getBytes());
    long response = (Long) Protocol.read(new RedisInputStream(is));
    assertEquals(123, response);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RedisInputStream(redis.clients.util.RedisInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) RedisInputStream(redis.clients.util.RedisInputStream) Test(org.junit.Test)

Example 4 with RedisInputStream

use of redis.clients.util.RedisInputStream in project jedis by xetorthio.

the class ProtocolTest method multiBulkReply.

@SuppressWarnings("unchecked")
@Test
public void multiBulkReply() {
    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());
    List<byte[]> response = (List<byte[]>) Protocol.read(new RedisInputStream(is));
    List<byte[]> expected = new ArrayList<byte[]>();
    expected.add(SafeEncoder.encode("foo"));
    expected.add(SafeEncoder.encode("bar"));
    expected.add(SafeEncoder.encode("Hello"));
    expected.add(SafeEncoder.encode("World"));
    assertByteArrayListEquals(expected, response);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RedisInputStream(redis.clients.util.RedisInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RedisInputStream(redis.clients.util.RedisInputStream) Test(org.junit.Test)

Example 5 with RedisInputStream

use of redis.clients.util.RedisInputStream in project cachecloud by sohutv.

the class ProtocolTest method integerReply.

@Test
public void integerReply() {
    InputStream is = new ByteArrayInputStream(":123\r\n".getBytes());
    long response = (Long) Protocol.read(new RedisInputStream(is));
    assertEquals(123, response);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RedisInputStream(redis.clients.util.RedisInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) RedisInputStream(redis.clients.util.RedisInputStream) Test(org.junit.Test)

Aggregations

RedisInputStream (redis.clients.util.RedisInputStream)27 ByteArrayInputStream (java.io.ByteArrayInputStream)25 InputStream (java.io.InputStream)25 BufferedInputStream (java.io.BufferedInputStream)19 PipedInputStream (java.io.PipedInputStream)19 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)6 List (java.util.List)6 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 Socket (java.net.Socket)2 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)2 RedisOutputStream (redis.clients.util.RedisOutputStream)2 JedisBusyException (redis.clients.jedis.exceptions.JedisBusyException)1