Search in sources :

Example 6 with StreamException

use of io.netty.handler.codec.http2.Http2Exception.StreamException in project rest.li by linkedin.

the class TestHttp2NettyStreamClient method testMaxConcurrentStreamExhaustion.

/**
 * When the maximum number of concurrent streams is exhausted, the client is expected to throw
 * an {@link StreamException} immediately.
 */
@Test(timeOut = TEST_TIMEOUT)
public void testMaxConcurrentStreamExhaustion() throws Exception {
    final HttpServerBuilder serverBuilder = new HttpServerBuilder();
    final Server server = serverBuilder.maxConcurrentStreams(0).build();
    final HttpClientBuilder clientBuilder = new HttpClientBuilder(_eventLoop, _scheduler);
    final Http2NettyStreamClient client = clientBuilder.buildHttp2StreamClient();
    final FutureTransportCallback<StreamResponse> callback = new FutureTransportCallback<>();
    final TransportResponse<StreamResponse> response;
    try {
        server.start();
        // Sends the stream request
        final StreamRequestBuilder builder = new StreamRequestBuilder(new URI(URL));
        final StreamRequest request = builder.setMethod(METHOD).setHeader(HttpHeaderNames.HOST.toString(), HOST_NAME.toString()).build(EntityStreams.newEntityStream(new ByteStringWriter(ByteString.copy(new byte[REQUEST_SIZE]))));
        client.streamRequest(request, new RequestContext(), new HashMap<>(), callback);
        response = callback.get();
    } finally {
        server.stop();
    }
    Assert.assertNotNull(response);
    Assert.assertTrue(response.hasError());
    Assert.assertNotNull(response.getError());
    ExceptionTestUtil.verifyCauseChain(response.getError(), Http2Exception.StreamException.class);
}
Also used : Http2Exception(io.netty.handler.codec.http2.Http2Exception) Server(org.eclipse.jetty.server.Server) FutureTransportCallback(com.linkedin.r2.transport.common.bridge.common.FutureTransportCallback) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) HttpServerBuilder(com.linkedin.r2.testutils.server.HttpServerBuilder) HttpClientBuilder(com.linkedin.r2.transport.http.client.HttpClientBuilder) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) URI(java.net.URI) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) RequestContext(com.linkedin.r2.message.RequestContext) ByteStringWriter(com.linkedin.r2.message.stream.entitystream.ByteStringWriter) Test(org.testng.annotations.Test)

Example 7 with StreamException

use of io.netty.handler.codec.http2.Http2Exception.StreamException in project netty by netty.

the class Http2FrameCodecTest method streamErrorShouldFireUserEvent.

@Test
public void streamErrorShouldFireUserEvent() throws Exception {
    frameListener.onHeadersRead(http2HandlerCtx, 3, request, 31, false);
    Http2Stream stream = framingCodec.connectionHandler().connection().stream(3);
    assertNotNull(stream);
    Http2StreamActiveEvent activeEvent = inboundHandler.readInboundMessageOrUserEvent();
    assertNotNull(activeEvent);
    assertEquals(stream.id(), activeEvent.streamId());
    StreamException streamEx = new StreamException(3, Http2Error.INTERNAL_ERROR, "foo");
    framingCodec.connectionHandler().onError(http2HandlerCtx, streamEx);
    Http2HeadersFrame headersFrame = inboundHandler.readInboundMessageOrUserEvent();
    assertNotNull(headersFrame);
    try {
        inboundHandler.checkException();
        fail("stream exception expected");
    } catch (StreamException e) {
        assertEquals(streamEx, e);
    }
    Http2StreamClosedEvent closedEvent = inboundHandler.readInboundMessageOrUserEvent();
    assertNotNull(closedEvent);
    assertEquals(stream.id(), closedEvent.streamId());
    assertNull(inboundHandler.readInboundMessageOrUserEvent());
}
Also used : StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) Test(org.junit.Test)

Example 8 with StreamException

use of io.netty.handler.codec.http2.Http2Exception.StreamException in project netty by netty.

the class Http2MultiplexCodecTest method streamExceptionClosesChildChannel.

@Test(expected = StreamException.class)
public void streamExceptionClosesChildChannel() throws Exception {
    LastInboundHandler inboundHandler = streamActiveAndWriteHeaders(streamId);
    assertTrue(inboundHandler.isChannelActive());
    StreamException e = new StreamException(streamId, Http2Error.PROTOCOL_ERROR, "baaam!");
    parentChannel.pipeline().fireExceptionCaught(e);
    parentChannel.runPendingTasks();
    assertFalse(inboundHandler.isChannelActive());
    inboundHandler.checkException();
}
Also used : StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) Test(org.junit.Test)

Example 9 with StreamException

use of io.netty.handler.codec.http2.Http2Exception.StreamException in project netty by netty.

the class Http2ConnectionHandler method onError.

/**
 * Central handler for all exceptions caught during HTTP/2 processing.
 */
@Override
public void onError(ChannelHandlerContext ctx, boolean outbound, Throwable cause) {
    Http2Exception embedded = getEmbeddedHttp2Exception(cause);
    if (isStreamError(embedded)) {
        onStreamError(ctx, outbound, cause, (StreamException) embedded);
    } else if (embedded instanceof CompositeStreamException) {
        CompositeStreamException compositException = (CompositeStreamException) embedded;
        for (StreamException streamException : compositException) {
            onStreamError(ctx, outbound, cause, streamException);
        }
    } else {
        onConnectionError(ctx, outbound, cause, embedded);
    }
    ctx.flush();
}
Also used : Http2CodecUtil.getEmbeddedHttp2Exception(io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception) CompositeStreamException(io.netty.handler.codec.http2.Http2Exception.CompositeStreamException) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) CompositeStreamException(io.netty.handler.codec.http2.Http2Exception.CompositeStreamException)

Example 10 with StreamException

use of io.netty.handler.codec.http2.Http2Exception.StreamException in project netty by netty.

the class Http2MultiplexTest method streamExceptionTriggersChildChannelExceptionAndClose.

@Test
public void streamExceptionTriggersChildChannelExceptionAndClose() throws Exception {
    final LastInboundHandler inboundHandler = new LastInboundHandler();
    Http2StreamChannel channel = newInboundStream(3, false, inboundHandler);
    assertTrue(channel.isActive());
    StreamException cause = new StreamException(channel.stream().id(), Http2Error.PROTOCOL_ERROR, "baaam!");
    parentChannel.pipeline().fireExceptionCaught(cause);
    assertFalse(channel.isActive());
    assertThrows(StreamException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            inboundHandler.checkException();
        }
    });
}
Also used : Executable(org.junit.jupiter.api.function.Executable) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) Test(org.junit.jupiter.api.Test)

Aggregations

StreamException (io.netty.handler.codec.http2.Http2Exception.StreamException)9 Test (org.junit.jupiter.api.Test)4 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)3 Executable (org.junit.jupiter.api.function.Executable)3 Http2Exception (io.netty.handler.codec.http2.Http2Exception)2 CompositeStreamException (io.netty.handler.codec.http2.Http2Exception.CompositeStreamException)2 Test (org.junit.Test)2 RequestContext (com.linkedin.r2.message.RequestContext)1 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)1 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)1 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)1 ByteStringWriter (com.linkedin.r2.message.stream.entitystream.ByteStringWriter)1 HttpServerBuilder (com.linkedin.r2.testutils.server.HttpServerBuilder)1 FutureTransportCallback (com.linkedin.r2.transport.common.bridge.common.FutureTransportCallback)1 HttpClientBuilder (com.linkedin.r2.transport.http.client.HttpClientBuilder)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelPromise (io.netty.channel.ChannelPromise)1 DecoderException (io.netty.handler.codec.DecoderException)1 UnsupportedMessageTypeException (io.netty.handler.codec.UnsupportedMessageTypeException)1 DefaultHttp2ResetFrame (io.netty.handler.codec.http2.DefaultHttp2ResetFrame)1