use of com.codahale.metrics.httpclient.InstrumentedHttpClientConnectionManager in project dropwizard by dropwizard.
the class HttpClientBuilderTest method canUseACustomDnsResolver.
@Test
void canUseACustomDnsResolver() throws Exception {
final DnsResolver resolver = mock(DnsResolver.class);
final InstrumentedHttpClientConnectionManager manager = builder.using(resolver).createConnectionManager(registry, "test");
// Yes, this is gross. Thanks, Apache!
final Field connectionOperatorField = getInaccessibleField(PoolingHttpClientConnectionManager.class, "connectionOperator");
final Object connectOperator = connectionOperatorField.get(manager);
final Field dnsResolverField = getInaccessibleField(connectOperator.getClass(), "dnsResolver");
assertThat(dnsResolverField.get(connectOperator)).isEqualTo(resolver);
}
use of com.codahale.metrics.httpclient.InstrumentedHttpClientConnectionManager in project wikidata-query-rdf by wikimedia.
the class HttpClientUtils method createConnectionManager.
public static HttpClientConnectionManager createConnectionManager(MetricRegistry registry, int soTimeout) {
InstrumentedHttpClientConnectionManager connectionManager = new InstrumentedHttpClientConnectionManager(registry);
configureConnectionManager(soTimeout, connectionManager);
return connectionManager;
}
use of com.codahale.metrics.httpclient.InstrumentedHttpClientConnectionManager in project dropwizard by dropwizard.
the class HttpClientBuilderTest method usesASystemDnsResolverByDefault.
@Test
void usesASystemDnsResolverByDefault() throws Exception {
final InstrumentedHttpClientConnectionManager manager = builder.createConnectionManager(registry, "test");
// Yes, this is gross. Thanks, Apache!
final Field connectionOperatorField = getInaccessibleField(PoolingHttpClientConnectionManager.class, "connectionOperator");
final Object connectOperator = connectionOperatorField.get(manager);
final Field dnsResolverField = getInaccessibleField(connectOperator.getClass(), "dnsResolver");
assertThat(dnsResolverField.get(connectOperator)).isInstanceOf(SystemDefaultDnsResolver.class);
}
use of com.codahale.metrics.httpclient.InstrumentedHttpClientConnectionManager in project dropwizard by dropwizard.
the class HttpClientBuilder method createConnectionManager.
/**
* Create a InstrumentedHttpClientConnectionManager based on the
* HttpClientConfiguration. It sets the maximum connections per route and
* the maximum total connections that the connection manager can create
*
* @param registry
* @param name
* @return a InstrumentedHttpClientConnectionManger instance
*/
protected InstrumentedHttpClientConnectionManager createConnectionManager(Registry<ConnectionSocketFactory> registry, String name) {
final Duration ttl = configuration.getTimeToLive();
final InstrumentedHttpClientConnectionManager manager = InstrumentedHttpClientConnectionManager.builder(metricRegistry).socketFactoryRegistry(registry).dnsResolver(resolver).connTTL(ttl.getQuantity()).connTTLTimeUnit(ttl.getUnit()).name(name).build();
return configureConnectionManager(manager);
}
Aggregations