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