Search in sources :

Example 46 with Dns

use of okhttp3.Dns in project okhttp by square.

the class EventListenerTest method emptyDnsLookup.

@Test
public void emptyDnsLookup() {
    Dns emptyDns = hostname -> Collections.emptyList();
    client = client.newBuilder().dns(emptyDns).build();
    Call call = client.newCall(new Request.Builder().url("http://fakeurl/").build());
    try {
        call.execute();
        fail();
    } catch (IOException expected) {
    }
    listener.removeUpToEvent(DnsStart.class);
    CallFailed callFailed = listener.removeUpToEvent(CallFailed.class);
    assertThat(callFailed.getCall()).isSameAs(call);
    assertThat(callFailed.getIoe()).isInstanceOf(UnknownHostException.class);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) SecureConnectStart(okhttp3.CallEvent.SecureConnectStart) CoreMatchers(org.hamcrest.CoreMatchers) BeforeEach(org.junit.jupiter.api.BeforeEach) RealConnectionPool(okhttp3.internal.connection.RealConnectionPool) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HandshakeCertificates(okhttp3.tls.HandshakeCertificates) MockWebServer(mockwebserver3.MockWebServer) InetAddress(java.net.InetAddress) Proxy(java.net.Proxy) BufferedSink(okio.BufferedSink) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) RequestBodyEnd(okhttp3.CallEvent.RequestBodyEnd) Tag(org.junit.jupiter.api.Tag) ConnectionAcquired(okhttp3.CallEvent.ConnectionAcquired) CallStart(okhttp3.CallEvent.CallStart) DnsStart(okhttp3.CallEvent.DnsStart) SecureConnectEnd(okhttp3.CallEvent.SecureConnectEnd) ResponseBodyStart(okhttp3.CallEvent.ResponseBodyStart) ConnectEnd(okhttp3.CallEvent.ConnectEnd) ResponseBodyEnd(okhttp3.CallEvent.ResponseBodyEnd) ConnectStart(okhttp3.CallEvent.ConnectStart) InetSocketAddress(java.net.InetSocketAddress) Flaky(okhttp3.testing.Flaky) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) RequestBodyStart(okhttp3.CallEvent.RequestBodyStart) TlsUtil.localhost(okhttp3.tls.internal.TlsUtil.localhost) ResponseHeadersEnd(okhttp3.CallEvent.ResponseHeadersEnd) MatcherAssert(org.hamcrest.MatcherAssert) CallEnd(okhttp3.CallEvent.CallEnd) PlatformRule(okhttp3.testing.PlatformRule) RecordingOkAuthenticator(okhttp3.internal.RecordingOkAuthenticator) MockResponse(mockwebserver3.MockResponse) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assume.assumeThat(org.junit.Assume.assumeThat) RequestHeadersEnd(okhttp3.CallEvent.RequestHeadersEnd) ResponseHeadersStart(okhttp3.CallEvent.ResponseHeadersStart) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) DoubleInetAddressDns(okhttp3.internal.DoubleInetAddressDns) DnsEnd(okhttp3.CallEvent.DnsEnd) ResponseFailed(okhttp3.CallEvent.ResponseFailed) ConnectFailed(okhttp3.CallEvent.ConnectFailed) InterruptedIOException(java.io.InterruptedIOException) SocketPolicy(mockwebserver3.SocketPolicy) BaseMatcher(org.hamcrest.BaseMatcher) CoreMatchers.any(org.hamcrest.CoreMatchers.any) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Nullable(javax.annotation.Nullable) ConnectionReleased(okhttp3.CallEvent.ConnectionReleased) Description(org.hamcrest.Description) Buffer(okio.Buffer) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) AfterEach(org.junit.jupiter.api.AfterEach) RequestHeadersStart(okhttp3.CallEvent.RequestHeadersStart) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Matcher(org.hamcrest.Matcher) Collections(java.util.Collections) Timeout(org.junit.jupiter.api.Timeout) CallFailed(okhttp3.CallEvent.CallFailed) DoubleInetAddressDns(okhttp3.internal.DoubleInetAddressDns) CallFailed(okhttp3.CallEvent.CallFailed) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.Test)23 MockResponse (okhttp3.mockwebserver.MockResponse)13 OkHttpClient (okhttp3.OkHttpClient)12 DoubleInetAddressDns (okhttp3.internal.DoubleInetAddressDns)10 Test (org.junit.jupiter.api.Test)9 IOException (java.io.IOException)8 Request (okhttp3.Request)8 SingleInetAddressDns (okhttp3.internal.SingleInetAddressDns)8 InetAddress (java.net.InetAddress)7 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 MockResponse (mockwebserver3.MockResponse)6 Response (okhttp3.Response)6 HttpURLConnection (java.net.HttpURLConnection)5 InetSocketAddress (java.net.InetSocketAddress)5 UnknownHostException (java.net.UnknownHostException)5 List (java.util.List)4 X509TrustManager (javax.net.ssl.X509TrustManager)4 Dns (okhttp3.Dns)4 Interceptor (okhttp3.Interceptor)4 HandshakeCertificates (okhttp3.tls.HandshakeCertificates)4