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);
}
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());
}
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();
}
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();
}
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();
}
});
}
Aggregations