Java Code Examples for com.nike.internal.util.Pair#of()

The following examples show how to use com.nike.internal.util.Pair#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 6 votes vote down vote up
private Pair<Span, Map<String, String>> generateUpstreamSpanHeaders(boolean includeUserId) {
    Span.Builder spanBuilder = Span.newBuilder("upstreamSpan", Span.SpanPurpose.CLIENT);
    if (includeUserId) {
        spanBuilder.withUserId("user-" + UUID.randomUUID().toString());
    }

    Span span = spanBuilder.build();

    MapBuilder<String, String> headersBuilder = MapBuilder
        .builder(TraceHeaders.TRACE_ID, span.getTraceId())
        .put(TraceHeaders.SPAN_ID, span.getSpanId())
        .put(TraceHeaders.SPAN_NAME, span.getSpanName())
        .put(TraceHeaders.TRACE_SAMPLED, String.valueOf(span.isSampleable()));

    if (span.getUserId() != null) {
        headersBuilder.put(USER_ID_HEADER_KEY, span.getUserId());
    }

    return Pair.of(span, headersBuilder.build());
}
 
Example 2
Source File: AsyncCompletionHandlerWithTracingAndMdcSupportTest.java    From riposte with Apache License 2.0 6 votes vote down vote up
private Pair<ObjectHolder<Span>, ObjectHolder<Span>> setupBeforeAndAfterSpanCaptureForOnCompleted()
    throws Throwable {
    ObjectHolder<Span> before = new ObjectHolder<>();
    ObjectHolder<Span> after = new ObjectHolder<>();

    doAnswer(invocation -> {
        before.setObj(Tracer.getInstance().getCurrentSpan());
        return null;
    }).when(circuitBreakerManualTaskMock).handleEvent(responseMock);

    doAnswer(invocation -> {
        after.setObj(Tracer.getInstance().getCurrentSpan());
        return responseHandlerResult;
    }).when(responseHandlerFunctionMock).handleResponse(responseMock);

    return Pair.of(before, after);
}
 
Example 3
Source File: BiFunctionWithTracingAndMdcSupportTest.java    From riposte with Apache License 2.0 6 votes vote down vote up
@DataProvider(value = {
    "true   |   true",
    "true   |   false",
    "false  |   true",
    "false  |   false",
}, splitBy = "\\|")
@Test
public void pair_constructor_sets_fields_as_expected(boolean nullSpanStack, boolean nullMdcInfo) {
    // given
    Deque<Span> spanStackMock = (nullSpanStack) ? null : mock(Deque.class);
    Map<String, String> mdcInfoMock = (nullMdcInfo) ? null : mock(Map.class);

    // when
    BiFunctionWithTracingAndMdcSupport instance = new BiFunctionWithTracingAndMdcSupport(
        biFunctionMock, Pair.of(spanStackMock, mdcInfoMock)
    );

    // then
    assertThat(instance.origBiFunction).isSameAs(biFunctionMock);
    assertThat(instance.distributedTraceStackForExecution).isEqualTo(spanStackMock);
    assertThat(instance.mdcContextMapForExecution).isEqualTo(mdcInfoMock);
}
 
Example 4
Source File: AsyncNettyHelperTest.java    From riposte with Apache License 2.0 6 votes vote down vote up
@Test
public void linkTracingAndMdcToCurrentThread_pair_works_as_expected_with_non_null_pair_and_null_innards() {
    // given
    Pair<Deque<Span>, Map<String, String>> infoForLinking = Pair.of(null, null);
    resetTracingAndMdc();
    Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString());
    Pair<Deque<Span>, Map<String, String>> expectedPreCallInfo = Pair.of(
        Tracer.getInstance().getCurrentSpanStackCopy(),
        MDC.getCopyOfContextMap()
    );

    // when
    Pair<Deque<Span>, Map<String, String>> preCallInfo =
        AsyncNettyHelper.linkTracingAndMdcToCurrentThread(infoForLinking);
    Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of(
        Tracer.getInstance().getCurrentSpanStackCopy(),
        MDC.getCopyOfContextMap()
    );

    // then
    assertThat(preCallInfo).isEqualTo(expectedPreCallInfo);
    assertThat(postCallInfo).isEqualTo(Pair.of(null, Collections.emptyMap()));
}
 
Example 5
Source File: SignalFxEndpointMetricsHandlerTest.java    From riposte with Apache License 2.0 6 votes vote down vote up
@Test
public void three_arg_constructor_sets_fields_as_expected() {
    // given
    SignalFxReporter reporterMock = mock(SignalFxReporter.class);
    MetricMetadata expectedMetricMetadata = wireUpReporterForConstructor(reporterMock);

    Pair<Long, TimeUnit> reportingFrequency = Pair.of(42L, TimeUnit.DAYS);

    // when
    SignalFxEndpointMetricsHandler instance =
        new SignalFxEndpointMetricsHandler(reporterMock, reportingFrequency, metricRegistryMock);

    // then
    assertThat(instance.metricMetadata).isSameAs(expectedMetricMetadata);
    assertThat(instance.metricRegistry).isSameAs(metricRegistryMock);
    assertThat(instance.requestTimerBuilder).isInstanceOf(RollingWindowTimerBuilder.class);
    RollingWindowTimerBuilder rwtb = (RollingWindowTimerBuilder) instance.requestTimerBuilder;
    assertThat(rwtb.amount).isEqualTo(reportingFrequency.getLeft());
    assertThat(rwtb.timeUnit).isEqualTo(reportingFrequency.getRight());
    assertThat(instance.requestTimerDimensionConfigurator)
        .isSameAs(DEFAULT_REQUEST_LATENCY_TIMER_DIMENSION_CONFIGURATOR);
}
 
Example 6
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "true",
    "false"
})
@Test
public void verify_mono_endpoint_traced_correctly(boolean upstreamSendsSpan) {
    Pair<Span, Map<String, String>> upstreamSpanInfo = (upstreamSendsSpan)
                                                       ? generateUpstreamSpanHeaders()
                                                       : Pair.of((Span)null, Collections.emptyMap());

    ExtractableResponse response =
        given()
            .baseUri("http://localhost")
            .port(SERVER_PORT)
            .headers(upstreamSpanInfo.getRight())
            .queryParam("foo", "bar")
            .log().all()
        .when()
            .get(MONO_PATH)
        .then()
            .log().all()
            .extract();

    assertThat(response.statusCode()).isEqualTo(200);
    assertThat(response.asString()).isEqualTo(MONO_RESULT);
    Span completedSpan =
        verifySingleSpanCompletedAndReturnedInResponse(response, SLEEP_TIME_MILLIS, upstreamSpanInfo.getLeft());
    verifySpanNameAndTags(
        completedSpan,
        "GET " + MONO_PATH,
        "GET",
        MONO_PATH,
        "http://localhost:" + SERVER_PORT + MONO_PATH + "?foo=bar",
        MONO_PATH,
        response.statusCode(),
        null,
        "spring.webflux.server"
    );
}
 
Example 7
Source File: CallableWithTracingTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "true   |   true    |   true",
    "true   |   false   |   true",
    "false  |   true    |   true",
    "false  |   false   |   true",
    "true   |   true    |   false",
    "true   |   false   |   false",
    "false  |   true    |   false",
    "false  |   false   |   false",
}, splitBy = "\\|")
@Test
public void pair_constructor_sets_fields_as_expected(
    boolean nullSpanStack, boolean nullMdcInfo, boolean useStaticFactory
) {
    // given
    Deque<Span> spanStackMock = (nullSpanStack) ? null : mock(Deque.class);
    Map<String, String> mdcInfoMock = (nullMdcInfo) ? null : mock(Map.class);

    // when
    CallableWithTracing instance = (useStaticFactory)
                                   ? withTracing(callableMock, Pair.of(spanStackMock, mdcInfoMock))
                                   : new CallableWithTracing(callableMock, Pair.of(spanStackMock, mdcInfoMock)
    );

    // then
    assertThat(instance.origCallable).isSameAs(callableMock);
    assertThat(instance.spanStackForExecution).isEqualTo(spanStackMock);
    assertThat(instance.mdcContextMapForExecution).isEqualTo(mdcInfoMock);
}
 
Example 8
Source File: AsyncNettyHelperTest.java    From riposte with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "true",
    "false"
})
@Test
public void unlinkTracingAndMdcFromCurrentThread_pair_works_as_expected(boolean useNullPair) {
    // given
    Pair<Deque<Span>, Map<String, String>> infoForLinking = (useNullPair) ? null
                                                                           : setupStateWithTracingAndMdcInfo();
    // Setup the current thread with something that is not ultimately what we expect so that our assertions are
    //      verifying that the unlinkTracingAndMdcFromCurrentThread method actually did something.
    resetTracingAndMdc();
    Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString());

    // when
    AsyncNettyHelper.unlinkTracingAndMdcFromCurrentThread(infoForLinking);
    Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of(
        Tracer.getInstance().getCurrentSpanStackCopy(),
        MDC.getCopyOfContextMap()
    );

    // then
    if (useNullPair)
        assertThat(postCallInfo).isEqualTo(Pair.of(null, Collections.emptyMap()));
    else
        assertThat(postCallInfo).isEqualTo(infoForLinking);
}
 
Example 9
Source File: AsyncWingtipsHelperTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "true",
    "false"
})
@Test
public void unlinkTracingFromCurrentThread_pair_works_as_expected_with_non_null_pair_and_null_innards(
    boolean useStaticMethod
) {
    // given
    Pair<Deque<Span>, Map<String, String>> infoForLinking = Pair.of(null, null);
    // Setup the current thread with something that is not ultimately what we expect so that our assertions are
    //      verifying that the unlinkTracingFromCurrentThread method actually did something.
    resetTracing();
    Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString());

    // when
    if (useStaticMethod) {
        unlinkTracingFromCurrentThread(infoForLinking);
    }
    else {
        DEFAULT_IMPL.unlinkTracingFromCurrentThread(infoForLinking);
    }

    Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of(
        Tracer.getInstance().getCurrentSpanStackCopy(),
        MDC.getCopyOfContextMap()
    );

    // then
    assertThat(postCallInfo.getLeft()).isNull();
    assertThat(postCallInfo.getRight()).isNullOrEmpty();
}
 
Example 10
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
private Pair<Span, Map<String, String>> generateUpstreamSpanHeaders() {
    Span span = Span.newBuilder("upstreamSpan", Span.SpanPurpose.CLIENT).build();
    Map<String, String> headers = MapBuilder
        .builder(TraceHeaders.TRACE_ID, span.getTraceId())
        .put(TraceHeaders.SPAN_ID, span.getSpanId())
        .put(TraceHeaders.SPAN_NAME, span.getSpanName())
        .put(TraceHeaders.TRACE_SAMPLED, String.valueOf(span.isSampleable()))
        .build();

    return Pair.of(span, headers);
}
 
Example 11
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "true",
    "false"
})
@Test
public void verify_simple_endpoint_traced_correctly(boolean upstreamSendsSpan) {
    Pair<Span, Map<String, String>> upstreamSpanInfo = (upstreamSendsSpan)
                                                       ? generateUpstreamSpanHeaders()
                                                       : Pair.of((Span)null, Collections.<String, String>emptyMap());

    ExtractableResponse response =
        given()
            .baseUri("http://localhost")
            .port(SERVER_PORT)
            .headers(upstreamSpanInfo.getRight())
            .queryParam("foo", "bar")
            .log().all()
        .when()
            .get(SIMPLE_PATH)
        .then()
            .log().all()
            .extract();

    assertThat(response.statusCode()).isEqualTo(200);
    assertThat(response.asString()).isEqualTo(SIMPLE_RESULT);
    Span completedSpan =
        verifySingleSpanCompletedAndReturnedInResponse(response, 0, upstreamSpanInfo.getLeft());
    verifySpanNameAndTags(
        completedSpan,
        "GET " + SIMPLE_PATH,
        "GET",
        SIMPLE_PATH,
        "http://localhost:" + SERVER_PORT + SIMPLE_PATH + "?foo=bar",
        SIMPLE_PATH,
        response.statusCode(),
        null,
        "servlet"
    );
}
 
Example 12
Source File: ConsumerWithTracingTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "true   |   true    |   true",
    "true   |   false   |   true",
    "false  |   true    |   true",
    "false  |   false   |   true",
    "true   |   true    |   false",
    "true   |   false   |   false",
    "false  |   true    |   false",
    "false  |   false   |   false",
}, splitBy = "\\|")
@Test
public void pair_constructor_sets_fields_as_expected(
    boolean nullSpanStack, boolean nullMdcInfo, boolean useStaticFactory
) {
    // given
    Deque<Span> spanStackMock = (nullSpanStack) ? null : mock(Deque.class);
    Map<String, String> mdcInfoMock = (nullMdcInfo) ? null : mock(Map.class);

    // when
    ConsumerWithTracing instance = (useStaticFactory)
                                     ? withTracing(consumerMock, Pair.of(spanStackMock, mdcInfoMock))
                                     : new ConsumerWithTracing(consumerMock, Pair.of(spanStackMock, mdcInfoMock)
                                     );

    // then
    assertThat(instance.origConsumer).isSameAs(consumerMock);
    assertThat(instance.spanStackForExecution).isEqualTo(spanStackMock);
    assertThat(instance.mdcContextMapForExecution).isEqualTo(mdcInfoMock);
}
 
Example 13
Source File: AsyncWingtipsHelperTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
private Pair<Deque<Span>, Map<String, String>> generateTracingInfo() {
    resetTracing();
    Tracer.getInstance().startRequestWithRootSpan("someSpan");
    Pair<Deque<Span>, Map<String, String>> result = Pair.of(
        Tracer.getInstance().getCurrentSpanStackCopy(), new HashMap<>(MDC.getCopyOfContextMap())
    );
    resetTracing();
    return result;
}
 
Example 14
Source File: RequestTracingFilterComponentTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "true",
    "false"
})
@Test
public void verify_blocking_endpoint_traced_correctly(boolean upstreamSendsSpan) {
    Pair<Span, Map<String, String>> upstreamSpanInfo =
        (upstreamSendsSpan)
        ? generateUpstreamSpanHeaders()
        : Pair.of((Span) null, Collections.<String, String>emptyMap());

    ExtractableResponse response =
        given()
            .baseUri("http://localhost")
            .port(port)
            .headers(upstreamSpanInfo.getRight())
            .log().all()
        .when()
            .get(BLOCKING_PATH)
        .then()
            .log().all()
            .extract();

    assertThat(response.statusCode()).isEqualTo(200);
    assertThat(response.asString()).isEqualTo(BLOCKING_RESULT);
    Span completedSpan =
        verifySingleSpanCompletedAndReturnedInResponse(response, SLEEP_TIME_MILLIS, upstreamSpanInfo.getLeft());
    verifySpanNameAndTags(
        completedSpan,
        "GET",
        "GET",
        BLOCKING_PATH,
        "http://localhost:" + port + BLOCKING_PATH,
        null,
        response.statusCode(),
        null,
        "servlet"
    );
}
 
Example 15
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "true",
    "false"
})
@Test
public void verify_blocking_endpoint_traced_correctly(boolean upstreamSendsSpan) {
    Pair<Span, Map<String, String>> upstreamSpanInfo = (upstreamSendsSpan)
                                                       ? generateUpstreamSpanHeaders()
                                                       : Pair.of((Span)null, Collections.<String, String>emptyMap());

    ExtractableResponse response =
        given()
            .baseUri("http://localhost")
            .port(SERVER_PORT)
            .headers(upstreamSpanInfo.getRight())
            .queryParam("foo", "bar")
            .log().all()
        .when()
            .get(BLOCKING_PATH)
        .then()
            .log().all()
            .extract();

    assertThat(response.statusCode()).isEqualTo(200);
    assertThat(response.asString()).isEqualTo(BLOCKING_RESULT);
    Span completedSpan =
        verifySingleSpanCompletedAndReturnedInResponse(response, SLEEP_TIME_MILLIS, upstreamSpanInfo.getLeft());
    verifySpanNameAndTags(
        completedSpan,
        "GET " + BLOCKING_PATH,
        "GET",
        BLOCKING_PATH,
        "http://localhost:" + SERVER_PORT + BLOCKING_PATH + "?foo=bar",
        BLOCKING_PATH,
        response.statusCode(),
        null,
        "servlet"
    );
}
 
Example 16
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 4 votes vote down vote up
@DataProvider(value = {
    "true",
    "false"
})
@Test
public void verify_wildcard_endpoint_traced_correctly(boolean upstreamSendsSpan) {
    Pair<Span, Map<String, String>> upstreamSpanInfo = (upstreamSendsSpan)
                                                       ? generateUpstreamSpanHeaders()
                                                       : Pair.of((Span)null, Collections.emptyMap());

    String fullPathWithPathParam = WILDCARD_PATH_PREFIX + "/" + UUID.randomUUID().toString();
    String expectedPathTemplate = WILDCARD_PATH_PREFIX + "/**";

    ExtractableResponse response =
        given()
            .baseUri("http://localhost")
            .port(SERVER_PORT)
            .headers(upstreamSpanInfo.getRight())
            .queryParam("foo", "bar")
            .log().all()
        .when()
            .get(fullPathWithPathParam)
        .then()
            .log().all()
            .extract();

    assertThat(response.statusCode()).isEqualTo(200);
    assertThat(response.asString()).isEqualTo(WILDCARD_RESULT);
    Span completedSpan =
        verifySingleSpanCompletedAndReturnedInResponse(response, SLEEP_TIME_MILLIS, upstreamSpanInfo.getLeft());
    verifySpanNameAndTags(
        completedSpan,
        "GET " + expectedPathTemplate,
        "GET",
        fullPathWithPathParam,
        "http://localhost:" + SERVER_PORT + fullPathWithPathParam + "?foo=bar",
        expectedPathTemplate,
        response.statusCode(),
        null,
        "spring.webflux.server"
    );
}
 
Example 17
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 4 votes vote down vote up
@DataProvider(value = {
    "true",
    "false"
})
@Test
public void verify_wildcard_endpoint_traced_correctly(boolean upstreamSendsSpan) {
    Pair<Span, Map<String, String>> upstreamSpanInfo = (upstreamSendsSpan)
                                                       ? generateUpstreamSpanHeaders()
                                                       : Pair.of((Span)null, Collections.<String, String>emptyMap());

    String fullPathWithPathParam = WILDCARD_PATH_PREFIX + "/" + UUID.randomUUID().toString();
    String expectedPathTemplate = WILDCARD_PATH_PREFIX + "/**";

    ExtractableResponse response =
        given()
            .baseUri("http://localhost")
            .port(SERVER_PORT)
            .headers(upstreamSpanInfo.getRight())
            .queryParam("foo", "bar")
            .log().all()
        .when()
            .get(fullPathWithPathParam)
        .then()
            .log().all()
            .extract();

    assertThat(response.statusCode()).isEqualTo(200);
    assertThat(response.asString()).isEqualTo(WILDCARD_RESULT);
    Span completedSpan =
        verifySingleSpanCompletedAndReturnedInResponse(response, SLEEP_TIME_MILLIS, upstreamSpanInfo.getLeft());
    verifySpanNameAndTags(
        completedSpan,
        "GET " + expectedPathTemplate,
        "GET",
        fullPathWithPathParam,
        "http://localhost:" + SERVER_PORT + fullPathWithPathParam + "?foo=bar",
        expectedPathTemplate,
        response.statusCode(),
        null,
        "servlet"
    );
}
 
Example 18
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 4 votes vote down vote up
@DataProvider(value = {
    "true",
    "false"
})
@Test
public void verify_path_param_endpoint_traced_correctly(boolean upstreamSendsSpan) {
    Pair<Span, Map<String, String>> upstreamSpanInfo = (upstreamSendsSpan)
                                                       ? generateUpstreamSpanHeaders()
                                                       : Pair.of((Span)null, Collections.<String, String>emptyMap());

    String fullPathWithPathParam = PATH_PARAM_ENDPOINT_PATH_PREFIX + "/" + UUID.randomUUID().toString();
    String expectedPathTemplate = PATH_PARAM_ENDPOINT_PATH_PREFIX + "/{somePathParam}";

    ExtractableResponse response =
        given()
            .baseUri("http://localhost")
            .port(SERVER_PORT)
            .headers(upstreamSpanInfo.getRight())
            .queryParam("foo", "bar")
            .log().all()
        .when()
            .get(fullPathWithPathParam)
        .then()
            .log().all()
            .extract();

    assertThat(response.statusCode()).isEqualTo(200);
    assertThat(response.asString()).isEqualTo(PATH_PARAM_ENDPOINT_RESULT);
    Span completedSpan =
        verifySingleSpanCompletedAndReturnedInResponse(response, SLEEP_TIME_MILLIS, upstreamSpanInfo.getLeft());
    verifySpanNameAndTags(
        completedSpan,
        "GET " + expectedPathTemplate,
        "GET",
        fullPathWithPathParam,
        "http://localhost:" + SERVER_PORT + fullPathWithPathParam + "?foo=bar",
        expectedPathTemplate,
        response.statusCode(),
        null,
        "servlet"
    );
}
 
Example 19
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 4 votes vote down vote up
@DataProvider(value = {
    "true   |   true",
    "true   |   false",
    "false  |   true",
    "false  |   false"
}, splitBy = "\\|")
@Test
public void verify_span_info_endpoint_traced_correctly(boolean upstreamSendsSpan, boolean upstreamSendsUserId) {
    Pair<Span, Map<String, String>> upstreamSpanInfo = (upstreamSendsSpan)
                                                       ? generateUpstreamSpanHeaders(upstreamSendsUserId)
                                                       : Pair.of((Span)null, Collections.emptyMap());

    ExtractableResponse response =
        given()
            .baseUri("http://localhost")
            .port(SERVER_PORT)
            .headers(upstreamSpanInfo.getRight())
            .queryParam("foo", "bar")
            .log().all()
        .when()
            .get(SPAN_INFO_CALL_PATH)
        .then()
            .log().all()
            .extract();

    assertThat(response.statusCode()).isEqualTo(200);
    Span completedSpan =
        verifySingleSpanCompletedAndReturnedInResponse(response, SLEEP_TIME_MILLIS, upstreamSpanInfo.getLeft());
    verifySpanNameAndTags(
        completedSpan,
        "GET " + SPAN_INFO_CALL_PATH,
        "GET",
        SPAN_INFO_CALL_PATH,
        "http://localhost:" + SERVER_PORT + SPAN_INFO_CALL_PATH + "?foo=bar",
        SPAN_INFO_CALL_PATH,
        response.statusCode(),
        null,
        "spring.webflux.server"
    );
    EndpointSpanInfoDto resultDto = response.as(EndpointSpanInfoDto.class);
    if (upstreamSendsSpan) {
        verifySpanInfoEqual(resultDto.parent_span_info, spanInfoDtoFromSpan(upstreamSpanInfo.getLeft()));
        verifyParentChildRelationship(resultDto);
    }
    else {
        verifySpanInfoEqual(resultDto.parent_span_info, emptySpanInfoDto());
    }
}
 
Example 20
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 4 votes vote down vote up
@DataProvider(value = {
    "true",
    "false"
})
@Test
public void verify_path_param_endpoint_traced_correctly(boolean upstreamSendsSpan) {
    Pair<Span, Map<String, String>> upstreamSpanInfo = (upstreamSendsSpan)
                                                       ? generateUpstreamSpanHeaders()
                                                       : Pair.of((Span)null, Collections.<String, String>emptyMap());

    String fullPathWithPathParam = PATH_PARAM_ENDPOINT_PATH_PREFIX + "/" + UUID.randomUUID().toString();
    String expectedPathTemplate = PATH_PARAM_ENDPOINT_PATH_PREFIX + "/{somePathParam}";

    ExtractableResponse response =
        given()
            .baseUri("http://localhost")
            .port(SERVER_PORT)
            .headers(upstreamSpanInfo.getRight())
            .queryParam("foo", "bar")
            .log().all()
        .when()
            .get(fullPathWithPathParam)
        .then()
            .log().all()
            .extract();

    assertThat(response.statusCode()).isEqualTo(200);
    assertThat(response.asString()).isEqualTo(PATH_PARAM_ENDPOINT_RESULT);
    Span completedSpan =
        verifySingleSpanCompletedAndReturnedInResponse(response, SLEEP_TIME_MILLIS, upstreamSpanInfo.getLeft());
    verifySpanNameAndTags(
        completedSpan,
        "GET " + expectedPathTemplate,
        "GET",
        fullPathWithPathParam,
        "http://localhost:" + SERVER_PORT + fullPathWithPathParam + "?foo=bar",
        expectedPathTemplate,
        response.statusCode(),
        null,
        "servlet"
    );
}