use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class ConsumerWithTracingAndMdcSupportTest 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();
ConsumerWithTracingAndMdcSupport instance = new ConsumerWithTracingAndMdcSupport(consumerMock, spanStack, mdcInfo);
resetTracingAndMdc();
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isEmpty();
// when
Throwable ex = catchThrowable(() -> instance.accept(inObj));
// then
verify(consumerMock).accept(inObj);
if (throwException) {
assertThat(ex).isNotNull();
} else {
assertThat(ex).isNull();
}
assertThat(currentSpanStackWhenConsumerWasCalled.get(0)).isEqualTo(spanStack);
assertThat(currentMdcInfoWhenConsumerWasCalled.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 kitchen_sink_constructor_fails_with_IllegalArgumentException_if_certain_args_are_null.
@DataProvider(value = { "true | false | false | signalFxReporterMetricMetadata cannot be null", "false | true | false | metricRegistry cannot be null", "false | false | true | requestTimerBuilder cannot be null" }, splitBy = "\\|")
@Test
public void kitchen_sink_constructor_fails_with_IllegalArgumentException_if_certain_args_are_null(boolean metadataIsNull, boolean registryIsNull, boolean timerBuilderIsNull, String expectedMessage) {
// given
MetricMetadata metricMetadata = (metadataIsNull) ? null : metricMetadataMock;
MetricRegistry registry = (registryIsNull) ? null : metricRegistryMock;
MetricBuilder<Timer> timerBuilder = (timerBuilderIsNull) ? null : requestTimerBuilderMock;
// when
Throwable ex = catchThrowable(() -> new SignalFxEndpointMetricsHandler(metricMetadata, registry, timerBuilder, null));
// then
assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage(expectedMessage);
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class StreamingAsyncHttpClientTest method StreamingChannel_doCloseChannelDueToUnrecoverableError_works_as_expected.
@DataProvider(value = { "true", "false" })
@Test
public void StreamingChannel_doCloseChannelDueToUnrecoverableError_works_as_expected(boolean callActive) {
// given
streamingChannelSpy.callActiveHolder.heldObject = callActive;
Throwable unrecoverableError = new RuntimeException("kaboom");
// when
streamingChannelSpy.doCloseChannelDueToUnrecoverableError(unrecoverableError);
// then
if (callActive) {
verify(channelIsBrokenAttrMock).set(true);
verifyChannelReleasedBackToPool(streamingChannelSpy.callActiveHolder, channelPoolMock, channelMock);
verify(channelMock).close();
} else {
verify(channelIsBrokenAttrMock, never()).set(anyBoolean());
verify(channelMock, never()).close();
}
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class StreamingAsyncHttpClientTest method StreamingChannel_closeChannelDueToUnrecoverableError_sets_field_to_true_but_otherwise_does_nothing_if_already_closed_or_call_inactive.
@DataProvider(value = { "true | true", "false | false", "true | false" }, splitBy = "\\|")
@Test
public void StreamingChannel_closeChannelDueToUnrecoverableError_sets_field_to_true_but_otherwise_does_nothing_if_already_closed_or_call_inactive(boolean alreadyClosed, boolean callActive) {
// given
Throwable unrecoverableError = new RuntimeException("kaboom");
streamingChannelSpy.channelClosedDueToUnrecoverableError = alreadyClosed;
streamingChannelSpy.callActiveHolder.heldObject = callActive;
// when
streamingChannelSpy.closeChannelDueToUnrecoverableError(unrecoverableError);
// then
assertThat(streamingChannelSpy.channelClosedDueToUnrecoverableError).isTrue();
verifyZeroInteractions(channelMock);
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class StreamingAsyncHttpClientTest method StreamingChannel_doStreamChunk_works_as_expected_when_last_chunk_already_sent_downstream_and_incoming_chunk_does_not_match_requirements.
@DataProvider(value = { "false | 0", "true | 42" }, splitBy = "\\|")
@Test
public void StreamingChannel_doStreamChunk_works_as_expected_when_last_chunk_already_sent_downstream_and_incoming_chunk_does_not_match_requirements(boolean chunkIsLastChunk, int readableBytes) {
// given
streamingChannelSpy.downstreamLastChunkSentHolder.heldObject = true;
streamingChannelSpy.callActiveHolder.heldObject = true;
streamingChannelSpy.channelClosedDueToUnrecoverableError = false;
HttpContent contentChunkMock = (chunkIsLastChunk) ? mock(LastHttpContent.class) : mock(HttpContent.class);
ByteBuf contentByteBufMock = mock(ByteBuf.class);
doReturn(contentByteBufMock).when(contentChunkMock).content();
doReturn(readableBytes).when(contentByteBufMock).readableBytes();
doReturn(writeAndFlushChannelFutureMock).when(channelMock).writeAndFlush(contentChunkMock);
// when
ChannelFuture result = streamingChannelSpy.doStreamChunk(contentChunkMock);
// then
verify(channelMock).writeAndFlush(contentChunkMock);
assertThat(result).isSameAs(writeAndFlushChannelFutureMock);
}
Aggregations