use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class SignalFxEndpointMetricsHandlerTest method two_arg_constructor_fails_with_IllegalArgumentException_if_reporting_frequency_args_are_null.
@DataProvider(value = { "true | false", "false | true" }, splitBy = "\\|")
@Test
public void two_arg_constructor_fails_with_IllegalArgumentException_if_reporting_frequency_args_are_null(boolean amountIsNull, boolean timeUnitIsNull) {
// given
SignalFxReporterFactory reporterFactoryMock = mock(SignalFxReporterFactory.class);
wireUpReporterFactoryMockForConstructor(reporterFactoryMock, metricRegistryMock);
if (amountIsNull)
doReturn(null).when(reporterFactoryMock).getInterval();
if (timeUnitIsNull)
doReturn(null).when(reporterFactoryMock).getTimeUnit();
// when
Throwable ex = catchThrowable(() -> new SignalFxEndpointMetricsHandler(reporterFactoryMock, metricRegistryMock));
// then
if (amountIsNull) {
assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage("reportingFrequency amount cannot be null");
}
if (timeUnitIsNull) {
assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage("reportingFrequency TimeUnit cannot be null");
}
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class SignalFxEndpointMetricsHandlerTest method three_arg_constructor_fails_with_IllegalArgumentException_if_reporting_frequency_args_are_null.
@DataProvider(value = { "true | false", "false | true" }, splitBy = "\\|")
@Test
public void three_arg_constructor_fails_with_IllegalArgumentException_if_reporting_frequency_args_are_null(boolean amountIsNull, boolean timeUnitIsNull) {
// given
SignalFxReporter reporterMock = mock(SignalFxReporter.class);
wireUpReporterForConstructor(reporterMock);
Long amount = (amountIsNull) ? null : 42L;
TimeUnit timeUnit = (timeUnitIsNull) ? null : TimeUnit.DAYS;
// when
Throwable ex = catchThrowable(() -> new SignalFxEndpointMetricsHandler(reporterMock, Pair.of(amount, timeUnit), metricRegistryMock));
// then
if (amountIsNull) {
assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage("reportingFrequency amount cannot be null");
}
if (timeUnitIsNull) {
assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage("reportingFrequency TimeUnit cannot be null");
}
}
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 SignalFxEndpointMetricsHandlerTest method handleRequest_gracefully_handles_some_null_args.
@DataProvider(value = { "true | false | false", "false | true | false", "false | false | true", "true | true | true" }, splitBy = "\\|")
@Test
public void handleRequest_gracefully_handles_some_null_args(boolean endpointIsNull, boolean methodIsNull, boolean matchingPathTemplateIsNull) {
// given
int statusCode = 242;
int statusCodeXXValue = 2;
long elapsedTimeMillis = 42;
Endpoint endpoint = (endpointIsNull) ? null : endpointMock;
doReturn(endpoint).when(httpStateMock).getEndpointForExecution();
String expectedEndpointClass = (endpointIsNull) ? "NONE" : endpoint.getClass().getName();
HttpMethod method = (methodIsNull) ? null : httpMethod;
doReturn(method).when(requestInfoMock).getMethod();
String expectedMethodName = (methodIsNull) ? "NONE" : method.name();
String pathTemplate = (matchingPathTemplateIsNull) ? null : matchingPathTemplate;
doReturn(pathTemplate).when(httpStateMock).getMatchingPathTemplate();
String expectedPathTemplate = (matchingPathTemplateIsNull) ? "NONE" : pathTemplate;
// when
handler.handleRequest(requestInfoMock, responseInfoMock, httpStateMock, statusCode, statusCodeXXValue, elapsedTimeMillis);
// then
verify(metricMetadataMock).forBuilder(requestTimerBuilderMock);
verify(dimensionConfiguratorMock).setupMetricWithDimensions(timerBuilderTaggerMock, requestInfoMock, responseInfoMock, httpStateMock, statusCode, statusCodeXXValue, elapsedTimeMillis, endpoint, expectedEndpointClass, expectedMethodName, expectedPathTemplate);
verify(timerBuilderTaggerMock).createOrGet(metricRegistryMock);
verify(timerMock).update(elapsedTimeMillis, TimeUnit.MILLISECONDS);
}
Aggregations