Package com.taobao.gecko.core.buffer

Examples of com.taobao.gecko.core.buffer.IoBuffer


    }


    @Override
    public void write(final GetCommand getCommand, final SessionContext ctx) {
        final IoBuffer buf = this.makeHead(getCommand.getOpaque(), this.sizeInBytes.get());
        // transfer to socket
        this.tryToLogTransferInfo(getCommand, ctx.getConnection());
        ctx.getConnection().transferFrom(buf, null, this.channel, this.offset, this.sizeInBytes.get());
    }
View Full Code Here


    }


    // value totalLen opaque\r\n
    IoBuffer makeHead(final int opaque, final long size) {
        final IoBuffer buf = IoBuffer.allocate(9 + ByteUtils.stringSize(opaque) + ByteUtils.stringSize(size));
        ByteUtils.setArguments(buf, "value", size, opaque);
        buf.flip();
        return buf;
    }
View Full Code Here

public class StatsCommandUnitTest {
    @Test
    public void testEncodeEmptyItem() {
        final StatsCommand cmd = new StatsCommand(-1000, null);
        final IoBuffer buf = cmd.encode();
        assertEquals(0, buf.position());
        assertEquals("stats  -1000\r\n", new String(buf.array()));
    }
View Full Code Here


    @Test
    public void testEncodeWithItem() {
        final StatsCommand cmd = new StatsCommand(-1000, "topics");
        final IoBuffer buf = cmd.encode();
        assertEquals(0, buf.position());
        assertEquals("stats topics -1000\r\n", new String(buf.array()));
    }
View Full Code Here


    @Test
    public void testDecodeSyncCommand() {
        final SyncCommand syncCmd = new SyncCommand("test", 1, "hello".getBytes(), 0, 9999L, 0, -1);
        final IoBuffer buf = syncCmd.encode();

        final SyncCommand decodedCmd = (SyncCommand) this.decoder.decode(buf, null);
        assertNotNull(decodedCmd);
        assertEquals(9999L, decodedCmd.getMsgId());
        // assertNotNull(decodedCmd.getTransactionId());
        assertEquals(syncCmd, decodedCmd);
        assertEquals(syncCmd.getMsgId(), decodedCmd.getMsgId());
        assertFalse(buf.hasRemaining());
    }
View Full Code Here


    @Test
    public void testDecodeGetCommand() {
        final GetCommand cmd = new GetCommand("test", "boyan", 1, 1000L, 1024 * 1024, -3);
        final IoBuffer buf = cmd.encode();

        final GetCommand decodedCmd = (GetCommand) this.decoder.decode(buf, null);
        assertNotNull(decodedCmd);
        assertEquals(cmd, decodedCmd);
        assertFalse(buf.hasRemaining());
    }
View Full Code Here


    @Test
    public void testDecodeDataCommand() {

        final IoBuffer buf = IoBuffer.allocate(100);
        buf.put("value 5 99\r\nhello".getBytes());
        buf.flip();

        final DataCommand decodedCmd = (DataCommand) this.decoder.decode(buf, null);
        assertNotNull(decodedCmd);
        assertEquals((Integer) 99, decodedCmd.getOpaque());
        assertEquals("hello", new String(decodedCmd.getData()));
        assertFalse(buf.hasRemaining());
    }
View Full Code Here


    @Test
    public void testDecodeBooleanCommand() {
        final BooleanCommand cmd = new BooleanCommand(HttpStatus.NotFound, "not found", 99);
        final IoBuffer buf = cmd.encode();
        final BooleanCommand decodedCmd = (BooleanCommand) this.decoder.decode(buf, null);
        assertNotNull(decodedCmd);
        assertEquals(cmd, decodedCmd);
        assertFalse(buf.hasRemaining());
    }
View Full Code Here

    }


    @Test
    public void testDecodeVersion() {
        IoBuffer buf = IoBuffer.wrap("version\r\n".getBytes());
        VersionCommand versionCommand = (VersionCommand) this.decoder.decode(buf, null);
        assertNotNull(versionCommand);
        assertEquals(Integer.MAX_VALUE, (int) versionCommand.getOpaque());

        buf = IoBuffer.wrap("version -1\r\n".getBytes());
View Full Code Here


    @Test
    public void testDecodeOffsetCommand() {
        final OffsetCommand cmd = new OffsetCommand("test", "boyan", 1, 1000L, -1);
        final IoBuffer buf = cmd.encode();
        final OffsetCommand decodedCmd = (OffsetCommand) this.decoder.decode(buf, null);
        assertNotNull(decodedCmd);
        assertEquals(cmd, decodedCmd);
        assertFalse(buf.hasRemaining());
    }
View Full Code Here

TOP

Related Classes of com.taobao.gecko.core.buffer.IoBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.