Search in sources :

Example 11 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.

the class Http2ServerDowngraderTest method testUpgradeEmptyEnd.

@Test
public void testUpgradeEmptyEnd() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
    LastHttpContent end = LastHttpContent.EMPTY_LAST_CONTENT;
    assertTrue(ch.writeOutbound(end));
    Http2DataFrame emptyFrame = ch.readOutbound();
    try {
        assertThat(emptyFrame.content().readableBytes(), is(0));
        assertTrue(emptyFrame.isEndStream());
    } finally {
        emptyFrame.release();
    }
    assertThat(ch.readOutbound(), is(nullValue()));
    assertFalse(ch.finish());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Test(org.junit.Test)

Example 12 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.

the class Http2ServerDowngraderTest method testUpgradeEmptyFullResponse.

@Test
public void testUpgradeEmptyFullResponse() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
    assertTrue(ch.writeOutbound(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)));
    Http2HeadersFrame headersFrame = ch.readOutbound();
    assertThat(headersFrame.headers().status().toString(), is("200"));
    assertTrue(headersFrame.isEndStream());
    assertThat(ch.readOutbound(), is(nullValue()));
    assertFalse(ch.finish());
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 13 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.

the class Http2ServerDowngraderTest method testUpgradeTrailers.

@Test
public void testUpgradeTrailers() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
    LastHttpContent trailers = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER, true);
    HttpHeaders headers = trailers.trailingHeaders();
    headers.set("key", "value");
    assertTrue(ch.writeOutbound(trailers));
    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) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Test(org.junit.Test)

Example 14 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.

the class Http2ServerDowngraderTest method testUpgradeHeaders.

@Test
public void testUpgradeHeaders() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    assertTrue(ch.writeOutbound(response));
    Http2HeadersFrame headersFrame = ch.readOutbound();
    assertThat(headersFrame.headers().status().toString(), is("200"));
    assertFalse(headersFrame.isEndStream());
    assertThat(ch.readOutbound(), is(nullValue()));
    assertFalse(ch.finish());
}
Also used : DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) Test(org.junit.Test)

Example 15 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.

the class Http2FrameCodecTest method setUp.

@Before
public void setUp() throws Exception {
    frameWriter = spy(new VerifiableHttp2FrameWriter());
    framingCodec = new Http2FrameCodec(true, frameWriter, new Http2FrameLogger(LogLevel.TRACE), new Http2Settings());
    frameListener = ((DefaultHttp2ConnectionDecoder) framingCodec.connectionHandler().decoder()).internalFrameListener();
    inboundHandler = new LastInboundHandler();
    channel = new EmbeddedChannel();
    channel.connect(new InetSocketAddress(0));
    channel.pipeline().addLast(framingCodec);
    channel.pipeline().addLast(inboundHandler);
    http2HandlerCtx = channel.pipeline().context(framingCodec.connectionHandler());
    // Handshake
    verify(frameWriter).writeSettings(eq(http2HandlerCtx), anyHttp2Settings(), anyChannelPromise());
    verifyNoMoreInteractions(frameWriter);
    channel.writeInbound(Http2CodecUtil.connectionPrefaceBuf());
    frameListener.onSettingsRead(http2HandlerCtx, new Http2Settings());
    verify(frameWriter).writeSettingsAck(eq(http2HandlerCtx), anyChannelPromise());
    frameListener.onSettingsAckRead(http2HandlerCtx);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Before(org.junit.Before)

Aggregations

EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1027 Test (org.junit.jupiter.api.Test)515 ByteBuf (io.netty.buffer.ByteBuf)356 Test (org.junit.Test)342 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)85 HttpResponse (io.netty.handler.codec.http.HttpResponse)73 HttpRequest (io.netty.handler.codec.http.HttpRequest)69 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)64 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)60 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)55 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)50 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)49 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)46 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)42 IOException (java.io.IOException)38 InetSocketAddress (java.net.InetSocketAddress)38 Executable (org.junit.jupiter.api.function.Executable)36 ArrayList (java.util.ArrayList)34 Before (org.junit.Before)32 ChannelHandler (io.netty.channel.ChannelHandler)27