use of okhttp3.CallEvent.RequestBodyEnd in project okhttp by square.
the class EventListenerTest method assertBytesReadWritten.
private void assertBytesReadWritten(RecordingEventListener listener, @Nullable Matcher<Long> requestHeaderLength, @Nullable Matcher<Long> requestBodyBytes, @Nullable Matcher<Long> responseHeaderLength, @Nullable Matcher<Long> responseBodyBytes) {
if (requestHeaderLength != null) {
RequestHeadersEnd responseHeadersEnd = listener.removeUpToEvent(RequestHeadersEnd.class);
MatcherAssert.assertThat("request header length", responseHeadersEnd.getHeaderLength(), requestHeaderLength);
} else {
assertThat(listener.recordedEventTypes()).doesNotContain("RequestHeadersEnd");
}
if (requestBodyBytes != null) {
RequestBodyEnd responseBodyEnd = listener.removeUpToEvent(RequestBodyEnd.class);
MatcherAssert.assertThat("request body bytes", responseBodyEnd.getBytesWritten(), requestBodyBytes);
} else {
assertThat(listener.recordedEventTypes()).doesNotContain("RequestBodyEnd");
}
if (responseHeaderLength != null) {
ResponseHeadersEnd responseHeadersEnd = listener.removeUpToEvent(ResponseHeadersEnd.class);
MatcherAssert.assertThat("response header length", responseHeadersEnd.getHeaderLength(), responseHeaderLength);
} else {
assertThat(listener.recordedEventTypes()).doesNotContain("ResponseHeadersEnd");
}
if (responseBodyBytes != null) {
ResponseBodyEnd responseBodyEnd = listener.removeUpToEvent(ResponseBodyEnd.class);
MatcherAssert.assertThat("response body bytes", responseBodyEnd.getBytesRead(), responseBodyBytes);
} else {
assertThat(listener.recordedEventTypes()).doesNotContain("ResponseBodyEnd");
}
}
use of okhttp3.CallEvent.RequestBodyEnd in project okhttp by square.
the class DuplexTest method requestBodyEndsAfterResponseBody.
@Test
public void requestBodyEndsAfterResponseBody() throws Exception {
enableProtocol(Protocol.HTTP_2);
MockDuplexResponseBody mockDuplexResponseBody = enqueueResponseWithBody(new MockResponse().clearHeaders(), new MockDuplexResponseBody().exhaustResponse().receiveRequest("request A\n").exhaustRequest());
Call call = client.newCall(new Request.Builder().url(server.url("/")).post(new AsyncRequestBody()).build());
try (Response response = call.execute()) {
BufferedSource responseBody = response.body().source();
assertTrue(responseBody.exhausted());
BufferedSink requestBody = ((AsyncRequestBody) call.request().body()).takeSink();
requestBody.writeUtf8("request A\n");
requestBody.close();
}
mockDuplexResponseBody.awaitSuccess();
assertThat(listener.recordedEventTypes()).containsExactly("CallStart", "ProxySelectStart", "ProxySelectEnd", "DnsStart", "DnsEnd", "ConnectStart", "SecureConnectStart", "SecureConnectEnd", "ConnectEnd", "ConnectionAcquired", "RequestHeadersStart", "RequestHeadersEnd", "RequestBodyStart", "ResponseHeadersStart", "ResponseHeadersEnd", "ResponseBodyStart", "ResponseBodyEnd", "RequestBodyEnd", "ConnectionReleased", "CallEnd");
}
Aggregations