@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); }
@Test public void fragmentedBulkReply() { FragmentedByteArrayInputStream fis = new FragmentedByteArrayInputStream("$30\r\n012345678901234567890123456789\r\n".getBytes()); byte[] response = (byte[]) Protocol.read(new RedisInputStream(fis)); assertArrayEquals(SafeEncoder.encode("012345678901234567890123456789"), response); }
public List<Object> getAll(int except) { List<Object> all = new ArrayList<Object>(); flush(); while (pipelinedCommands > except) { all.add(protocol.read(inputStream)); pipelinedCommands--; } return all; }
protected String getStatusCodeReply() { flush(); pipelinedCommands--; final byte[] resp = (byte[]) protocol.read(inputStream); if (null == resp) { return null; } else { return SafeEncoder.encode(resp); } }
@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."); }
public List<Object> getAll(int except) { List<Object> all = new ArrayList<Object>(); flush(); while (pipelinedCommands > except) { try { all.add(Protocol.read(inputStream)); } catch (JedisDataException e) { all.add(e); } pipelinedCommands--; } return all; }
@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")); assertEquals(expected, response); }
@Override public void run() { JedisDataException exception = null; try { while (isConnected()) { Response<?> response = asyncResponses.take(); Object data = Protocol.read(inputStream); response.set(data); wakeNextWriter(); } } catch (Exception ioe) { exception = new JedisDataException(ioe); } if (exception == null) { exception = new JedisDataException("Disconnected"); } // if something went wrong Response<?> response; while ((response = asyncResponses.poll()) != null) { response.set(exception); } }
@Test public void nullBulkReply() { InputStream is = new ByteArrayInputStream("$-1\r\n".getBytes()); String response = (String) Protocol.read(new RedisInputStream(is)); assertEquals(null, response); }
@Test public void bulkReply() { InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes()); byte[] response = (byte[]) Protocol.read(new RedisInputStream(is)); assertArrayEquals(SafeEncoder.encode("foobar"), response); }
@SuppressWarnings("unchecked") public List<Object> getObjectMultiBulkReply() { flush(); pipelinedCommands--; return (List<Object>) protocol.read(inputStream); }
public Long getIntegerReply() { flush(); pipelinedCommands--; return (Long) protocol.read(inputStream); }
public byte[] getBinaryBulkReply() { flush(); pipelinedCommands--; return (byte[]) protocol.read(inputStream); }
public Object getOne() { waitForAsyncReadsToComplete(); flush(); pipelinedCommands--; return Protocol.read(inputStream); }
@Test public void singleLineReply() { InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes()); byte[] response = (byte[]) Protocol.read(new RedisInputStream(is)); assertArrayEquals(SafeEncoder.encode("OK"), response); }
public Object getOne() { flush(); pipelinedCommands--; return protocol.read(inputStream); }
@Test public void integerReply() { InputStream is = new ByteArrayInputStream(":123\r\n".getBytes()); long response = (Long) Protocol.read(new RedisInputStream(is)); assertEquals(123, response); }
@SuppressWarnings("deprecation") public Double getDoubleReply() { flush(); pipelinedCommands--; return Double.valueOf(new String((byte[]) Protocol.read(inputStream))); }