Package com.taobao.gecko.core.buffer

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


    }


    @Test
    public void testMakeHead() throws Exception {
        final IoBuffer head = this.fileMessageSet.makeHead(-1999, 100);
        assertEquals(0, head.position());
        assertTrue(head.hasRemaining());
        assertEquals("value 100 -1999\r\n", new String(head.array()));
    }
View Full Code Here


        assertEquals(2L * str.length(), subSet.highWaterMark());
        final Connection conn = EasyMock.createMock(Connection.class);
        EasyMock.expect(conn.getRemoteSocketAddress()).andReturn(new InetSocketAddress(8181)).anyTimes();

        final int opaque = 99;
        final IoBuffer head = IoBuffer.wrap(("value " + 2 * str.length() + " " + opaque + "\r\n").getBytes());
        conn.transferFrom(head, null, this.fileMessageSet.channel(), 0, 2 * str.length());
        EasyMock.expectLastCall();
        EasyMock.replay(conn);

        subSet.write(new GetCommand("test", "boyan-test", -1, 0, 1024 * 1024, opaque), new SessionContextImpl(null,
View Full Code Here

public class SyncCommandUnitTest {

    @Test
    public void testEncode() {
        final SyncCommand putCommand = new SyncCommand("test", 1, "hello".getBytes(), 0, 9999L, 777, 0);
        final IoBuffer buf = putCommand.encode();
        assertEquals(0, buf.position());
        assertEquals("sync test 1 5 0 9999 777 0\r\nhello", new String(buf.array()));
    }
View Full Code Here

    private ResponseCommand processStatsConfig(final StatsCommand request, final SessionContext ctx) {
        try {
            final FileChannel fc = new FileInputStream(this.metaConfig.getConfigFilePath()).getChannel();
            // result code length opaque\r\n
            IoBuffer buf =
                    IoBuffer.allocate(11 + 3 + ByteUtils.stringSize(fc.size())
                        + ByteUtils.stringSize(request.getOpaque()));
            ByteUtils.setArguments(buf, MetaEncodeCommand.RESULT_CMD, HttpStatus.Success, fc.size(),
                request.getOpaque());
            buf.flip();
            ctx.getConnection().transferFrom(buf, null, fc, 0, fc.size(), request.getOpaque(),
                new SingleRequestCallBackListener() {

                @Override
                public void onResponse(ResponseCommand responseCommand, Connection conn) {
View Full Code Here

    @Test
    public void testEncode_HasTransactionId() {
        final TransactionId id = new LocalTransactionId("test", 1);
        final PutCommand putCommand = new PutCommand("test", 1, "hello".getBytes(), id, 0, 0);
        final IoBuffer buf = putCommand.encode();
        assertEquals(0, buf.position());
        assertEquals("put test 1 5 0 -1 TX:test:1 0\r\nhello", new String(buf.array()));
    }
View Full Code Here


    @Test
    public void testEncode_NoTransactionId() {
        final PutCommand putCommand = new PutCommand("test", 1, "hello".getBytes(), null, 0, 0);
        final IoBuffer buf = putCommand.encode();
        assertEquals(0, buf.position());
        assertEquals("put test 1 5 0 -1 0\r\nhello", new String(buf.array()));
    }
View Full Code Here

public class QuitCommandUnitTest {
    @Test
    public void testEncode() {
        final QuitCommand cmd = new QuitCommand();
        final IoBuffer buf = cmd.encode();
        assertEquals(0, buf.position());
        assertEquals("quit\r\n", new String(buf.array()));
    }
View Full Code Here

public class BooleanCommandUnitTest {
    @Test
    public void testEncodeWithMessage() {
        final BooleanCommand cmd = new BooleanCommand(HttpStatus.NotFound, "not found", 99);
        final IoBuffer buf = cmd.encode();
        assertEquals(0, buf.position());
        assertEquals("result 404 9 99\r\nnot found", new String(buf.array()));
    }
View Full Code Here


    @Test
    public void testEncodeWithoutMessage() {
        final BooleanCommand cmd = new BooleanCommand(HttpStatus.NotFound, null, 99);
        final IoBuffer buf = cmd.encode();
        assertEquals(0, buf.position());
        assertEquals("result 404 0 99\r\n", new String(buf.array()));
    }
View Full Code Here

public class DataCommandCommandUnitTest {
    @Test
    public void testEncodeWithMessage() {
        final DataCommand cmd = new DataCommand("hello".getBytes(), 99, true);
        final IoBuffer buf = cmd.encode();
        assertEquals(0, buf.position());
        assertEquals("value 5 99\r\nhello", 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.