Search in sources :

Example 6 with DnsResolver

use of org.apache.http.conn.DnsResolver in project helios by spotify.

the class EndpointsTest method testInvalidUri_NoScheme.

@Test
public void testInvalidUri_NoScheme() throws Exception {
    final DnsResolver resolver = mock(DnsResolver.class);
    when(resolver.resolve("example.com")).thenReturn(IPS_1);
    exception.expect(IllegalArgumentException.class);
    Endpoints.of(ImmutableList.of(new URI(null, "example.com", null, null)), resolver);
}
Also used : DnsResolver(org.apache.http.conn.DnsResolver) URI(java.net.URI) Test(org.junit.Test)

Example 7 with DnsResolver

use of org.apache.http.conn.DnsResolver in project helios by spotify.

the class EndpointsTest method testFactory.

@Test
public void testFactory() throws Exception {
    final DnsResolver resolver = mock(DnsResolver.class);
    when(resolver.resolve("example.com")).thenReturn(IPS_1);
    when(resolver.resolve("example.net")).thenReturn(IPS_2);
    final List<Endpoint> endpoints = Endpoints.of(uris, resolver);
    assertThat(endpoints.size(), equalTo(4));
    assertThat(endpoints.get(0).getUri(), equalTo(uri1));
    assertThat(endpoints.get(0).getIp(), equalTo(IP_A));
    assertThat(endpoints.get(1).getUri(), equalTo(uri1));
    assertThat(endpoints.get(1).getIp(), equalTo(IP_B));
    assertThat(endpoints.get(2).getUri(), equalTo(uri2));
    assertThat(endpoints.get(2).getIp(), equalTo(IP_C));
    assertThat(endpoints.get(3).getUri(), equalTo(uri2));
    assertThat(endpoints.get(3).getIp(), equalTo(IP_D));
}
Also used : DnsResolver(org.apache.http.conn.DnsResolver) Test(org.junit.Test)

Example 8 with DnsResolver

use of org.apache.http.conn.DnsResolver in project helios by spotify.

the class EndpointsTest method testSupplierFactory.

@Test
public void testSupplierFactory() throws Exception {
    final DnsResolver resolver = mock(DnsResolver.class);
    when(resolver.resolve("example.com")).thenReturn(IPS_1);
    when(resolver.resolve("example.net")).thenReturn(IPS_2);
    final Supplier<List<URI>> uriSupplier = Suppliers.ofInstance(uris);
    final Supplier<List<Endpoint>> endpointSupplier = Endpoints.of(uriSupplier, resolver);
    final List<Endpoint> endpoints = endpointSupplier.get();
    assertThat(endpoints.size(), equalTo(4));
    assertThat(endpoints.get(0).getUri(), equalTo(uri1));
    assertThat(endpoints.get(0).getIp(), equalTo(IP_A));
    assertThat(endpoints.get(1).getUri(), equalTo(uri1));
    assertThat(endpoints.get(1).getIp(), equalTo(IP_B));
    assertThat(endpoints.get(2).getUri(), equalTo(uri2));
    assertThat(endpoints.get(2).getIp(), equalTo(IP_C));
    assertThat(endpoints.get(3).getUri(), equalTo(uri2));
    assertThat(endpoints.get(3).getIp(), equalTo(IP_D));
}
Also used : DnsResolver(org.apache.http.conn.DnsResolver) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Aggregations

DnsResolver (org.apache.http.conn.DnsResolver)8 Test (org.junit.Test)7 SystemDefaultDnsResolver (org.apache.http.impl.conn.SystemDefaultDnsResolver)3 URI (java.net.URI)2 InstrumentedHttpClientConnectionManager (com.codahale.metrics.httpclient.InstrumentedHttpClientConnectionManager)1 ImmutableList (com.google.common.collect.ImmutableList)1 Field (java.lang.reflect.Field)1 UnknownHostException (java.net.UnknownHostException)1 List (java.util.List)1 HttpHost (org.apache.http.HttpHost)1 AuthScope (org.apache.http.auth.AuthScope)1 NTCredentials (org.apache.http.auth.NTCredentials)1 HttpRequestRetryHandler (org.apache.http.client.HttpRequestRetryHandler)1 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)1 AbstractHttpClient (org.apache.http.impl.client.AbstractHttpClient)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1 StandardHttpRequestRetryHandler (org.apache.http.impl.client.StandardHttpRequestRetryHandler)1 BasicHttpParams (org.apache.http.params.BasicHttpParams)1 DefaultedHttpParams (org.apache.http.params.DefaultedHttpParams)1