Search in sources :

Example 1 with RecordingProxySelector

use of okhttp3.internal.http.RecordingProxySelector in project okhttp by square.

the class CallTest method connectTimeoutsAttemptsAlternateRoute.

/**
   * Make a request with two routes. The first route will time out because it's connecting to a
   * special address that never connects. The automatic retry will succeed.
   */
@Test
public void connectTimeoutsAttemptsAlternateRoute() throws Exception {
    InetSocketAddress unreachableAddress = new InetSocketAddress("10.255.255.1", 8080);
    RecordingProxySelector proxySelector = new RecordingProxySelector();
    proxySelector.proxies.add(new Proxy(Proxy.Type.HTTP, unreachableAddress));
    proxySelector.proxies.add(server.toProxyAddress());
    server.enqueue(new MockResponse().setBody("success!"));
    client = client.newBuilder().proxySelector(proxySelector).readTimeout(100, TimeUnit.MILLISECONDS).connectTimeout(100, TimeUnit.MILLISECONDS).build();
    Request request = new Request.Builder().url("http://android.com/").build();
    executeSynchronously(request).assertCode(200).assertBody("success!");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) RecordingProxySelector(okhttp3.internal.http.RecordingProxySelector) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test)

Example 2 with RecordingProxySelector

use of okhttp3.internal.http.RecordingProxySelector in project okhttp by square.

the class CallTest method readTimeoutFails.

/**
   * Make a request with two routes. The first route will fail because the null server connects but
   * never responds. The manual retry will succeed.
   */
@Test
public void readTimeoutFails() throws Exception {
    InetSocketAddress nullServerAddress = startNullServer();
    RecordingProxySelector proxySelector = new RecordingProxySelector();
    proxySelector.proxies.add(new Proxy(Proxy.Type.HTTP, nullServerAddress));
    proxySelector.proxies.add(server.toProxyAddress());
    server.enqueue(new MockResponse().setBody("success!"));
    client = client.newBuilder().proxySelector(proxySelector).readTimeout(100, TimeUnit.MILLISECONDS).build();
    Request request = new Request.Builder().url("http://android.com/").build();
    executeSynchronously(request).assertFailure(SocketTimeoutException.class);
    executeSynchronously(request).assertCode(200).assertBody("success!");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) RecordingProxySelector(okhttp3.internal.http.RecordingProxySelector) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test)

Example 3 with RecordingProxySelector

use of okhttp3.internal.http.RecordingProxySelector in project okhttp by square.

the class AddressTest method differentProxySelectorsAreDifferent.

@Test
public void differentProxySelectorsAreDifferent() throws Exception {
    Address a = new Address("square.com", 80, dns, socketFactory, null, null, null, authenticator, null, protocols, connectionSpecs, new RecordingProxySelector());
    Address b = new Address("square.com", 80, dns, socketFactory, null, null, null, authenticator, null, protocols, connectionSpecs, new RecordingProxySelector());
    assertFalse(a.equals(b));
}
Also used : RecordingProxySelector(okhttp3.internal.http.RecordingProxySelector) Test(org.junit.Test)

Aggregations

RecordingProxySelector (okhttp3.internal.http.RecordingProxySelector)3 Test (org.junit.Test)3 InetSocketAddress (java.net.InetSocketAddress)2 Proxy (java.net.Proxy)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2