use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class RequestFilterHandlerTest method handleFilterLogic_executes_all_filters_and_uses_original_request_when_filters_are_not_short_circuiting_and_return_null.
@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void handleFilterLogic_executes_all_filters_and_uses_original_request_when_filters_are_not_short_circuiting_and_return_null(boolean isFirstChunk) {
// given
HandleFilterLogicMethodCallArgs args = new HandleFilterLogicMethodCallArgs(isFirstChunk);
filtersList.forEach(filter -> doReturn(false).when(filter).isShortCircuitRequestFilter());
// when
PipelineContinuationBehavior result = handlerSpy.handleFilterLogic(ctxMock, args.msg, args.normalFilterCall, args.shortCircuitFilterCall);
// then
assertThat(result).isEqualTo(CONTINUE);
filtersList.forEach(filter -> {
if (isFirstChunk)
verify(filter).filterRequestFirstChunkNoPayload(requestInfoMock, ctxMock);
else
verify(filter).filterRequestLastChunkWithFullPayload(requestInfoMock, ctxMock);
});
assertThat(state.getRequestInfo()).isSameAs(requestInfoMock);
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class AsyncHttpClientHelperTest method executeAsyncHttpRequest_completes_future_if_exception_happens_during_setup.
@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void executeAsyncHttpRequest_completes_future_if_exception_happens_during_setup(boolean throwCircuitBreakerOpenException) {
// given
RuntimeException exToThrow = (throwCircuitBreakerOpenException) ? new CircuitBreakerOpenException("foo", "kaboom") : new RuntimeException("kaboom");
doThrow(exToThrow).when(helperSpy).getCircuitBreaker(any(RequestBuilderWrapper.class));
Logger loggerMock = mock(Logger.class);
Whitebox.setInternalState(helperSpy, "logger", loggerMock);
// when
CompletableFuture result = helperSpy.executeAsyncHttpRequest(mock(RequestBuilderWrapper.class), mock(AsyncResponseHandler.class), null, null);
// then
assertThat(result).isCompletedExceptionally();
Throwable ex = catchThrowable(result::get);
assertThat(ex).isInstanceOf(ExecutionException.class).hasCause(exToThrow);
if (throwCircuitBreakerOpenException)
verifyZeroInteractions(loggerMock);
else
verify(loggerMock).error(anyString(), anyString(), anyString(), eq(exToThrow));
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class AsyncHttpClientHelperTest method getRequestBuilder_with_circuit_breaker_args_sets_values_as_expected.
@DataProvider(value = { "CONNECT", "DELETE", "GET", "HEAD", "POST", "OPTIONS", "PUT", "PATCH", "TRACE", "FOO_METHOD_DOES_NOT_EXIST" }, splitBy = "\\|")
@Test
public void getRequestBuilder_with_circuit_breaker_args_sets_values_as_expected(String methodName) {
CircuitBreaker<Response> cbMock = mock(CircuitBreaker.class);
List<Pair<Optional<CircuitBreaker<Response>>, Boolean>> variations = Arrays.asList(Pair.of(Optional.empty(), true), Pair.of(Optional.empty(), false), Pair.of(Optional.of(cbMock), true), Pair.of(Optional.of(cbMock), false));
variations.forEach(variation -> {
String url = "http://localhost/some/path";
HttpMethod method = HttpMethod.valueOf(methodName);
Optional<CircuitBreaker<Response>> cbOpt = variation.getLeft();
boolean disableCb = variation.getRight();
RequestBuilderWrapper rbw = helperSpy.getRequestBuilder(url, method, cbOpt, disableCb);
verifyRequestBuilderWrapperGeneratedAsExpected(rbw, url, methodName, cbOpt, disableCb);
});
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class AsyncHttpClientHelperTest method constructor_clears_out_tracing_and_mdc_info_before_building_underlying_client_and_resets_afterward.
@DataProvider(value = { "true | true", "true | false", "false | true", "false | false" }, splitBy = "\\|")
@Test
public void constructor_clears_out_tracing_and_mdc_info_before_building_underlying_client_and_resets_afterward(boolean emptyBeforeCall, boolean explode) {
AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().build();
AsyncHttpClientConfig.Builder builderMock = mock(AsyncHttpClientConfig.Builder.class);
List<Span> traceAtTimeOfBuildCall = new ArrayList<>();
List<Map<String, String>> mdcAtTimeOfBuildCall = new ArrayList<>();
RuntimeException explodeEx = new RuntimeException("kaboom");
doAnswer(invocation -> {
traceAtTimeOfBuildCall.add(Tracer.getInstance().getCurrentSpan());
mdcAtTimeOfBuildCall.add(MDC.getCopyOfContextMap());
if (explode)
throw explodeEx;
return config;
}).when(builderMock).build();
Span spanBeforeCall = (emptyBeforeCall) ? null : Tracer.getInstance().startRequestWithRootSpan("foo");
Map<String, String> mdcBeforeCall = MDC.getCopyOfContextMap();
assertThat(Tracer.getInstance().getCurrentSpan()).isEqualTo(spanBeforeCall);
if (emptyBeforeCall)
assertThat(mdcBeforeCall).isNull();
else
assertThat(mdcBeforeCall).isNotEmpty();
// when
Throwable ex = catchThrowable(() -> new AsyncHttpClientHelper(builderMock, true));
// then
verify(builderMock).build();
assertThat(traceAtTimeOfBuildCall).hasSize(1);
assertThat(traceAtTimeOfBuildCall.get(0)).isNull();
assertThat(mdcAtTimeOfBuildCall).hasSize(1);
assertThat(mdcAtTimeOfBuildCall.get(0)).isNull();
assertThat(Tracer.getInstance().getCurrentSpan()).isEqualTo(spanBeforeCall);
assertThat(MDC.getCopyOfContextMap()).isEqualTo(mdcBeforeCall);
if (explode)
assertThat(ex).isSameAs(explodeEx);
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class AsyncHttpClientHelperTest method kitchen_sink_constructor_sets_up_underlying_client_with_expected_config.
@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void kitchen_sink_constructor_sets_up_underlying_client_with_expected_config(boolean performSubspan) {
// given
int customRequestTimeoutVal = 4242;
AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setRequestTimeout(customRequestTimeoutVal).build();
AsyncHttpClientConfig.Builder builderMock = mock(AsyncHttpClientConfig.Builder.class);
doReturn(config).when(builderMock).build();
// when
AsyncHttpClientHelper instance = new AsyncHttpClientHelper(builderMock, performSubspan);
// then
assertThat(instance.performSubSpanAroundDownstreamCalls).isEqualTo(performSubspan);
assertThat(instance.asyncHttpClient.getConfig()).isSameAs(config);
assertThat(instance.asyncHttpClient.getConfig().getRequestTimeout()).isEqualTo(customRequestTimeoutVal);
}
Aggregations