use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project riposte by Nike-Inc.
the class HttpChannelInitializerTest method initChannel_adds_ExceptionHandlingHandler_immediately_before_ResponseSenderHandler_and_after_NonblockingEndpointExecutionHandler_and_uses_riposteErrorHandler_and_riposteUnhandledErrorHandler.
@Test
public void initChannel_adds_ExceptionHandlingHandler_immediately_before_ResponseSenderHandler_and_after_NonblockingEndpointExecutionHandler_and_uses_riposteErrorHandler_and_riposteUnhandledErrorHandler() {
// given
HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();
RiposteErrorHandler expectedRiposteErrorHandler = extractField(hci, "riposteErrorHandler");
RiposteUnhandledErrorHandler expectedRiposteUnhandledErrorHandler = extractField(hci, "riposteUnhandledErrorHandler");
DistributedTracingConfig<Span> distributedTracingConfigMock = mock(DistributedTracingConfig.class);
ServerSpanNamingAndTaggingStrategy<Span> serverSpanNamingAndTaggingStrategyMock = mock(ServerSpanNamingAndTaggingStrategy.class);
Whitebox.setInternalState(hci, "distributedTracingConfig", distributedTracingConfigMock);
doReturn(serverSpanNamingAndTaggingStrategyMock).when(distributedTracingConfigMock).getServerSpanNamingAndTaggingStrategy();
// when
hci.initChannel(socketChannelMock);
// then
ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
Pair<Integer, ResponseSenderHandler> responseSenderHandler = findChannelHandler(handlers, ResponseSenderHandler.class);
Pair<Integer, NonblockingEndpointExecutionHandler> nonblockingEndpointExecutionHandler = findChannelHandler(handlers, NonblockingEndpointExecutionHandler.class);
Pair<Integer, ExceptionHandlingHandler> exceptionHandlingHandler = findChannelHandler(handlers, ExceptionHandlingHandler.class);
assertThat(responseSenderHandler, notNullValue());
assertThat(nonblockingEndpointExecutionHandler, notNullValue());
assertThat(exceptionHandlingHandler, notNullValue());
assertThat(exceptionHandlingHandler.getLeft(), is(responseSenderHandler.getLeft() - 1));
assertThat(exceptionHandlingHandler.getLeft(), is(greaterThan(nonblockingEndpointExecutionHandler.getLeft())));
assertThat(extractField(exceptionHandlingHandler.getRight(), "spanNamingAndTaggingStrategy"), is(serverSpanNamingAndTaggingStrategyMock));
// and then
RiposteErrorHandler actualRiposteErrorHandler = (RiposteErrorHandler) Whitebox.getInternalState(exceptionHandlingHandler.getRight(), "riposteErrorHandler");
RiposteUnhandledErrorHandler actualRiposteUnhandledErrorHandler = (RiposteUnhandledErrorHandler) Whitebox.getInternalState(exceptionHandlingHandler.getRight(), "riposteUnhandledErrorHandler");
assertThat(actualRiposteErrorHandler, is(expectedRiposteErrorHandler));
assertThat(actualRiposteUnhandledErrorHandler, is(expectedRiposteUnhandledErrorHandler));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project riposte by Nike-Inc.
the class HttpChannelInitializerTest method initChannel_adds_HttpServerCodec_with_config_values_coming_from_httpRequestDecoderConfig.
@Test
public void initChannel_adds_HttpServerCodec_with_config_values_coming_from_httpRequestDecoderConfig() {
// given
HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();
HttpRequestDecoderConfig configWithCustomValues = new HttpRequestDecoderConfig() {
@Override
public int maxInitialLineLength() {
return 123;
}
@Override
public int maxHeaderSize() {
return 456;
}
@Override
public int maxChunkSize() {
return 789;
}
};
Whitebox.setInternalState(hci, "httpRequestDecoderConfig", configWithCustomValues);
// when
hci.initChannel(socketChannelMock);
// then
ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
Pair<Integer, HttpServerCodec> httpServerCodecHandlerPair = findChannelHandler(handlers, HttpServerCodec.class);
Assertions.assertThat(httpServerCodecHandlerPair).isNotNull();
HttpServerCodec httpServerCodecHandler = httpServerCodecHandlerPair.getValue();
HttpRequestDecoder decoderHandler = (HttpRequestDecoder) Whitebox.getInternalState(httpServerCodecHandler, "inboundHandler");
int actualMaxInitialLineLength = extractField(extractField(decoderHandler, "lineParser"), "maxLength");
int actualMaxHeaderSize = extractField(extractField(decoderHandler, "headerParser"), "maxLength");
int actualMaxChunkSize = extractField(decoderHandler, "maxChunkSize");
Assertions.assertThat(actualMaxInitialLineLength).isEqualTo(configWithCustomValues.maxInitialLineLength());
Assertions.assertThat(actualMaxHeaderSize).isEqualTo(configWithCustomValues.maxHeaderSize());
Assertions.assertThat(actualMaxChunkSize).isEqualTo(configWithCustomValues.maxChunkSize());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project riposte by Nike-Inc.
the class HttpChannelInitializerTest method initChannel_adds_RequestContentDeserializerHandler_after_RequestInfoSetterHandler_and_RoutingHandler_and_uses_requestContentDeserializer.
@Test
public void initChannel_adds_RequestContentDeserializerHandler_after_RequestInfoSetterHandler_and_RoutingHandler_and_uses_requestContentDeserializer() {
// given
HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();
ObjectMapper expectedRequestContentDeserializer = mock(ObjectMapper.class);
Whitebox.setInternalState(hci, "requestContentDeserializer", expectedRequestContentDeserializer);
// when
hci.initChannel(socketChannelMock);
// then
ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
Pair<Integer, RequestInfoSetterHandler> requestInfoSetterHandler = findChannelHandler(handlers, RequestInfoSetterHandler.class);
Pair<Integer, RoutingHandler> routingHandler = findChannelHandler(handlers, RoutingHandler.class);
Pair<Integer, RequestContentDeserializerHandler> requestContentDeserializerHandler = findChannelHandler(handlers, RequestContentDeserializerHandler.class);
assertThat(requestInfoSetterHandler, notNullValue());
assertThat(routingHandler, notNullValue());
assertThat(requestContentDeserializerHandler, notNullValue());
assertThat(requestContentDeserializerHandler.getLeft(), is(greaterThan(requestInfoSetterHandler.getLeft())));
assertThat(requestContentDeserializerHandler.getLeft(), is(greaterThan(routingHandler.getLeft())));
// and then
ObjectMapper actualRequestContentDeserializer = (ObjectMapper) Whitebox.getInternalState(requestContentDeserializerHandler.getRight(), "defaultRequestContentDeserializer");
assertThat(actualRequestContentDeserializer, is(expectedRequestContentDeserializer));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project ambry by linkedin.
the class FrontendNettyChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
// If channel handler implementations are not annotated with @Sharable, Netty creates a new instance of every class
// in the pipeline for every connection.
// i.e. if there are a 1000 active connections there will be a 1000 NettyMessageProcessor instances.
ChannelPipeline pipeline = ch.pipeline();
// connection stats handler to track connection related metrics
pipeline.addLast("connectionStatsHandler", connectionStatsHandler);
// if SSL is enabled, add an SslHandler before the HTTP codec
if (sslFactory != null) {
InetSocketAddress peerAddress = ch.remoteAddress();
String peerHost = peerAddress.getHostName();
int peerPort = peerAddress.getPort();
SslHandler sslHandler = new SslHandler(sslFactory.createSSLEngine(peerHost, peerPort, SSLFactory.Mode.SERVER));
pipeline.addLast("sslHandler", sslHandler);
}
pipeline.addLast("codec", new HttpServerCodec(nettyConfig.nettyServerMaxInitialLineLength, nettyConfig.nettyServerMaxHeaderSize, nettyConfig.nettyServerMaxChunkSize)).addLast("healthCheckHandler", new HealthCheckHandler(restServerState, nettyMetrics)).addLast("publicAccessLogHandler", new PublicAccessLogHandler(publicAccessLogger, nettyMetrics)).addLast("idleStateHandler", new IdleStateHandler(0, 0, nettyConfig.nettyServerIdleTimeSeconds)).addLast("chunker", new ChunkedWriteHandler());
if (addedChannelHandlers != null) {
pipeline.addLast(addedChannelHandlers.toArray(new ChannelHandler[0]));
}
// custom processing class that interfaces with a RestRequestService.
pipeline.addLast("processor", new NettyMessageProcessor(nettyMetrics, nettyConfig, performanceConfig, requestHandler));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project java by wavefrontHQ.
the class HttpEndToEndTest method setup.
@Before
public void setup() throws Exception {
backendPort = findAvailablePort(8081);
ChannelHandler channelHandler = new WrappingHttpHandler(null, null, String.valueOf(backendPort), server);
thread = new Thread(new TcpIngester(createInitializer(channelHandler, backendPort, 32768, 16 * 1024 * 1024, 5, null, null), backendPort));
thread.start();
waitUntilListenerIsOnline(backendPort);
}
Aggregations