Search in sources :

Example 1 with RequestBuilderWrapper

use of com.nike.riposte.client.asynchttp.ning.RequestBuilderWrapper in project riposte by Nike-Inc.

the class VerifyAsyncHttpClientHelperComponentTest method verify_basic_functionality.

@Test
public void verify_basic_functionality() throws Exception {
    // given
    RequestBuilderWrapper rbw = asyncClient.getRequestBuilder("http://localhost:" + serverPort + TestEndpoint.MATCHING_PATH, HttpMethod.GET);
    rbw.requestBuilder.setHeader(TestEndpoint.EXPECTED_HEADER_KEY, TestEndpoint.EXPECTED_HEADER_VAL);
    rbw.requestBuilder.setBody(TestEndpoint.EXPECTED_REQUEST_PAYLOAD);
    Span origSpan = Tracer.getInstance().startRequestWithRootSpan("overallReqSpan");
    Deque<Span> distributedTraceStackForCall = Tracer.getInstance().getCurrentSpanStackCopy();
    Map<String, String> mdcContextForCall = MDC.getCopyOfContextMap();
    resetTracingAndMdc();
    // when
    Response result = asyncClient.executeAsyncHttpRequest(rbw, response -> response, distributedTraceStackForCall, mdcContextForCall).join();
    // then
    assertThat(result.getStatusCode()).isEqualTo(200);
    assertThat(result.getResponseBody()).isEqualTo(TestEndpoint.RESPONSE_PAYLOAD);
    assertThat(result.getHeader(TraceHeaders.TRACE_ID)).isEqualTo(origSpan.getTraceId());
    // The async client should have surrounded the request in a subspan,
    //      so the parent ID sent to the downstream service should be the original span's span ID.
    assertThat(result.getHeader(TraceHeaders.PARENT_SPAN_ID)).isEqualTo(origSpan.getSpanId());
}
Also used : Response(com.ning.http.client.Response) Span(com.nike.wingtips.Span) RequestInfo(com.nike.riposte.server.http.RequestInfo) BeforeClass(org.junit.BeforeClass) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ResponseInfo(com.nike.riposte.server.http.ResponseInfo) TraceHeaders(com.nike.wingtips.TraceHeaders) Tracer(com.nike.wingtips.Tracer) CompletableFuture(java.util.concurrent.CompletableFuture) ServerConfig(com.nike.riposte.server.config.ServerConfig) Deque(java.util.Deque) ServerSocket(java.net.ServerSocket) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Collections.singleton(java.util.Collections.singleton) ApiError(com.nike.backstopper.apierror.ApiError) After(org.junit.After) Map(java.util.Map) Server(com.nike.riposte.server.Server) AsyncHttpClientHelper(com.nike.riposte.client.asynchttp.ning.AsyncHttpClientHelper) Response(com.ning.http.client.Response) Before(org.junit.Before) AfterClass(org.junit.AfterClass) ApiException(com.nike.backstopper.exception.ApiException) Executor(java.util.concurrent.Executor) Collection(java.util.Collection) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test) IOException(java.io.IOException) StandardEndpoint(com.nike.riposte.server.http.StandardEndpoint) UUID(java.util.UUID) ApiErrorBase(com.nike.backstopper.apierror.ApiErrorBase) Endpoint(com.nike.riposte.server.http.Endpoint) Matcher(com.nike.riposte.util.Matcher) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) MDC(org.slf4j.MDC) RequestBuilderWrapper(com.nike.riposte.client.asynchttp.ning.RequestBuilderWrapper) RequestBuilderWrapper(com.nike.riposte.client.asynchttp.ning.RequestBuilderWrapper) Span(com.nike.wingtips.Span) Test(org.junit.Test)

Aggregations

ApiError (com.nike.backstopper.apierror.ApiError)1 ApiErrorBase (com.nike.backstopper.apierror.ApiErrorBase)1 ApiException (com.nike.backstopper.exception.ApiException)1 AsyncHttpClientHelper (com.nike.riposte.client.asynchttp.ning.AsyncHttpClientHelper)1 RequestBuilderWrapper (com.nike.riposte.client.asynchttp.ning.RequestBuilderWrapper)1 Server (com.nike.riposte.server.Server)1 ServerConfig (com.nike.riposte.server.config.ServerConfig)1 Endpoint (com.nike.riposte.server.http.Endpoint)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 Matcher (com.nike.riposte.util.Matcher)1 Span (com.nike.wingtips.Span)1 TraceHeaders (com.nike.wingtips.TraceHeaders)1 Tracer (com.nike.wingtips.Tracer)1 Response (com.ning.http.client.Response)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)1 HttpMethod (io.netty.handler.codec.http.HttpMethod)1 IOException (java.io.IOException)1