use of okhttp3.CallEvent.CallFailed in project okhttp by square.
the class EventListenerTest method failedDribbledCallEventSequence.
@Test
public void failedDribbledCallEventSequence() throws IOException {
server.enqueue(new MockResponse().setBody("0123456789").throttleBody(2, 100, TimeUnit.MILLISECONDS).setSocketPolicy(SocketPolicy.DISCONNECT_DURING_RESPONSE_BODY));
client = client.newBuilder().protocols(Collections.singletonList(Protocol.HTTP_1_1)).readTimeout(Duration.ofMillis(250)).build();
Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
Response response = call.execute();
try {
response.body().string();
fail();
} catch (IOException expected) {
assertThat(expected.getMessage()).isEqualTo("unexpected end of stream");
}
assertThat(listener.recordedEventTypes()).containsExactly("CallStart", "ProxySelectStart", "ProxySelectEnd", "DnsStart", "DnsEnd", "ConnectStart", "ConnectEnd", "ConnectionAcquired", "RequestHeadersStart", "RequestHeadersEnd", "ResponseHeadersStart", "ResponseHeadersEnd", "ResponseBodyStart", "ResponseFailed", "ConnectionReleased", "CallFailed");
ResponseFailed responseFailed = listener.removeUpToEvent(ResponseFailed.class);
assertThat(responseFailed.getIoe().getMessage()).isEqualTo("unexpected end of stream");
}
use of okhttp3.CallEvent.CallFailed in project okhttp by square.
the class EventListenerTest method failedSecureConnect.
@Test
public void failedSecureConnect() {
enableTlsWithTunnel(false);
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.FAIL_HANDSHAKE));
Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
try {
call.execute();
fail();
} catch (IOException expected) {
}
SecureConnectStart secureStart = listener.removeUpToEvent(SecureConnectStart.class);
assertThat(secureStart.getCall()).isSameAs(call);
CallFailed callFailed = listener.removeUpToEvent(CallFailed.class);
assertThat(callFailed.getCall()).isSameAs(call);
assertThat(callFailed.getIoe()).isNotNull();
}
use of okhttp3.CallEvent.CallFailed in project okhttp by square.
the class EventListenerTest method failedDnsLookup.
@Test
public void failedDnsLookup() {
client = client.newBuilder().dns(new FakeDns()).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);
}
use of okhttp3.CallEvent.CallFailed in project okhttp by square.
the class EventListenerTest method requestBodyFail.
private void requestBodyFail(@Nullable Protocol expectedProtocol) {
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_DURING_REQUEST_BODY));
NonCompletingRequestBody request = new NonCompletingRequestBody();
Call call = client.newCall(new Request.Builder().url(server.url("/")).post(request).build());
try {
call.execute();
fail();
} catch (IOException expected) {
}
if (expectedProtocol != null) {
ConnectionAcquired connectionAcquired = listener.removeUpToEvent(ConnectionAcquired.class);
assertThat(connectionAcquired.getConnection().protocol()).isEqualTo(expectedProtocol);
}
CallFailed callFailed = listener.removeUpToEvent(CallFailed.class);
assertThat(callFailed.getIoe()).isNotNull();
assertThat(request.ioe).isNotNull();
}
use of okhttp3.CallEvent.CallFailed in project okhttp by square.
the class LoggingEventListenerTest method dnsFail.
@Test
public void dnsFail() throws IOException {
client = new OkHttpClient.Builder().dns(hostname -> {
throw new UnknownHostException("reason");
}).eventListenerFactory(loggingEventListenerFactory).build();
try {
client.newCall(request().build()).execute();
fail();
} catch (UnknownHostException expected) {
}
logRecorder.assertLogMatch("callStart: Request\\{method=GET, url=" + url + "\\}").assertLogMatch("proxySelectStart: " + url).assertLogMatch("proxySelectEnd: \\[DIRECT\\]").assertLogMatch("dnsStart: " + url.host()).assertLogMatch("callFailed: java.net.UnknownHostException: reason").assertNoMoreLogs();
}
Aggregations