WebSocketHttpTest.java 文件源码

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

项目:GitHub 作者:
/**
 * There's no read timeout when reading the first byte of a new frame. But as soon as we start
 * reading a frame we enable the read timeout. In this test we have the server returning the first
 * byte of a frame but no more frames.
 */
@Test public void readTimeoutAppliesWithinFrames() throws IOException {
  webServer.setDispatcher(new Dispatcher() {
    @Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
      return upgradeResponse(request)
          .setBody(new Buffer().write(ByteString.decodeHex("81"))) // Truncated frame.
          .removeHeader("Content-Length")
          .setSocketPolicy(SocketPolicy.KEEP_OPEN);
    }
  });

  WebSocket webSocket = newWebSocket();
  clientListener.assertOpen();

  clientListener.assertFailure(SocketTimeoutException.class, "timeout", "Read timed out");
  assertFalse(webSocket.close(1000, null));
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号