NettyResponseChannelTest.java 文件源码

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

项目:ambry 作者:
/**
 * Tests setting of different available {@link ResponseStatus} codes and sees that they are recognized and converted
 * in {@link NettyResponseChannel}.
 * <p/>
 * If this test fails, a case for conversion probably needs to be added in {@link NettyResponseChannel}.
 */
@Test
public void setStatusTest() {
  // ask for every status to be set
  for (ResponseStatus expectedResponseStatus : ResponseStatus.values()) {
    HttpRequest request = createRequestWithHeaders(HttpMethod.GET, TestingUri.SetStatus.toString());
    request.headers().set(MockNettyMessageProcessor.STATUS_HEADER_NAME, expectedResponseStatus);
    HttpUtil.setKeepAlive(request, false);
    EmbeddedChannel channel = createEmbeddedChannel();
    channel.writeInbound(request);

    // pull but discard response
    channel.readOutbound();
    assertFalse("Channel not closed on the server", channel.isActive());
  }
  // check if all the ResponseStatus codes were recognized.
  String metricName = MetricRegistry.name(NettyResponseChannel.class, "UnknownResponseStatusCount");
  long metricCount = MockNettyMessageProcessor.METRIC_REGISTRY.getCounters().get(metricName).getCount();
  assertEquals("Some of the ResponseStatus codes were not recognized", 0, metricCount);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号