Search in sources :

Example 11 with MockDuplexResponseBody

use of mockwebserver3.internal.duplex.MockDuplexResponseBody in project okhttp by square.

the class DuplexTest method fullCallTimeoutDoesNotApplyOnceConnected.

@Test
public void fullCallTimeoutDoesNotApplyOnceConnected() throws Exception {
    enableProtocol(Protocol.HTTP_2);
    MockDuplexResponseBody mockDuplexResponseBody = enqueueResponseWithBody(new MockResponse().clearHeaders(), new MockDuplexResponseBody().sendResponse("response A\n").sleep(750, TimeUnit.MILLISECONDS).sendResponse("response B\n").receiveRequest("request C\n").exhaustResponse().exhaustRequest());
    Request request = new Request.Builder().url(server.url("/")).post(new AsyncRequestBody()).build();
    Call call = client.newCall(request);
    // Long enough for the first TLS handshake.
    call.timeout().timeout(500, TimeUnit.MILLISECONDS);
    try (Response response = call.execute()) {
        BufferedSink requestBody = ((AsyncRequestBody) call.request().body()).takeSink();
        BufferedSource responseBody = response.body().source();
        assertThat(responseBody.readUtf8Line()).isEqualTo("response A");
        assertThat(responseBody.readUtf8Line()).isEqualTo("response B");
        requestBody.writeUtf8("request C\n");
        requestBody.close();
        assertThat(responseBody.readUtf8Line()).isNull();
    }
    mockDuplexResponseBody.awaitSuccess();
}
Also used : MockResponse(mockwebserver3.MockResponse) MockResponse(mockwebserver3.MockResponse) MockDuplexResponseBody(mockwebserver3.internal.duplex.MockDuplexResponseBody) AsyncRequestBody(okhttp3.internal.duplex.AsyncRequestBody) BufferedSink(okio.BufferedSink) BufferedSource(okio.BufferedSource) Test(org.junit.jupiter.api.Test)

Aggregations

MockResponse (mockwebserver3.MockResponse)11 MockDuplexResponseBody (mockwebserver3.internal.duplex.MockDuplexResponseBody)11 Test (org.junit.jupiter.api.Test)11 AsyncRequestBody (okhttp3.internal.duplex.AsyncRequestBody)10 BufferedSink (okio.BufferedSink)10 BufferedSource (okio.BufferedSource)9 IOException (java.io.IOException)3 ProtocolException (java.net.ProtocolException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 RecordingOkAuthenticator (okhttp3.internal.RecordingOkAuthenticator)1 Nullable (org.jetbrains.annotations.Nullable)1 Disabled (org.junit.jupiter.api.Disabled)1