Search in sources :

Example 1 with RedisOutputStream

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

the class ProtocolBenchmark method measureCommand.

private static long measureCommand() throws Exception {
    long duration = 0;
    byte[] KEY = "123456789".getBytes();
    byte[] VAL = "FooBar".getBytes();
    for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
        RedisOutputStream out = new RedisOutputStream(new ByteArrayOutputStream(8192));
        long start = System.nanoTime();
        Protocol.sendCommand(out, Protocol.Command.SET, KEY, VAL);
        duration += (System.nanoTime() - start);
    }
    return duration;
}
Also used : RedisOutputStream(redis.clients.util.RedisOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with RedisOutputStream

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

the class ProtocolTest method writeOverflow.

@Test(expected = IOException.class)
public void writeOverflow() throws IOException {
    RedisOutputStream ros = new RedisOutputStream(new OutputStream() {

        @Override
        public void write(int b) throws IOException {
            throw new IOException("thrown exception");
        }
    });
    ros.write(new byte[8191]);
    try {
        ros.write((byte) '*');
    } catch (IOException ioe) {
    }
    ros.write((byte) '*');
}
Also used : OutputStream(java.io.OutputStream) RedisOutputStream(redis.clients.util.RedisOutputStream) PipedOutputStream(java.io.PipedOutputStream) RedisOutputStream(redis.clients.util.RedisOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with RedisOutputStream

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

the class ProtocolTest method buildACommand.

@Test
public void buildACommand() throws IOException {
    PipedInputStream pis = new PipedInputStream();
    BufferedInputStream bis = new BufferedInputStream(pis);
    PipedOutputStream pos = new PipedOutputStream(pis);
    RedisOutputStream ros = new RedisOutputStream(pos);
    Protocol.sendCommand(ros, Protocol.Command.GET, "SOMEKEY".getBytes(Protocol.CHARSET));
    ros.flush();
    pos.close();
    String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n";
    int b;
    StringBuilder sb = new StringBuilder();
    while ((b = bis.read()) != -1) {
        sb.append((char) b);
    }
    assertEquals(expectedCommand, sb.toString());
}
Also used : BufferedInputStream(java.io.BufferedInputStream) RedisOutputStream(redis.clients.util.RedisOutputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Test(org.junit.Test)

Example 4 with RedisOutputStream

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

the class ProtocolTest method writeOverflow.

@Test(expected = IOException.class)
public void writeOverflow() throws IOException {
    RedisOutputStream ros = new RedisOutputStream(new OutputStream() {

        @Override
        public void write(int b) throws IOException {
            throw new IOException("thrown exception");
        }
    });
    ros.write(new byte[8191]);
    try {
        ros.write((byte) '*');
    } catch (IOException ioe) {
    }
    ros.write((byte) '*');
}
Also used : OutputStream(java.io.OutputStream) RedisOutputStream(redis.clients.util.RedisOutputStream) PipedOutputStream(java.io.PipedOutputStream) RedisOutputStream(redis.clients.util.RedisOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with RedisOutputStream

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

the class ProtocolTest method buildACommand.

@Test
public void buildACommand() throws IOException {
    PipedInputStream pis = new PipedInputStream();
    BufferedInputStream bis = new BufferedInputStream(pis);
    PipedOutputStream pos = new PipedOutputStream(pis);
    RedisOutputStream ros = new RedisOutputStream(pos);
    Protocol.sendCommand(ros, Protocol.Command.GET, "SOMEKEY".getBytes(Protocol.CHARSET));
    ros.flush();
    pos.close();
    String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n";
    int b;
    StringBuilder sb = new StringBuilder();
    while ((b = bis.read()) != -1) {
        sb.append((char) b);
    }
    assertEquals(expectedCommand, sb.toString());
}
Also used : BufferedInputStream(java.io.BufferedInputStream) RedisOutputStream(redis.clients.util.RedisOutputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Test(org.junit.Test)

Aggregations

RedisOutputStream (redis.clients.util.RedisOutputStream)11 PipedOutputStream (java.io.PipedOutputStream)6 Test (org.junit.Test)6 IOException (java.io.IOException)5 BufferedInputStream (java.io.BufferedInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStream (java.io.OutputStream)3 PipedInputStream (java.io.PipedInputStream)3 InetSocketAddress (java.net.InetSocketAddress)2 Socket (java.net.Socket)2 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)2 RedisInputStream (redis.clients.util.RedisInputStream)2