use of com.ning.http.client.AsyncHttpClientConfig 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.ning.http.client.AsyncHttpClientConfig 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);
}
use of com.ning.http.client.AsyncHttpClientConfig in project riposte by Nike-Inc.
the class AsyncHttpClientHelperTest method verifyDefaultUnderlyingClientConfig.
private void verifyDefaultUnderlyingClientConfig(AsyncHttpClientHelper instance) {
AsyncHttpClientConfig config = instance.asyncHttpClient.getConfig();
assertThat(config.isAllowPoolingConnections()).isTrue();
assertThat(config.getMaxRequestRetry()).isEqualTo(0);
assertThat(config.getRequestTimeout()).isEqualTo(DEFAULT_REQUEST_TIMEOUT_MILLIS);
assertThat(config.getConnectionTTL()).isEqualTo(DEFAULT_POOLED_DOWNSTREAM_CONNECTION_TTL_MILLIS);
}
use of com.ning.http.client.AsyncHttpClientConfig in project sonatype-aether by sonatype.
the class AsyncRepositoryConnector method getProvider.
private AsyncHttpProvider getProvider(RepositorySystemSession session, AsyncHttpClientConfig config) {
String className = ConfigUtils.getString(session, "", "aether.connector.ahc.provider");
if (className != null && className.length() > 0) {
if ("netty".equals(className)) {
className = "com.ning.http.client.providers.netty.NettyAsyncHttpProvider";
} else if ("jdk".equals(className)) {
className = "com.ning.http.client.providers.jdk.JDKAsyncHttpProvider";
} else if ("apache".equals(className)) {
className = "com.ning.http.client.providers.apache.ApacheAsyncHttpProvider";
}
RepositoryCache cache = session.getCache();
try {
if (cache == null || cache.get(session, className) == null) {
logger.debug("Using AHC provider " + className);
Class<?> providerClass = getClass().getClassLoader().loadClass(className);
Object inst = providerClass.getConstructor(AsyncHttpClientConfig.class).newInstance(config);
return (AsyncHttpProvider) inst;
}
} catch (LinkageError e) {
warn("Could not load AHC provider " + className + ", falling back to default", e);
} catch (ClassNotFoundException e) {
logger.warn("Could not load AHC provider " + className + ", falling back to default");
} catch (ClassCastException e) {
logger.warn("Could not load type-compatible AHC provider " + className + ", falling back to default");
} catch (Exception e) {
Throwable cause = e;
if (e instanceof InvocationTargetException && e.getCause() != null) {
cause = e.getCause();
}
warn("Could not instantiate AHC provider " + className + ", falling back to default", cause);
}
if (cache != null) {
cache.put(session, className, Boolean.TRUE);
}
}
return getDefaultProvider(config);
}
Aggregations