Package com.taobao.gecko.core.buffer

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


    }


    @Test(expected = MetaCodecException.class)
    public void testDecodeUnknowCommand() {
        final IoBuffer buf = IoBuffer.wrap("just for test\r\n".getBytes());
        this.decoder.decode(buf, null);
    }
View Full Code Here


    }


    @Test
    public void testDecodeNotALine() {
        final IoBuffer buf = IoBuffer.wrap("just for test".getBytes());
        assertNull(this.decoder.decode(buf, null));
    }
View Full Code Here


    @Test
    public void decodePutCommandUnCompleteData() {

        IoBuffer buf = IoBuffer.wrap("put test 1 5 0 10\r\nhel".getBytes());

        PutCommand decodedCmd = (PutCommand) this.decoder.decode(buf, null);
        assertNull(decodedCmd);
        assertEquals(0, buf.position());
        assertEquals(buf.capacity(), buf.remaining());

        buf = IoBuffer.wrap("put test 1 5 0 10\r\nhello".getBytes());
        decodedCmd = (PutCommand) this.decoder.decode(buf, null);
        assertNotNull(decodedCmd);
        assertEquals("test", decodedCmd.getTopic());
        assertEquals(1, decodedCmd.getPartition());
        assertEquals(0, decodedCmd.getFlag());
        assertEquals(10, (int) decodedCmd.getOpaque());
        assertEquals("hello", new String(decodedCmd.getData()));
        assertFalse(buf.hasRemaining());

    }
View Full Code Here

    }


    @Test
    public void testDecodeTransactionCommand() {
        final IoBuffer buf = IoBuffer.wrap("transaction TX:sessionId:99 sessionId COMMIT_ONE_PHASE 100\r\n".getBytes());
        final TransactionCommand cmd = (TransactionCommand) this.decoder.decode(buf, null);
        assertNotNull(cmd);
        assertEquals(100, (int) cmd.getOpaque());
        assertEquals(0, cmd.getTransactionInfo().getTimeout());
        final TransactionInfo info = cmd.getTransactionInfo();
View Full Code Here

    }


    @Test
    public void testDecodeTransactionCommandWithTimeout() {
        final IoBuffer buf =
                IoBuffer.wrap("transaction TX:sessionId:99 sessionId COMMIT_ONE_PHASE 3 100\r\n".getBytes());
        final TransactionCommand cmd = (TransactionCommand) this.decoder.decode(buf, null);
        assertNotNull(cmd);
        assertEquals(100, (int) cmd.getOpaque());
        assertEquals(3, cmd.getTransactionInfo().getTimeout());
View Full Code Here

    }


    @Test
    public void testDecodeTransactionCommandWithUniqueQualifier() {
        final IoBuffer buf =
                IoBuffer.wrap("transaction TX:sessionId:99 sessionId COMMIT_ONE_PHASE unique-qualifier 100\r\n"
                    .getBytes());
        final TransactionCommand cmd = (TransactionCommand) this.decoder.decode(buf, null);
        assertNotNull(cmd);
        assertEquals(100, (int) cmd.getOpaque());
View Full Code Here

    }


    @Test
    public void testDecodeTransactionCommandWithTimeoutAndUniqueQualifier() {
        final IoBuffer buf =
                IoBuffer.wrap("transaction TX:sessionId:99 sessionId COMMIT_ONE_PHASE 3 unique-qualifier 100\r\n"
                    .getBytes());
        final TransactionCommand cmd = (TransactionCommand) this.decoder.decode(buf, null);
        assertNotNull(cmd);
        assertEquals(100, (int) cmd.getOpaque());
View Full Code Here

public class GetCommandUnitTest {
    @Test
    public void testEncode() {
        final GetCommand cmd = new GetCommand("test", "boyan-group", 1, 1000L, 1024 * 1024, -3);
        final IoBuffer buf = cmd.encode();
        assertEquals(0, buf.position());
        assertEquals("get test boyan-group 1 1000 1048576 -3\r\n", new String(buf.array()));
    }
View Full Code Here

public class OffsetCommandUnitTest {
    @Test
    public void testEncode() {
        final OffsetCommand cmd = new OffsetCommand("test", "boyan-test", 1, 1000L, -1);
        final IoBuffer buf = cmd.encode();
        assertEquals(0, buf.position());
        assertEquals("offset test boyan-test 1 1000 -1\r\n", new String(buf.array()));
    }
View Full Code Here

public class VersionCommandUnitTest {
    @Test
    public void testEncode() {
        final VersionCommand cmd = new VersionCommand(999);
        final IoBuffer buf = cmd.encode();
        assertEquals(0, buf.position());
        assertEquals("version 999\r\n", new String(buf.array()));
    }
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.