Package io.netty.buffer

Examples of io.netty.buffer.CompositeByteBuf$Component


            ByteBuf buf = (ByteBuf) msg;
            if (!buf.hasMemoryAddress() && (PlatformDependent.hasUnsafe() || !buf.isDirect())) {
                if (buf instanceof CompositeByteBuf) {
                    // Special handling of CompositeByteBuf to reduce memory copies if some of the Components
                    // in the CompositeByteBuf are backed by a memoryAddress.
                    CompositeByteBuf comp = (CompositeByteBuf) buf;
                    if (!comp.isDirect() || comp.nioBufferCount() > Native.IOV_MAX) {
                        // more then 1024 buffers for gathering writes so just do a memory copy.
                        buf = newDirectBuffer(buf);
                        assert buf.hasMemoryAddress();
                    }
                } else {
View Full Code Here


        checkContentBuffer(aggratedMessage);
        assertNull(embedder.readInbound());
    }

    private static void checkContentBuffer(FullHttpRequest aggregatedMessage) {
        CompositeByteBuf buffer = (CompositeByteBuf) aggregatedMessage.content();
        assertEquals(2, buffer.numComponents());
        List<ByteBuf> buffers = buffer.decompose(0, buffer.capacity());
        assertEquals(2, buffers.size());
        for (ByteBuf buf: buffers) {
            // This should be false as we decompose the buffer before to not have deep hierarchy
            assertFalse(buf instanceof CompositeByteBuf);
        }
View Full Code Here

                int split =  buf.readableBytes() / 2;
                int size = buf.readableBytes() - split;
                int oldIndex = buf.writerIndex();
                buf.writerIndex(split);
                ByteBuf buf2 = Unpooled.buffer(size).writeBytes(buf, split, oldIndex - split);
                CompositeByteBuf comp = Unpooled.compositeBuffer();
                comp.addComponent(buf).addComponent(buf2).writerIndex(length);
                cc.write(comp);
            } else {
                cc.write(buf);
            }
            i += length;
View Full Code Here

    public void testNioBuffersExpand2() {
        TestChannel channel = new TestChannel();

        ChannelOutboundBuffer buffer = new ChannelOutboundBuffer(channel);

        CompositeByteBuf comp = compositeBuffer(256);
        ByteBuf buf = directBuffer().writeBytes("buf1".getBytes(CharsetUtil.US_ASCII));
        for (int i = 0; i < 65; i++) {
            comp.addComponent(buf.copy()).writerIndex(comp.writerIndex() + buf.readableBytes());
        }
        buffer.addMessage(comp, comp.readableBytes(), channel.voidPromise());

        assertEquals("Should still be 0 as not flushed yet", 0, buffer.nioBufferCount());
        buffer.addFlush();
        ByteBuffer[] buffers = buffer.nioBuffers();
        assertEquals(65, buffer.nioBufferCount());
View Full Code Here

    public void testSimpleSendCompositeDirectByteBuf() throws Throwable {
        run();
    }

    public void testSimpleSendCompositeDirectByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
        CompositeByteBuf buf = Unpooled.compositeBuffer();
        buf.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 0, 2));
        buf.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 2, 2));
        buf.writerIndex(4);
        testSimpleSend0(sb, cb, buf, true, BYTES, 1);

        CompositeByteBuf buf2 = Unpooled.compositeBuffer();
        buf2.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 0, 2));
        buf2.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 2, 2));
        buf2.writerIndex(4);
        testSimpleSend0(sb, cb, buf2, true, BYTES, 4);
    }
View Full Code Here

    public void testSimpleSendCompositeHeapByteBuf() throws Throwable {
        run();
    }

    public void testSimpleSendCompositeHeapByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
        CompositeByteBuf buf = Unpooled.compositeBuffer();
        buf.addComponent(Unpooled.buffer().writeBytes(BYTES, 0, 2));
        buf.addComponent(Unpooled.buffer().writeBytes(BYTES, 2, 2));
        buf.writerIndex(4);
        testSimpleSend0(sb, cb, buf, true, BYTES, 1);

        CompositeByteBuf buf2 = Unpooled.compositeBuffer();
        buf2.addComponent(Unpooled.buffer().writeBytes(BYTES, 0, 2));
        buf2.addComponent(Unpooled.buffer().writeBytes(BYTES, 2, 2));
        buf2.writerIndex(4);
        testSimpleSend0(sb, cb, buf2, true, BYTES, 4);
    }
View Full Code Here

    public void testSimpleSendCompositeMixedByteBuf() throws Throwable {
        run();
    }

    public void testSimpleSendCompositeMixedByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
        CompositeByteBuf buf = Unpooled.compositeBuffer();
        buf.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 0, 2));
        buf.addComponent(Unpooled.buffer().writeBytes(BYTES, 2, 2));
        buf.writerIndex(4);
        testSimpleSend0(sb, cb, buf, true, BYTES, 1);

        CompositeByteBuf buf2 = Unpooled.compositeBuffer();
        buf2.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 0, 2));
        buf2.addComponent(Unpooled.buffer().writeBytes(BYTES, 2, 2));
        buf2.writerIndex(4);
        testSimpleSend0(sb, cb, buf2, true, BYTES, 4);
    }
View Full Code Here

    db.prepareDbUnit(getClass(), "migrate_components.xml");

    migration.execute();
    session.commit();

    Component root = mapper.selectComponentByKey("org.struts:struts");
    assertThat(root.getUuid()).isNotNull();
    assertThat(root.getProjectUuid()).isEqualTo(root.getUuid());
    assertThat(root.getModuleUuid()).isNull();
    assertThat(root.getModuleUuidPath()).isNull();

    Component module = mapper.selectComponentByKey("org.struts:struts-core");
    assertThat(module.getUuid()).isNotNull();
    assertThat(module.getProjectUuid()).isEqualTo(root.getUuid());
    assertThat(module.getModuleUuid()).isEqualTo(root.getUuid());
    assertThat(module.getModuleUuidPath()).isEqualTo(root.getUuid());

    Component subModule = mapper.selectComponentByKey("org.struts:struts-db");
    assertThat(subModule.getUuid()).isNotNull();
    assertThat(subModule.getProjectUuid()).isEqualTo(root.getUuid());
    assertThat(subModule.getModuleUuid()).isEqualTo(module.getUuid());
    assertThat(subModule.getModuleUuidPath()).isEqualTo(root.getUuid() + "." + module.getUuid());

    Component directory = mapper.selectComponentByKey("org.struts:struts-core:src/org/struts");
    assertThat(directory.getUuid()).isNotNull();
    assertThat(directory.getProjectUuid()).isEqualTo(root.getUuid());
    assertThat(directory.getModuleUuid()).isEqualTo(subModule.getUuid());
    assertThat(directory.getModuleUuidPath()).isEqualTo(root.getUuid() + "." + module.getUuid() + "." + subModule.getUuid());

    Component file = mapper.selectComponentByKey("org.struts:struts-core:src/org/struts/RequestContext.java");
    assertThat(file.getUuid()).isNotNull();
    assertThat(file.getProjectUuid()).isEqualTo(root.getUuid());
    assertThat(file.getModuleUuid()).isEqualTo(subModule.getUuid());
    assertThat(file.getModuleUuidPath()).isEqualTo(root.getUuid() + "." + module.getUuid() + "." + subModule.getUuid());

    // Verify that each generated uuid is unique
    assertThat(ImmutableSet.of(root.getUuid(), module.getUuid(), subModule.getUuid(), directory.getUuid(), file.getUuid())).hasSize(5);
  }
View Full Code Here

    db.prepareDbUnit(getClass(), "not_migrate_already_migrated_components.xml");

    migration.execute();
    session.commit();

    Component root = mapper.selectComponentByKey("org.struts:struts");
    assertThat(root.getUuid()).isEqualTo("ABCD");
    assertThat(root.getProjectUuid()).isEqualTo("ABCD");
    assertThat(root.getModuleUuid()).isNull();
    assertThat(root.getModuleUuidPath()).isNull();

    Component module = mapper.selectComponentByKey("org.struts:struts-core");
    assertThat(module.getUuid()).isEqualTo("BCDE");
    assertThat(module.getProjectUuid()).isEqualTo("ABCD");
    assertThat(module.getModuleUuid()).isEqualTo("ABCD");
    assertThat(module.getModuleUuidPath()).isEqualTo("ABCD");

    Component subModule = mapper.selectComponentByKey("org.struts:struts-db");
    assertThat(subModule.getUuid()).isNotNull();
    assertThat(subModule.getProjectUuid()).isEqualTo("ABCD");
    assertThat(subModule.getModuleUuid()).isEqualTo("BCDE");
    assertThat(subModule.getModuleUuidPath()).isEqualTo("ABCD.BCDE");

    Component directory = mapper.selectComponentByKey("org.struts:struts-core:src/org/struts");
    assertThat(directory.getUuid()).isNotNull();
    assertThat(directory.getProjectUuid()).isEqualTo("ABCD");
    assertThat(directory.getModuleUuid()).isEqualTo(subModule.getUuid());
    assertThat(directory.getModuleUuidPath()).isEqualTo("ABCD.BCDE." + subModule.getUuid());

    Component file = mapper.selectComponentByKey("org.struts:struts-core:src/org/struts/RequestContext.java");
    assertThat(file.getUuid()).isNotNull();
    assertThat(file.getProjectUuid()).isEqualTo("ABCD");
    assertThat(file.getModuleUuid()).isEqualTo(subModule.getUuid());
    assertThat(file.getModuleUuidPath()).isEqualTo("ABCD.BCDE." + subModule.getUuid());

    Component removedFile = mapper.selectComponentByKey("org.struts:struts-core:src/org/struts/RequestContext2.java");
    assertThat(removedFile.getUuid()).isEqualTo("DCBA");
    assertThat(removedFile.getProjectUuid()).isEqualTo("ABCD");
    assertThat(removedFile.getModuleUuid()).isEqualTo("BCDE");
    assertThat(removedFile.getModuleUuidPath()).isEqualTo("ABCD.BCDE");
  }
View Full Code Here

    db.prepareDbUnit(getClass(), "migrate_disable_components.xml");

    migration.execute();
    session.commit();

    Component root = mapper.selectComponentByKey("org.struts:struts");
    assertThat(root.getUuid()).isNotNull();

    Component module = mapper.selectComponentByKey("org.struts:struts-core");
    assertThat(module.getUuid()).isNotNull();
    assertThat(module.getProjectUuid()).isEqualTo(root.getUuid());
    // Module and module path will always be null for removed components
    assertThat(module.getModuleUuid()).isNull();
    assertThat(module.getModuleUuidPath()).isNull();

    Component subModule = mapper.selectComponentByKey("org.struts:struts-db");
    assertThat(subModule.getUuid()).isNotNull();
    assertThat(subModule.getProjectUuid()).isEqualTo(root.getUuid());
    // Module and module path will always be null for removed components
    assertThat(subModule.getModuleUuid()).isNull();
    assertThat(subModule.getModuleUuidPath()).isNull();

    Component directory = mapper.selectComponentByKey("org.struts:struts-core:src/org/struts");
    assertThat(directory.getUuid()).isNotNull();
    assertThat(directory.getProjectUuid()).isEqualTo(root.getUuid());
    // Module and module path will always be null for removed components
    assertThat(directory.getModuleUuid()).isNull();
    assertThat(directory.getModuleUuidPath()).isNull();

    Component file = mapper.selectComponentByKey("org.struts:struts-core:src/org/struts/RequestContext.java");
    assertThat(file.getUuid()).isNotNull();
    assertThat(file.getProjectUuid()).isEqualTo(root.getUuid());
    // Module and module path will always be null for removed components
    assertThat(file.getModuleUuid()).isNull();
    assertThat(file.getModuleUuidPath()).isNull();
  }
View Full Code Here

TOP

Related Classes of io.netty.buffer.CompositeByteBuf$Component

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.