use of okhttp3.CallEvent.CallFailed in project okhttp by square.
the class EventListenerTest method responseBodyFail.
private void responseBodyFail(Protocol expectedProtocol) throws IOException {
// Use a 2 MiB body so the disconnect won't happen until the client has read some data.
// 2 MiB
int responseBodySize = 2 * 1024 * 1024;
server.enqueue(new MockResponse().setBody(new Buffer().write(new byte[responseBodySize])).setSocketPolicy(SocketPolicy.DISCONNECT_DURING_RESPONSE_BODY));
Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
Response response = call.execute();
if (expectedProtocol == Protocol.HTTP_2) {
// soft failure since client may not support depending on Platform
assumeThat(response, matchesProtocol(Protocol.HTTP_2));
}
assertThat(response.protocol()).isEqualTo(expectedProtocol);
try {
response.body().string();
fail();
} catch (IOException expected) {
}
CallFailed callFailed = listener.removeUpToEvent(CallFailed.class);
assertThat(callFailed.getIoe()).isNotNull();
}
use of okhttp3.CallEvent.CallFailed in project okhttp by square.
the class EventListenerTest method emptyDnsLookup.
@Test
public void emptyDnsLookup() {
Dns emptyDns = hostname -> Collections.emptyList();
client = client.newBuilder().dns(emptyDns).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 ClientAuthTest method invalidClientAuthEvents.
@Test
public void invalidClientAuthEvents() throws Throwable {
server.enqueue(new MockResponse().setBody("abc"));
clientCert = new HeldCertificate.Builder().signedBy(clientIntermediateCa).serialNumber(4L).commonName("Jethro Willis").addSubjectAlternativeName("jethrowillis.com").validityInterval(1, 2).build();
OkHttpClient client = buildClient(clientCert, clientIntermediateCa.certificate());
RecordingEventListener listener = new RecordingEventListener();
client = client.newBuilder().eventListener(listener).build();
SSLSocketFactory socketFactory = buildServerSslSocketFactory();
server.useHttps(socketFactory, false);
server.requireClientAuth();
Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
try {
call.execute();
fail();
} catch (IOException expected) {
}
// Observed Events are variable
// JDK 14
// CallStart, ProxySelectStart, ProxySelectEnd, DnsStart, DnsEnd, ConnectStart, SecureConnectStart,
// SecureConnectEnd, ConnectEnd, ConnectionAcquired, RequestHeadersStart, RequestHeadersEnd,
// ResponseFailed, ConnectionReleased, CallFailed
// JDK 8
// CallStart, ProxySelectStart, ProxySelectEnd, DnsStart, DnsEnd, ConnectStart, SecureConnectStart,
// ConnectFailed, CallFailed
// Gradle - JDK 11
// CallStart, ProxySelectStart, ProxySelectEnd, DnsStart, DnsEnd, ConnectStart, SecureConnectStart,
// SecureConnectEnd, ConnectFailed, CallFailed
List<String> recordedEventTypes = listener.recordedEventTypes();
assertThat(recordedEventTypes).startsWith("CallStart", "ProxySelectStart", "ProxySelectEnd", "DnsStart", "DnsEnd", "ConnectStart", "SecureConnectStart");
assertThat(recordedEventTypes).endsWith("CallFailed");
}
Aggregations