Search in sources :

Example 6 with TracingState

use of com.nike.wingtips.util.TracingState in project riposte by Nike-Inc.

the class NonblockingEndpointExecutionHandlerTest method beforeMethod.

@Before
public void beforeMethod() {
    stateMock = mock(HttpProcessingState.class);
    proxyRouterStateMock = mock(ProxyRouterProcessingState.class);
    ctxMock = mock(ChannelHandlerContext.class);
    channelMock = mock(Channel.class);
    stateAttrMock = mock(Attribute.class);
    proxyRouterStateAttrMock = mock(Attribute.class);
    requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
    endpointMock = mock(StandardEndpoint.class);
    longRunningTaskExecutorMock = mock(Executor.class);
    responseFuture = new CompletableFuture<>();
    stateWorkChainFutureSpy = spy(CompletableFuture.completedFuture(null));
    eventLoopMock = mock(EventLoop.class);
    eventExecutorMock = mock(EventExecutor.class);
    distributedTracingConfigMock = mock(DistributedTracingConfig.class);
    taggingStrategySpy = spy(DefaultRiposteServerSpanNamingAndTaggingStrategy.getDefaultInstance());
    doReturn(taggingStrategySpy).when(distributedTracingConfigMock).getServerSpanNamingAndTaggingStrategy();
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(stateMock).when(stateAttrMock).get();
    doReturn(false).when(stateMock).isRequestHandled();
    doReturn(proxyRouterStateAttrMock).when(channelMock).attr(ChannelAttributes.PROXY_ROUTER_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(proxyRouterStateMock).when(proxyRouterStateAttrMock).get();
    doReturn(endpointMock).when(stateMock).getEndpointForExecution();
    doReturn(requestInfo).when(stateMock).getRequestInfo();
    doReturn(responseFuture).when(endpointMock).execute(any(RequestInfo.class), any(Executor.class), any(ChannelHandlerContext.class));
    doReturn(eventLoopMock).when(channelMock).eventLoop();
    doReturn(eventExecutorMock).when(ctxMock).executor();
    doReturn(true).when(eventExecutorMock).inEventLoop();
    doReturn(true).when(channelMock).isActive();
    doAnswer(invocation -> {
        CompletableFuture actualFutureForAttaching = (CompletableFuture) invocation.callRealMethod();
        futureThatWillBeAttachedToSpy = spy(actualFutureForAttaching);
        return futureThatWillBeAttachedToSpy;
    }).when(stateWorkChainFutureSpy).thenCompose(any(Function.class));
    doReturn(stateWorkChainFutureSpy).when(stateMock).getPreEndpointExecutionWorkChain();
    handlerSpy = spy(new NonblockingEndpointExecutionHandler(longRunningTaskExecutorMock, defaultCompletableFutureTimeoutMillis, distributedTracingConfigMock));
    resetTracingAndMdc();
    Tracer.getInstance().startRequestWithRootSpan("someRootSpan");
    TracingState tracingState = TracingState.getCurrentThreadTracingState();
    doReturn(tracingState.getLeft()).when(stateMock).getDistributedTraceStack();
    doReturn(tracingState.getRight()).when(stateMock).getLoggerMdcContextMap();
}
Also used : DistributedTracingConfig(com.nike.riposte.server.config.distributedtracing.DistributedTracingConfig) Attribute(io.netty.util.Attribute) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) Channel(io.netty.channel.Channel) ProxyRouterProcessingState(com.nike.riposte.server.http.ProxyRouterProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) RequestInfo(com.nike.riposte.server.http.RequestInfo) TracingState(com.nike.wingtips.util.TracingState) Function(java.util.function.Function) CompletableFuture(java.util.concurrent.CompletableFuture) EventExecutor(io.netty.util.concurrent.EventExecutor) Executor(java.util.concurrent.Executor) EventLoop(io.netty.channel.EventLoop) EventExecutor(io.netty.util.concurrent.EventExecutor) StandardEndpoint(com.nike.riposte.server.http.StandardEndpoint) Before(org.junit.Before)

Aggregations

TracingState (com.nike.wingtips.util.TracingState)6 Test (org.junit.Test)4 Span (com.nike.wingtips.Span)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)2 LastOutboundMessageSendFullResponseInfo (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)1 DistributedTracingConfig (com.nike.riposte.server.config.distributedtracing.DistributedTracingConfig)1 InvalidHttpRequestException (com.nike.riposte.server.error.exception.InvalidHttpRequestException)1 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)1 ProxyRouterProcessingState (com.nike.riposte.server.http.ProxyRouterProcessingState)1 RequestInfo (com.nike.riposte.server.http.RequestInfo)1 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)1 StandardEndpoint (com.nike.riposte.server.http.StandardEndpoint)1 Channel (io.netty.channel.Channel)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 EventLoop (io.netty.channel.EventLoop)1 Attribute (io.netty.util.Attribute)1 EventExecutor (io.netty.util.concurrent.EventExecutor)1 CompletableFuture (java.util.concurrent.CompletableFuture)1