Search in sources :

Example 21 with Http2Runnable

use of io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable in project netty by netty.

the class Http2ConnectionRoundtripTest method headersWithEndStreamShouldNotSendError.

@Test
public void headersWithEndStreamShouldNotSendError() throws Exception {
    bootstrapEnv(1, 1, 2, 1);
    // Create a single stream by sending a HEADERS frame to the server.
    final short weight = 16;
    final Http2Headers headers = dummyHeaders();
    runInChannel(clientChannel, new Http2Runnable() {

        @Override
        public void run() throws Http2Exception {
            http2Client.encoder().writeHeaders(ctx(), 3, headers, 0, weight, false, 0, true, newPromise());
            http2Client.flush(ctx());
        }
    });
    assertTrue(requestLatch.await(DEFAULT_AWAIT_TIMEOUT_SECONDS, SECONDS));
    verify(serverListener).onHeadersRead(any(ChannelHandlerContext.class), eq(3), eq(headers), eq(0), eq(weight), eq(false), eq(0), eq(true));
    // Wait for some time to see if a go_away or reset frame will be received.
    Thread.sleep(1000);
    // Verify that no errors have been received.
    verify(serverListener, never()).onGoAwayRead(any(ChannelHandlerContext.class), anyInt(), anyLong(), any(ByteBuf.class));
    verify(serverListener, never()).onRstStreamRead(any(ChannelHandlerContext.class), anyInt(), anyLong());
    // The server will not respond, and so don't wait for graceful shutdown
    setClientGracefulShutdownTime(0);
}
Also used : Http2Runnable(io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 22 with Http2Runnable

use of io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable in project netty by netty.

the class DataCompressionHttp2Test method zstdEncodingSingleMessage.

@Test
public void zstdEncodingSingleMessage() throws Exception {
    final String text = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccc";
    final ByteBuf data = Unpooled.copiedBuffer(text.getBytes(CharsetUtil.UTF_8.name()));
    bootstrapEnv(data.readableBytes());
    try {
        final Http2Headers headers = new DefaultHttp2Headers().method(POST).path(PATH).set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.ZSTD);
        runInChannel(clientChannel, new Http2Runnable() {

            @Override
            public void run() throws Http2Exception {
                clientEncoder.writeHeaders(ctxClient(), 3, headers, 0, false, newPromiseClient());
                clientEncoder.writeData(ctxClient(), 3, data.retain(), 0, true, newPromiseClient());
                clientHandler.flush(ctxClient());
            }
        });
        awaitServer();
        assertEquals(text, serverOut.toString(CharsetUtil.UTF_8.name()));
    } finally {
        data.release();
    }
}
Also used : Http2Runnable(io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable) AsciiString(io.netty.util.AsciiString) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 23 with Http2Runnable

use of io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable in project netty by netty.

the class DataCompressionHttp2Test method gzipEncodingSingleEmptyMessage.

@Test
public void gzipEncodingSingleEmptyMessage() throws Exception {
    final String text = "";
    final ByteBuf data = Unpooled.copiedBuffer(text.getBytes());
    bootstrapEnv(data.readableBytes());
    try {
        final Http2Headers headers = new DefaultHttp2Headers().method(POST).path(PATH).set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.GZIP);
        runInChannel(clientChannel, new Http2Runnable() {

            @Override
            public void run() throws Http2Exception {
                clientEncoder.writeHeaders(ctxClient(), 3, headers, 0, false, newPromiseClient());
                clientEncoder.writeData(ctxClient(), 3, data.retain(), 0, true, newPromiseClient());
                clientHandler.flush(ctxClient());
            }
        });
        awaitServer();
        assertEquals(text, serverOut.toString(CharsetUtil.UTF_8.name()));
    } finally {
        data.release();
    }
}
Also used : Http2Runnable(io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable) AsciiString(io.netty.util.AsciiString) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 24 with Http2Runnable

use of io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable in project netty by netty.

the class DataCompressionHttp2Test method brotliEncodingSingleEmptyMessage.

@Test
public void brotliEncodingSingleEmptyMessage() throws Exception {
    final String text = "";
    final ByteBuf data = Unpooled.copiedBuffer(text.getBytes());
    bootstrapEnv(data.readableBytes());
    try {
        final Http2Headers headers = new DefaultHttp2Headers().method(POST).path(PATH).set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.BR);
        runInChannel(clientChannel, new Http2Runnable() {

            @Override
            public void run() throws Http2Exception {
                clientEncoder.writeHeaders(ctxClient(), 3, headers, 0, false, newPromiseClient());
                clientEncoder.writeData(ctxClient(), 3, data.retain(), 0, true, newPromiseClient());
                clientHandler.flush(ctxClient());
            }
        });
        awaitServer();
        assertEquals(text, serverOut.toString(CharsetUtil.UTF_8.name()));
    } finally {
        data.release();
    }
}
Also used : Http2Runnable(io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable) AsciiString(io.netty.util.AsciiString) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 25 with Http2Runnable

use of io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable in project netty by netty.

the class DataCompressionHttp2Test method gzipEncodingSingleMessage.

@Test
public void gzipEncodingSingleMessage() throws Exception {
    final String text = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccc";
    final ByteBuf data = Unpooled.copiedBuffer(text.getBytes());
    bootstrapEnv(data.readableBytes());
    try {
        final Http2Headers headers = new DefaultHttp2Headers().method(POST).path(PATH).set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.GZIP);
        runInChannel(clientChannel, new Http2Runnable() {

            @Override
            public void run() throws Http2Exception {
                clientEncoder.writeHeaders(ctxClient(), 3, headers, 0, false, newPromiseClient());
                clientEncoder.writeData(ctxClient(), 3, data.retain(), 0, true, newPromiseClient());
                clientHandler.flush(ctxClient());
            }
        });
        awaitServer();
        assertEquals(text, serverOut.toString(CharsetUtil.UTF_8.name()));
    } finally {
        data.release();
    }
}
Also used : Http2Runnable(io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable) AsciiString(io.netty.util.AsciiString) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Aggregations

Http2Runnable (io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable)41 Test (org.junit.jupiter.api.Test)37 ByteBuf (io.netty.buffer.ByteBuf)28 AsciiString (io.netty.util.AsciiString)20 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)18 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)12 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)11 FullHttpMessage (io.netty.handler.codec.http.FullHttpMessage)11 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 ChannelFuture (io.netty.channel.ChannelFuture)6 ChannelFutureListener (io.netty.channel.ChannelFutureListener)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 ExecutionException (java.util.concurrent.ExecutionException)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 IllegalReferenceCountException (io.netty.util.IllegalReferenceCountException)3 ChannelHandlerAdapter (io.netty.channel.ChannelHandlerAdapter)2 ChannelPromise (io.netty.channel.ChannelPromise)2