@Test
  public void clientEarlyTerminationTest() throws Exception {
    EmbeddedChannel channel = createEmbeddedChannel();
    TestingUri uri = TestingUri.OnResponseCompleteWithEarlyClientTermination;
    HttpRequest httpRequest = RestTestUtils.createRequest(HttpMethod.POST, uri.toString(), null);
    HttpUtil.setKeepAlive(httpRequest, false);

    String brMetricName = MetricRegistry.name(NettyResponseChannel.class, "BadRequestCount");
    long brBeforeCount = MockNettyMessageProcessor.METRIC_REGISTRY.getCounters().get(brMetricName).getCount();
    String cetMetricName = MetricRegistry.name(NettyResponseChannel.class, "ClientEarlyTerminationCount");
    long cetBeforeCount = MockNettyMessageProcessor.METRIC_REGISTRY.getCounters().get(cetMetricName).getCount();

    channel.writeInbound(httpRequest);
    // first outbound has to be response.
    HttpResponse response = channel.readOutbound();
    assertEquals("Unexpected response status", HttpResponseStatus.BAD_REQUEST, response.status());
    if (!(response instanceof FullHttpResponse)) {
      // empty the channel
      while (channel.readOutbound() != null) {
      }
    }

    assertEquals("Client terminations should not count towards Bad request count", brBeforeCount,
        MockNettyMessageProcessor.METRIC_REGISTRY.getCounters().get(brMetricName).getCount());
    assertEquals("Client terminations should have been tracked", cetBeforeCount + 1,
        MockNettyMessageProcessor.METRIC_REGISTRY.getCounters().get(cetMetricName).getCount());
  }
Tests that client initiated terminations don't count towards {@link HttpResponseStatus#INTERNAL_SERVER_ERROR}.
ambry-rest/src/test/java/com/github/ambry/rest/NettyResponseChannelTest.java