io.netty.buffer.DefaultByteBufHolder Java Examples

The following examples show how to use io.netty.buffer.DefaultByteBufHolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoggingHandlerTest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldLogByteBufHolderDataRead() throws Exception {
    ByteBufHolder msg = new DefaultByteBufHolder(Unpooled.copiedBuffer("hello", CharsetUtil.UTF_8)) {
        @Override
        public String toString() {
            return "foobar";
        }
    };

    EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
    channel.writeInbound(msg);
    verify(appender).doAppend(argThat(new RegexLogMatcher(".+READ: foobar, 5B$")));

    ByteBufHolder handledMsg = channel.readInbound();
    assertThat(msg, is(sameInstance(handledMsg)));
    handledMsg.release();
    assertThat(channel.readInbound(), is(nullValue()));
}
 
Example #2
Source File: MessageAggregatorTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testReadFlowManagement() throws Exception {
    ReadCounter counter = new ReadCounter();
    ByteBufHolder first = message("first");
    ByteBufHolder chunk = message("chunk");
    ByteBufHolder last = message("last");

    MockMessageAggregator agg = spy(MockMessageAggregator.class);
    when(agg.isStartMessage(first)).thenReturn(true);
    when(agg.isContentMessage(chunk)).thenReturn(true);
    when(agg.isContentMessage(last)).thenReturn(true);
    when(agg.isLastContentMessage(last)).thenReturn(true);

    EmbeddedChannel embedded = new EmbeddedChannel(counter, agg);
    embedded.config().setAutoRead(false);

    assertFalse(embedded.writeInbound(first));
    assertFalse(embedded.writeInbound(chunk));
    assertTrue(embedded.writeInbound(last));

    assertEquals(3, counter.value); // 2 reads issued from MockMessageAggregator
                                    // 1 read issued from EmbeddedChannel constructor

    ByteBufHolder all = new DefaultByteBufHolder(Unpooled.wrappedBuffer(
        first.content().retain(), chunk.content().retain(), last.content().retain()));
    ByteBufHolder out = embedded.readInbound();

    assertEquals(all, out);
    assertTrue(all.release() && out.release());
    assertFalse(embedded.finish());
}
 
Example #3
Source File: MessageAggregatorTest.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
private static ByteBufHolder message(String string) {
    return new DefaultByteBufHolder(
        Unpooled.copiedBuffer(string, CharsetUtil.US_ASCII));
}