Search in sources :

Example 76 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project neo4j by neo4j.

the class NetworkFlushableChannelNetty4Test method shouldNotCountBytesAlreadyInBuffer.

@Test
public void shouldNotCountBytesAlreadyInBuffer() throws Exception {
    // Given
    int sizeLimit = 100;
    ByteBuf buffer = Unpooled.buffer();
    int padding = Long.BYTES;
    buffer.writeLong(0);
    NetworkFlushableChannelNetty4 channel = new NetworkFlushableChannelNetty4(buffer, sizeLimit);
    // When
    for (int i = 0; i < sizeLimit - padding; i++) {
        channel.put((byte) 0);
    }
    // again, when
    for (int i = 0; i < padding; i++) {
        channel.put((byte) 0);
    }
    // finally, when we pass the limit
    try {
        channel.put((byte) 0);
        fail("Should not allow more bytes than what the limit dictates");
    } catch (MessageTooBigException e) {
    // then
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 77 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project netty by netty.

the class Http2MultiplexCodecTest method inboundDataFrameShouldEmitWindowUpdateFrame.

@Test
public void inboundDataFrameShouldEmitWindowUpdateFrame() {
    LastInboundHandler inboundHandler = streamActiveAndWriteHeaders(streamId);
    ByteBuf tenBytes = bb("0123456789");
    parentChannel.pipeline().fireChannelRead(new DefaultHttp2DataFrame(tenBytes, true).streamId(streamId));
    parentChannel.pipeline().flush();
    Http2WindowUpdateFrame windowUpdate = parentChannel.readOutbound();
    assertNotNull(windowUpdate);
    assertEquals(streamId, windowUpdate.streamId());
    assertEquals(10, windowUpdate.windowSizeIncrement());
    // headers and data frame
    verifyFramesMultiplexedToCorrectChannel(streamId, inboundHandler, 2);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 78 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project netty by netty.

the class Http2ServerDowngraderTest method testUpgradeNonEmptyFullResponse.

@Test
public void testUpgradeNonEmptyFullResponse() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
    ByteBuf hello = Unpooled.copiedBuffer("hello world", CharsetUtil.UTF_8);
    assertTrue(ch.writeOutbound(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, hello)));
    Http2HeadersFrame headersFrame = ch.readOutbound();
    assertThat(headersFrame.headers().status().toString(), is("200"));
    assertFalse(headersFrame.isEndStream());
    Http2DataFrame dataFrame = ch.readOutbound();
    try {
        assertThat(dataFrame.content().toString(CharsetUtil.UTF_8), is("hello world"));
        assertTrue(dataFrame.isEndStream());
    } finally {
        dataFrame.release();
    }
    assertThat(ch.readOutbound(), is(nullValue()));
    assertFalse(ch.finish());
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 79 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project netty by netty.

the class Http2ServerDowngraderTest method testUpgradeDataEndWithTrailers.

@Test
public void testUpgradeDataEndWithTrailers() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
    ByteBuf hello = Unpooled.copiedBuffer("hello world", CharsetUtil.UTF_8);
    LastHttpContent trailers = new DefaultLastHttpContent(hello, true);
    HttpHeaders headers = trailers.trailingHeaders();
    headers.set("key", "value");
    assertTrue(ch.writeOutbound(trailers));
    Http2DataFrame dataFrame = ch.readOutbound();
    try {
        assertThat(dataFrame.content().toString(CharsetUtil.UTF_8), is("hello world"));
        assertFalse(dataFrame.isEndStream());
    } finally {
        dataFrame.release();
    }
    Http2HeadersFrame headerFrame = ch.readOutbound();
    assertThat(headerFrame.headers().get("key").toString(), is("value"));
    assertTrue(headerFrame.isEndStream());
    assertThat(ch.readOutbound(), is(nullValue()));
    assertFalse(ch.finish());
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Test(org.junit.Test)

Example 80 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project netty by netty.

the class Http2ServerDowngraderTest method testUpgradeDataEnd.

@Test
public void testUpgradeDataEnd() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
    ByteBuf hello = Unpooled.copiedBuffer("hello world", CharsetUtil.UTF_8);
    LastHttpContent end = new DefaultLastHttpContent(hello, true);
    assertTrue(ch.writeOutbound(end));
    Http2DataFrame dataFrame = ch.readOutbound();
    try {
        assertThat(dataFrame.content().toString(CharsetUtil.UTF_8), is("hello world"));
        assertTrue(dataFrame.isEndStream());
    } finally {
        dataFrame.release();
    }
    assertThat(ch.readOutbound(), is(nullValue()));
    assertFalse(ch.finish());
}
Also used : DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)5080 Test (org.junit.Test)1813 Test (org.junit.jupiter.api.Test)680 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)377 ArrayList (java.util.ArrayList)301 IOException (java.io.IOException)297 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)200 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)182 ByteBuffer (java.nio.ByteBuffer)167 InetSocketAddress (java.net.InetSocketAddress)145 ByteBuf (org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf)144 Test (org.testng.annotations.Test)140 Channel (io.netty.channel.Channel)137 List (java.util.List)134 ChannelFuture (io.netty.channel.ChannelFuture)128 Map (java.util.Map)118 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)107 Position (org.traccar.model.Position)105 DeviceSession (org.traccar.DeviceSession)100 NetworkMessage (org.traccar.NetworkMessage)93