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.
int responseBodySize = 2 * 1024 * 1024; // 2 MiB
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));
}
assertEquals(expectedProtocol, response.protocol());
try {
response.body.string();
fail();
} catch (IOException expected) {
}
CallFailed callFailed = listener.removeUpToEvent(CallFailed.class);
assertNotNull(callFailed.ioe);
}
EventListenerTest.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:GitHub
作者:
评论列表
文章目录