use of com.nike.riposte.server.config.distributedtracing.ServerSpanNamingAndTaggingStrategy in project riposte by Nike-Inc.
the class HttpChannelInitializerTest method initChannel_adds_NonblockingEndpointExecutionHandler_after_RoutingHandler_and_RequestContentDeserializerHandler_and_RequestContentValidationHandler_and_uses_longRunningTaskExecutor_and_defaultCompletableFutureTimeoutMillis.
@Test
public void initChannel_adds_NonblockingEndpointExecutionHandler_after_RoutingHandler_and_RequestContentDeserializerHandler_and_RequestContentValidationHandler_and_uses_longRunningTaskExecutor_and_defaultCompletableFutureTimeoutMillis() {
// given
HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();
Whitebox.setInternalState(hci, "validationService", mock(RequestValidator.class));
Executor expectedLongRunningTaskExecutor = extractField(hci, "longRunningTaskExecutor");
long expectedDefaultCompletableFutureTimeoutMillis = extractField(hci, "defaultCompletableFutureTimeoutMillis");
DistributedTracingConfig<Span> distributedTracingConfigMock = mock(DistributedTracingConfig.class);
ServerSpanNamingAndTaggingStrategy<Span> expectedServerSpanNamingAndTaggingStrategy = mock(ServerSpanNamingAndTaggingStrategy.class);
Whitebox.setInternalState(hci, "distributedTracingConfig", distributedTracingConfigMock);
doReturn(expectedServerSpanNamingAndTaggingStrategy).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, RoutingHandler> routingHandler = findChannelHandler(handlers, RoutingHandler.class);
Pair<Integer, RequestContentDeserializerHandler> requestContentDeserializerHandler = findChannelHandler(handlers, RequestContentDeserializerHandler.class);
Pair<Integer, RequestContentValidationHandler> requestContentValidationHandler = findChannelHandler(handlers, RequestContentValidationHandler.class);
Pair<Integer, NonblockingEndpointExecutionHandler> nonblockingEndpointExecutionHandler = findChannelHandler(handlers, NonblockingEndpointExecutionHandler.class);
assertThat(routingHandler, notNullValue());
assertThat(requestContentDeserializerHandler, notNullValue());
assertThat(requestContentValidationHandler, notNullValue());
assertThat(nonblockingEndpointExecutionHandler, notNullValue());
assertThat(nonblockingEndpointExecutionHandler.getLeft(), is(greaterThan(routingHandler.getLeft())));
assertThat(nonblockingEndpointExecutionHandler.getLeft(), is(greaterThan(requestContentDeserializerHandler.getLeft())));
assertThat(nonblockingEndpointExecutionHandler.getLeft(), is(greaterThan(requestContentValidationHandler.getLeft())));
// and then
Executor actualLongRunningTaskExecutor = (Executor) Whitebox.getInternalState(nonblockingEndpointExecutionHandler.getRight(), "longRunningTaskExecutor");
long actualDefaultCompletableFutureTimeoutMillis = (long) Whitebox.getInternalState(nonblockingEndpointExecutionHandler.getRight(), "defaultCompletableFutureTimeoutMillis");
ServerSpanNamingAndTaggingStrategy<Span> actualTaggingStrategy = (ServerSpanNamingAndTaggingStrategy<Span>) Whitebox.getInternalState(nonblockingEndpointExecutionHandler.getRight(), "spanTaggingStrategy");
assertThat(actualLongRunningTaskExecutor, is(expectedLongRunningTaskExecutor));
assertThat(actualDefaultCompletableFutureTimeoutMillis, is(expectedDefaultCompletableFutureTimeoutMillis));
assertThat(actualTaggingStrategy, is(expectedServerSpanNamingAndTaggingStrategy));
}
Aggregations