use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class VerifyProxyRouterTracingBehaviorComponentTest method proxy_endpoint_tracing_behavior_should_work_as_desired_when_orig_request_does_not_have_tracing_headers.
@DataProvider(value = { "HEADERS_ON_SUBSPAN_ON", "HEADERS_OFF_SUBSPAN_ON", "HEADERS_ON_SUBSPAN_OFF", "HEADERS_OFF_SUBSPAN_OFF" })
@Test
public void proxy_endpoint_tracing_behavior_should_work_as_desired_when_orig_request_does_not_have_tracing_headers(TracingBehaviorScenario scenario) {
ExtractableResponse response = given().baseUri("http://127.0.0.1").port(proxyServerConfig.endpointsPort()).basePath(RouterEndpoint.MATCHING_PATH).header(SET_TRACING_HEADERS_HEADER_KEY, scenario.tracingHeadersOn).header(PERFORM_SUBSPAN_HEADER_KEY, scenario.subspanOn).log().all().when().get().then().log().headers().extract();
assertThat(response.statusCode()).isEqualTo(200);
assertThat(response.asString()).isEqualTo(DownstreamEndpoint.RESPONSE_PAYLOAD);
// Verify that the proxy honored the subspan option, and get a handle on the span that surrounded the proxy
// downstream call.
Span spanForDownstreamCall = verifyCompletedSpansAndReturnSpanForDownstreamCall(scenario.subspanOn);
if (scenario.tracingHeadersOn) {
// The downstream endpoint should have received tracing headers based on the span surrounding the proxy
// downstream call.
verifyExpectedTracingHeadersReceivedDownstream(response, spanForDownstreamCall);
} else {
// Proxy had the "set tracing headers" option off, and we didn't send any in our original request, so
// the downstream endpoint should not have received *any* tracing headers.
verifyExpectedTracingHeadersReceivedDownstream(response, null, null, null, null);
}
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class DefaultRiposteProxyRouterSpanNamingAndTaggingStrategyTest method doChangeSpanName_changes_span_name_as_expected.
@DataProvider(value = { "null | false", " | false", "[whitespace] | false", "fooNewName | true" }, splitBy = "\\|")
@Test
public void doChangeSpanName_changes_span_name_as_expected(String newName, boolean expectNameToBeChanged) {
// given
if ("[whitespace]".equals(newName)) {
newName = " \r\n\t ";
}
String initialSpanName = UUID.randomUUID().toString();
Span span = Span.newBuilder(initialSpanName, Span.SpanPurpose.CLIENT).build();
String expectedSpanName = (expectNameToBeChanged) ? newName : initialSpanName;
// when
impl.doChangeSpanName(span, newName);
// then
assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class DefaultRiposteProxyRouterSpanNamingAndTaggingStrategyTest method doHandleResponseTaggingAndFinalSpanName_delegates_to_wingtips_strategy_but_reverts_span_name_if_necessary.
@DataProvider(value = { "REVERT_SCENARIO_WITH_PREFIX", "REVERT_SCENARIO_NO_PREFIX", "REQUEST_IS_NULL", "SPAN_NAME_FROM_STRATEGY_MATCHES_ORIG_SPAN_NAME", "SPAN_NAME_FROM_STRATEGY_IS_NOT_BASIC_SPAN_NAME", "ORIG_SPAN_NAME_IS_BLANK" })
@Test
public void doHandleResponseTaggingAndFinalSpanName_delegates_to_wingtips_strategy_but_reverts_span_name_if_necessary(FinalSpanNameScenario scenario) {
// given
DefaultRiposteProxyRouterSpanNamingAndTaggingStrategy implSpy = spy(impl);
doAnswer(new Answer() {
int invocationCount = 0;
@Override
public Object answer(InvocationOnMock invocation) {
if (invocationCount == 0) {
invocationCount++;
return scenario.origSpanName;
}
return scenario.finalNameFromStrategy;
}
}).when(spanMock).getSpanName();
doReturn(scenario.httpMethod).when(requestMock).method();
HttpRequest requestToUse = (scenario.requestIsNull) ? null : requestMock;
// when
implSpy.doHandleResponseTaggingAndFinalSpanName(spanMock, requestToUse, responseMock, errorMock);
// then
// The strategy should always be called.
strategyResponseTaggingArgs.get().verifyArgs(spanMock, requestToUse, responseMock, errorMock, wingtipsAdapterMock);
// The span name may or may not have been reverted back to the original span name, though.
if (scenario.expectSpanNameReversion) {
verify(implSpy).doChangeSpanName(spanMock, scenario.origSpanName);
} else {
verify(implSpy, never()).doChangeSpanName(any(Span.class), anyString());
}
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class ChannelPipelineFinalizerHandlerTest method doChannelInactive_does_what_it_can_when_the_RequestInfo_or_ResponseInfo_is_null.
@DataProvider(value = { "true | false", "false | true", "true | true" }, splitBy = "\\|")
@Test
public void doChannelInactive_does_what_it_can_when_the_RequestInfo_or_ResponseInfo_is_null(boolean requestInfoIsNull, boolean responseInfoIsNull) throws Exception {
// given
Span span = setupTracingForChannelInactive(false);
if (requestInfoIsNull)
state.setRequestInfo(null);
if (responseInfoIsNull)
state.setResponseInfo(null, null);
// when
PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
// then
Assertions.assertThat(span.isCompleted()).isTrue();
Assertions.assertThat(state.isTraceCompletedOrScheduled()).isTrue();
if (requestInfoIsNull)
verifyNoInteractions(requestInfoMock);
else
verify(requestInfoMock).releaseAllResources();
verify(proxyRouterStateMock).cancelRequestStreaming(any(), any());
verify(proxyRouterStateMock).cancelDownstreamRequest(any());
Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class ChannelPipelineFinalizerHandlerTest method doChannelInactive_does_what_it_can_when_the_HttpProcessingState_or_ProxyRouterProcessingState_is_null.
@DataProvider(value = { "true | false", "false | true", "true | true" }, splitBy = "\\|")
@Test
public void doChannelInactive_does_what_it_can_when_the_HttpProcessingState_or_ProxyRouterProcessingState_is_null(boolean httpStateIsNull, boolean proxyRouterStateIsNull) throws Exception {
// given
if (httpStateIsNull)
doReturn(null).when(stateAttributeMock).get();
if (proxyRouterStateIsNull)
doReturn(null).when(proxyRouterProcessingStateAttributeMock).get();
Span span = setupTracingForChannelInactive(false);
// when
PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
// then
if (httpStateIsNull)
Assertions.assertThat(span.isCompleted()).isFalse();
else
Assertions.assertThat(span.isCompleted()).isTrue();
if (httpStateIsNull)
verifyNoInteractions(requestInfoMock);
else
verify(requestInfoMock).releaseAllResources();
if (proxyRouterStateIsNull)
verifyNoInteractions(proxyRouterStateMock);
else {
verify(proxyRouterStateMock).cancelRequestStreaming(any(), any());
verify(proxyRouterStateMock).cancelDownstreamRequest(any());
}
Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Aggregations