Search in sources :

Example 1 with InstrumentedHttpClientConnectionManager

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);
}
Also used : SystemDefaultDnsResolver(org.apache.http.impl.conn.SystemDefaultDnsResolver) DnsResolver(org.apache.http.conn.DnsResolver) Field(java.lang.reflect.Field) InstrumentedHttpClientConnectionManager(com.codahale.metrics.httpclient.InstrumentedHttpClientConnectionManager) Test(org.junit.jupiter.api.Test)

Example 2 with InstrumentedHttpClientConnectionManager

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;
}
Also used : InstrumentedHttpClientConnectionManager(com.codahale.metrics.httpclient.InstrumentedHttpClientConnectionManager)

Example 3 with InstrumentedHttpClientConnectionManager

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);
}
Also used : Field(java.lang.reflect.Field) InstrumentedHttpClientConnectionManager(com.codahale.metrics.httpclient.InstrumentedHttpClientConnectionManager) Test(org.junit.jupiter.api.Test)

Example 4 with InstrumentedHttpClientConnectionManager

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);
}
Also used : InstrumentedHttpClientConnectionManager(com.codahale.metrics.httpclient.InstrumentedHttpClientConnectionManager) Duration(io.dropwizard.util.Duration)

Aggregations

InstrumentedHttpClientConnectionManager (com.codahale.metrics.httpclient.InstrumentedHttpClientConnectionManager)4 Field (java.lang.reflect.Field)2 Test (org.junit.jupiter.api.Test)2 Duration (io.dropwizard.util.Duration)1 DnsResolver (org.apache.http.conn.DnsResolver)1 SystemDefaultDnsResolver (org.apache.http.impl.conn.SystemDefaultDnsResolver)1