Search in sources :

Example 1 with DoubleInetAddressDns

use of okhttp3.internal.DoubleInetAddressDns in project okhttp by square.

the class HttpOverHttp2Test method recoverFromOneInternalErrorRequiresNewConnection.

@Test
public void recoverFromOneInternalErrorRequiresNewConnection() throws Exception {
    server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.RESET_STREAM_AT_START).setHttp2ErrorCode(ErrorCode.INTERNAL_ERROR.httpCode));
    server.enqueue(new MockResponse().setBody("abc"));
    client = client.newBuilder().dns(new DoubleInetAddressDns()).build();
    Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
    Response response = call.execute();
    assertEquals("abc", response.body().string());
    // New connection.
    assertEquals(0, server.takeRequest().getSequenceNumber());
    // New connection.
    assertEquals(0, server.takeRequest().getSequenceNumber());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) Call(okhttp3.Call) DoubleInetAddressDns(okhttp3.internal.DoubleInetAddressDns) Request(okhttp3.Request) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test)

Example 2 with DoubleInetAddressDns

use of okhttp3.internal.DoubleInetAddressDns in project okhttp by square.

the class URLConnectionTest method streamedBodyIsNotRetried.

@Test
public void streamedBodyIsNotRetried() throws Exception {
    server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AFTER_REQUEST));
    urlFactory = new OkUrlFactory(defaultClient().newBuilder().dns(new DoubleInetAddressDns()).build());
    HttpURLConnection connection = urlFactory.open(server.url("/").url());
    connection.setDoOutput(true);
    connection.setChunkedStreamingMode(100);
    OutputStream os = connection.getOutputStream();
    os.write("OutputStream is no fun.".getBytes("UTF-8"));
    os.close();
    try {
        connection.getResponseCode();
        fail();
    } catch (IOException expected) {
    }
    assertEquals(1, server.getRequestCount());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HttpURLConnection(java.net.HttpURLConnection) OkHttpURLConnection(okhttp3.internal.huc.OkHttpURLConnection) DoubleInetAddressDns(okhttp3.internal.DoubleInetAddressDns) OutputStream(java.io.OutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with DoubleInetAddressDns

use of okhttp3.internal.DoubleInetAddressDns in project okhttp by square.

the class CallTest method recoverWhenRetryOnConnectionFailureIsTrue.

@Test
public void recoverWhenRetryOnConnectionFailureIsTrue() throws Exception {
    server.enqueue(new MockResponse().setBody("seed connection pool"));
    server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AFTER_REQUEST));
    server.enqueue(new MockResponse().setBody("retry success"));
    client = client.newBuilder().dns(new DoubleInetAddressDns()).build();
    assertTrue(client.retryOnConnectionFailure());
    executeSynchronously("/").assertBody("seed connection pool");
    executeSynchronously("/").assertBody("retry success");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) DoubleInetAddressDns(okhttp3.internal.DoubleInetAddressDns) Test(org.junit.Test)

Example 4 with DoubleInetAddressDns

use of okhttp3.internal.DoubleInetAddressDns in project okhttp by square.

the class HttpOverHttp2Test method recoverFromMultipleRefusedStreamsRequiresNewConnection.

@Test
public void recoverFromMultipleRefusedStreamsRequiresNewConnection() throws Exception {
    server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.RESET_STREAM_AT_START).setHttp2ErrorCode(ErrorCode.REFUSED_STREAM.httpCode));
    server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.RESET_STREAM_AT_START).setHttp2ErrorCode(ErrorCode.REFUSED_STREAM.httpCode));
    server.enqueue(new MockResponse().setBody("abc"));
    client = client.newBuilder().dns(new DoubleInetAddressDns()).build();
    Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
    Response response = call.execute();
    assertEquals("abc", response.body().string());
    // New connection.
    assertEquals(0, server.takeRequest().getSequenceNumber());
    // Reused connection.
    assertEquals(1, server.takeRequest().getSequenceNumber());
    // New connection.
    assertEquals(0, server.takeRequest().getSequenceNumber());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) Call(okhttp3.Call) DoubleInetAddressDns(okhttp3.internal.DoubleInetAddressDns) Request(okhttp3.Request) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test)

Aggregations

DoubleInetAddressDns (okhttp3.internal.DoubleInetAddressDns)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 Test (org.junit.Test)4 Call (okhttp3.Call)2 Request (okhttp3.Request)2 Response (okhttp3.Response)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 OkHttpURLConnection (okhttp3.internal.huc.OkHttpURLConnection)1