use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class SignalFxAwareCodahaleMetricsCollectorTest method getNamedTimer_with_iterable_dimensions_creates_dimensioned_timer_using_sfx_mechanisms.
@DataProvider(value = { "null", "0", "1", "2" }, splitBy = "\\|")
@Test
public void getNamedTimer_with_iterable_dimensions_creates_dimensioned_timer_using_sfx_mechanisms(Integer numDimensions) {
// given
String timerName = UUID.randomUUID().toString();
List<Pair<String, String>> iterableDims = generateIterableDimensions(numDimensions);
// when
Timer result = sfxImpl.getNamedTimer(timerName, iterableDims);
// then
verifyMetricCreation(timerBuilderMock, timerTaggerMock, timerName, iterableDims, timerMock, result);
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class ChannelFutureListenerWithTracingAndMdcTest method apply_handles_tracing_and_mdc_info_as_expected.
@DataProvider(value = { "true", "false" })
@Test
public void apply_handles_tracing_and_mdc_info_as_expected(boolean throwException) {
// given
throwExceptionDuringCall = throwException;
Tracer.getInstance().startRequestWithRootSpan("foo");
Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy();
Map<String, String> mdcInfo = MDC.getCopyOfContextMap();
ChannelFutureListenerWithTracingAndMdc instance = new ChannelFutureListenerWithTracingAndMdc(consumerMock, spanStack, mdcInfo);
resetTracingAndMdc();
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isEmpty();
// when
Throwable ex = catchThrowable(() -> instance.operationComplete(inObj));
// then
verify(consumerMock).accept(inObj);
if (throwException) {
assertThat(ex).isNotNull();
} else {
assertThat(ex).isNull();
}
assertThat(currentSpanStackWhenChannelFutureWasCalled.get(0)).isEqualTo(spanStack);
assertThat(currentMdcInfoWhenChannelFutureWasCalled.get(0)).isEqualTo(mdcInfo);
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isEmpty();
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class FunctionWithTracingAndMdcSupportTest method apply_handles_tracing_and_mdc_info_as_expected.
@DataProvider(value = { "true", "false" })
@Test
public void apply_handles_tracing_and_mdc_info_as_expected(boolean throwException) {
// given
throwExceptionDuringCall = throwException;
Tracer.getInstance().startRequestWithRootSpan("foo");
Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy();
Map<String, String> mdcInfo = MDC.getCopyOfContextMap();
FunctionWithTracingAndMdcSupport instance = new FunctionWithTracingAndMdcSupport(functionMock, spanStack, mdcInfo);
resetTracingAndMdc();
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isEmpty();
// when
Throwable ex = null;
Object result = null;
try {
result = instance.apply(inObj);
} catch (Throwable t) {
ex = t;
}
// then
verify(functionMock).apply(inObj);
if (throwException) {
assertThat(ex).isNotNull();
assertThat(result).isNull();
} else {
assertThat(ex).isNull();
assertThat(result).isSameAs(outObj);
}
assertThat(currentSpanStackWhenFunctionWasCalled.get(0)).isEqualTo(spanStack);
assertThat(currentMdcInfoWhenFunctionWasCalled.get(0)).isEqualTo(mdcInfo);
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isEmpty();
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class CallableWithTracingAndMdcSupportTest method call_handles_tracing_and_mdc_info_as_expected.
@DataProvider(value = { "true", "false" })
@Test
public void call_handles_tracing_and_mdc_info_as_expected(boolean throwException) throws Exception {
// given
throwExceptionDuringCall = throwException;
Tracer.getInstance().startRequestWithRootSpan("foo");
Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy();
Map<String, String> mdcInfo = MDC.getCopyOfContextMap();
CallableWithTracingAndMdcSupport instance = new CallableWithTracingAndMdcSupport(callableMock, spanStack, mdcInfo);
resetTracingAndMdc();
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isEmpty();
// when
Throwable ex = catchThrowable(() -> instance.call());
// then
verify(callableMock).call();
if (throwException)
assertThat(ex).isNotNull();
else
assertThat(ex).isNull();
assertThat(currentSpanStackWhenCallableWasCalled.get(0)).isEqualTo(spanStack);
assertThat(currentMdcInfoWhenCallableWasCalled.get(0)).isEqualTo(mdcInfo);
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isEmpty();
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class AllowAllTheThingsCORSFilterTest method filterRequestFirstChunkWithOptionalShortCircuitResponse_short_circuits_on_CORS_preflight_OPTIONS_request.
@DataProvider(value = { "OPTIONS | true", "GET | false", "POST | false", "PUT | false" }, splitBy = "\\|")
@Test
public void filterRequestFirstChunkWithOptionalShortCircuitResponse_short_circuits_on_CORS_preflight_OPTIONS_request(String httpMethodString, boolean expectShortCircuit) {
// given
HttpMethod method = HttpMethod.valueOf(httpMethodString);
doReturn(method).when(requestMock).getMethod();
// when
Pair<RequestInfo<?>, Optional<ResponseInfo<?>>> result = filter.filterRequestFirstChunkWithOptionalShortCircuitResponse(requestMock, ctxMock);
// then
if (expectShortCircuit) {
assertThat(result).isNotNull();
assertThat(result.getLeft()).isSameAs(requestMock);
assertThat(result.getRight()).isPresent();
assertThat(result.getRight().get().getHttpStatusCode()).isEqualTo(200);
} else
assertThat(result).isNull();
}
Aggregations