private void doWriteMoreThanContentLengthTest(int chunkCount) throws Exception {
    EmbeddedChannel channel = createEmbeddedChannel();
    MockNettyMessageProcessor processor = channel.pipeline().get(MockNettyMessageProcessor.class);
    HttpHeaders httpHeaders = new DefaultHttpHeaders();
    httpHeaders.set(MockNettyMessageProcessor.CHUNK_COUNT_HEADER_NAME, chunkCount);
    HttpRequest httpRequest =
        RestTestUtils.createRequest(HttpMethod.POST, TestingUri.WriteMoreThanContentLength.toString(), httpHeaders);
    HttpUtil.setKeepAlive(httpRequest, true);
    channel.writeInbound(httpRequest);

    try {
      verifyCallbacks(processor);
      fail("One of the callbacks should have failed because the data written was more than Content-Length");
    } catch (IllegalStateException e) {
      // expected. Nothing to do.
    }

    // It doesn't matter what the response is - because it may either fail or succeed depending on certain race
    // conditions. What matters is that the programming error is caught appropriately by NettyResponseChannel and it
    // makes a callback with the right exception.
    while (channel.readOutbound() != null) {
    }
    channel.close();
  }
Asks the server to write more data than the set Content-Length and checks behavior.
@param chunkCount the number of chunks of {@link MockNettyMessageProcessor#CHUNK} to use to set Content-Length.
@throws Exception
ambry-rest/src/test/java/com/github/ambry/rest/NettyResponseChannelTest.java