private void backPressureTest(String digestAlgorithm, boolean useCopyForcingByteBuf, HttpMethod method)
      throws Exception {
    List<HttpContent> httpContents = new ArrayList<HttpContent>();
    byte[] contentBytes = TestUtils.getRandomBytes(GENERATED_CONTENT_SIZE);
    ByteBuffer content = ByteBuffer.wrap(contentBytes);
    splitContent(contentBytes, GENERATED_CONTENT_PART_COUNT, httpContents, useCopyForcingByteBuf);
    int chunkSize = httpContents.get(0).content().readableBytes();
    int[] bufferWatermarks =
        {1, chunkSize - 1, chunkSize, chunkSize + 1, chunkSize * httpContents.size() / 2, content.limit() - 1,
            content.limit(), content.limit() + 1};
    for (int bufferWatermark : bufferWatermarks) {
      NettyRequest.bufferWatermark = bufferWatermark;
      // start reading before addition of content
      httpContents.clear();
      content.rewind();
      splitContent(contentBytes, GENERATED_CONTENT_PART_COUNT, httpContents, useCopyForcingByteBuf);
      doBackPressureTest(digestAlgorithm, content, httpContents, 0, method);
      // start reading in the middle of content add
      httpContents.clear();
      content.rewind();
      splitContent(contentBytes, GENERATED_CONTENT_PART_COUNT, httpContents, useCopyForcingByteBuf);
      doBackPressureTest(digestAlgorithm, content, httpContents, httpContents.size() / 2, method);
      // start reading after all content added
      httpContents.clear();
      content.rewind();
      splitContent(contentBytes, GENERATED_CONTENT_PART_COUNT, httpContents, useCopyForcingByteBuf);
      doBackPressureTest(digestAlgorithm, content, httpContents, httpContents.size(), method);
    }
  }
Tests backpressure support in {@link NettyRequest} for different values of {@link NettyRequest#bufferWatermark}.
@param digestAlgorithm the digest algorithm to use. Can be empty or {@code null} if digest checking is not
                       required.
@param useCopyForcingByteBuf if {@code true}, uses {@link CopyForcingByteBuf} instead of the default
                             {@link ByteBuf}.
@param method Http method
@throws Exception
ambry-rest/src/test/java/com/github/ambry/rest/NettyRequestTest.java