EventListenerTest.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:GitHub 作者:
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);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号