Search in sources :

Example 1 with ServerSpanNamingAndTaggingStrategy

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));
}
Also used : RequestContentValidationHandler(com.nike.riposte.server.handler.RequestContentValidationHandler) RequestContentDeserializerHandler(com.nike.riposte.server.handler.RequestContentDeserializerHandler) ServerSpanNamingAndTaggingStrategy(com.nike.riposte.server.config.distributedtracing.ServerSpanNamingAndTaggingStrategy) ChannelHandler(io.netty.channel.ChannelHandler) Span(com.nike.wingtips.Span) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Executor(java.util.concurrent.Executor) RequestValidator(com.nike.riposte.server.error.validation.RequestValidator) RoutingHandler(com.nike.riposte.server.handler.RoutingHandler) NonblockingEndpointExecutionHandler(com.nike.riposte.server.handler.NonblockingEndpointExecutionHandler) Test(org.junit.Test)

Aggregations

ServerSpanNamingAndTaggingStrategy (com.nike.riposte.server.config.distributedtracing.ServerSpanNamingAndTaggingStrategy)1 RequestValidator (com.nike.riposte.server.error.validation.RequestValidator)1 NonblockingEndpointExecutionHandler (com.nike.riposte.server.handler.NonblockingEndpointExecutionHandler)1 RequestContentDeserializerHandler (com.nike.riposte.server.handler.RequestContentDeserializerHandler)1 RequestContentValidationHandler (com.nike.riposte.server.handler.RequestContentValidationHandler)1 RoutingHandler (com.nike.riposte.server.handler.RoutingHandler)1 Span (com.nike.wingtips.Span)1 ChannelHandler (io.netty.channel.ChannelHandler)1 Executor (java.util.concurrent.Executor)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 Test (org.junit.Test)1