use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class ChannelPipelineFinalizerHandlerTest method doChannelInactive_completes_releases_resources_and_completes_tracing_if_necessary.
@DataProvider(value = { "true | true", "false | true", "true | false", "false | false" }, splitBy = "\\|")
@Test
public void doChannelInactive_completes_releases_resources_and_completes_tracing_if_necessary(boolean tracingAlreadyDone, boolean responseSendingCompleted) throws Exception {
// given
Span span = setupTracingForChannelInactive(tracingAlreadyDone);
doReturn(responseSendingCompleted).when(responseInfoMock).isResponseSendingLastChunkSent();
if (responseSendingCompleted) {
state.setResponseWriterFinalChunkChannelFuture(mock(ChannelFuture.class));
}
// when
PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
// then
Assertions.assertThat(span.isCompleted()).isEqualTo(!tracingAlreadyDone);
Assertions.assertThat(state.isTraceCompletedOrScheduled()).isTrue();
verify(requestInfoMock).releaseAllResources();
verify(proxyRouterStateMock).setStreamingFailed();
verify(proxyRouterStateMock).triggerStreamingChannelErrorForChunks(any(Throwable.class));
Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class OpenChannelLimitHandlerTest method doChannelActive_marks_and_schedules_double_check_timeout_if_too_many_open_channels.
@DataProvider(value = { "0", "1" })
@Test
public void doChannelActive_marks_and_schedules_double_check_timeout_if_too_many_open_channels(int numOpenChannelsGreaterThanMax) throws Exception {
// given
int actualOpenChannels = maxOpenChannelsThreshold + numOpenChannelsGreaterThanMax;
setActualOpenChannels(actualOpenChannels);
// when
PipelineContinuationBehavior result = handler.doChannelActive(ctxMock);
// then
assertThat(result).isEqualTo(CONTINUE);
Pair<Runnable, GenericFutureListener> futureInfoPair = extractDoubleCheckRunnableAndCloseFutureListener();
verify(tooManyOpenConnectionsAttributeMock).set(actualOpenChannels);
verifyDoubleCheckFuture(futureInfoPair.getLeft());
verifyCloseFutureListener(futureInfoPair.getRight());
verify(channelGroupMock, never()).add(channelMock);
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverterTest method dataProviderTracerTags.
@DataProvider
public static Object[][] dataProviderTracerTags() {
Tracer tracer = new Tracer.Builder("x", null, null).build();
Map<String, String> rootTags = new HashMap<>();
rootTags.put("tracer.jaeger.version", tracer.getVersion());
rootTags.put("tracer.hostname", ANY);
rootTags.put("tracer.tag.str", "y");
rootTags.put("tracer.tag.bool", "true");
rootTags.put("tracer.tag.num", "1");
rootTags.put("sampler.type", "const");
rootTags.put("sampler.param", "true");
Map<String, String> childTags = new HashMap<>();
childTags.put("tracer.jaeger.version", UNDEF);
childTags.put("tracer.hostname", UNDEF);
childTags.put("tracer.tag.str", UNDEF);
childTags.put("tracer.tag.bool", UNDEF);
childTags.put("tracer.tag.num", UNDEF);
childTags.put("sampler.type", UNDEF);
childTags.put("sampler.param", UNDEF);
Map<String, String> rpcTags = new HashMap<>();
rpcTags.put("tracer.jaeger.version", tracer.getVersion());
rpcTags.put("tracer.hostname", ANY);
rpcTags.put("tracer.tag.str", "y");
rpcTags.put("tracer.tag.bool", "true");
rpcTags.put("tracer.tag.num", "1");
rpcTags.put("sampler.type", UNDEF);
rpcTags.put("sampler.param", UNDEF);
return new Object[][] { { SpanType.ROOT, rootTags }, { SpanType.CHILD, childTags }, { SpanType.RPC_SERVER, rpcTags } };
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class OpenChannelLimitHandlerTest method doChannelRead_throws_TooManyOpenChannelsException_or_not_depending_on_the_number_of_open_channels.
@DataProvider(value = { "null | false", "-1 | false", "0 | true", "1 | true" }, splitBy = "\\|")
@Test
public void doChannelRead_throws_TooManyOpenChannelsException_or_not_depending_on_the_number_of_open_channels(Integer numOpenChannelsDiffFromMaxThreshold, boolean expectTooManyOpenChannelsException) {
// given
Integer numOpenChannels = (numOpenChannelsDiffFromMaxThreshold == null) ? null : maxOpenChannelsThreshold + numOpenChannelsDiffFromMaxThreshold;
doReturn(numOpenChannels).when(tooManyOpenConnectionsAttributeMock).get();
// when
Throwable ex = null;
PipelineContinuationBehavior result = null;
try {
result = handler.doChannelRead(ctxMock, msg);
} catch (Throwable t) {
ex = t;
}
// then
if (expectTooManyOpenChannelsException) {
assertThat(ex).isInstanceOf(TooManyOpenChannelsException.class);
} else {
assertThat(ex).isNull();
assertThat(result).isEqualTo(CONTINUE);
}
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class RequestFilterHandlerTest method handleFilterLogic_executes_all_filters_and_uses_requestInfo_returned_by_short_circuiting_filters_when_they_do_not_short_circuit.
@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void handleFilterLogic_executes_all_filters_and_uses_requestInfo_returned_by_short_circuiting_filters_when_they_do_not_short_circuit(boolean isFirstChunk) {
// given
HandleFilterLogicMethodCallArgs args = new HandleFilterLogicMethodCallArgs(isFirstChunk);
filtersList.forEach(filter -> doReturn(true).when(filter).isShortCircuitRequestFilter());
RequestInfo<?> firstFilterResult = mock(RequestInfo.class);
RequestInfo<?> secondFilterResult = mock(RequestInfo.class);
// Do a mix of empty Optional vs null for the response to hit branch coverage (both indicate no short circuiting response)
doReturn(Pair.of(firstFilterResult, Optional.empty())).when(filter1Mock).filterRequestFirstChunkWithOptionalShortCircuitResponse(any(), any());
doReturn(Pair.of(firstFilterResult, null)).when(filter1Mock).filterRequestLastChunkWithOptionalShortCircuitResponse(any(), any());
doReturn(Pair.of(secondFilterResult, null)).when(filter2Mock).filterRequestFirstChunkWithOptionalShortCircuitResponse(any(), any());
doReturn(Pair.of(secondFilterResult, Optional.empty())).when(filter2Mock).filterRequestLastChunkWithOptionalShortCircuitResponse(any(), any());
// when
PipelineContinuationBehavior result = handlerSpy.handleFilterLogic(ctxMock, args.msg, args.normalFilterCall, args.shortCircuitFilterCall);
// then
assertThat(result).isEqualTo(CONTINUE);
// First filter should have been passed the original request.
if (isFirstChunk)
verify(filter1Mock).filterRequestFirstChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
else
verify(filter1Mock).filterRequestLastChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
// Second filter should have been passed the result of the first filter.
if (isFirstChunk)
verify(filter2Mock).filterRequestFirstChunkWithOptionalShortCircuitResponse(firstFilterResult, ctxMock);
else
verify(filter2Mock).filterRequestLastChunkWithOptionalShortCircuitResponse(firstFilterResult, ctxMock);
// The state should have been updated with the result of the second filter.
assertThat(state.getRequestInfo()).isSameAs(secondFilterResult);
}
Aggregations