@Test
  public void fillWriteBufferTest() throws IOException {
    String content = "@@randomContent@@@";
    String lastContent = "@@randomLastContent@@@";
    EmbeddedChannel channel = createEmbeddedChannel();
    HttpRequest httpRequest = RestTestUtils.createRequest(HttpMethod.GET, TestingUri.FillWriteBuffer.toString(), null);
    HttpUtil.setKeepAlive(httpRequest, false);
    channel.writeInbound(httpRequest);
    channel.writeInbound(createContent(content, false));
    channel.writeInbound(createContent(lastContent, true));

    // first outbound has to be response.
    HttpResponse response = channel.readOutbound();
    assertEquals("Unexpected response status", HttpResponseStatus.OK, response.status());
    // content echoed back.
    StringBuilder returnedContent = new StringBuilder();
    while (returnedContent.length() < content.length()) {
      HttpContent responseContent = channel.readOutbound();
      returnedContent.append(RestTestUtils.getContentString(responseContent));
      responseContent.release();
    }
    assertEquals("Content does not match with expected content", content, returnedContent.toString());
    // last content echoed back.
    StringBuilder returnedLastContent = new StringBuilder();
    while (returnedLastContent.length() < lastContent.length()) {
      HttpContent responseContent = channel.readOutbound();
      returnedLastContent.append(RestTestUtils.getContentString(responseContent));
      responseContent.release();
    }
    assertEquals("Content does not match with expected content", lastContent, returnedLastContent.toString());
    assertFalse("Channel not closed on the server", channel.isActive());
  }
Tests handling of content that is larger than write buffer size. In this test case, the write buffer low and high
watermarks are requested to be set to 1 and 2 respectively so the content will be written byte by byte into the
{@link NettyResponseChannel}. This does <b><i>not</i></b> test for the same situation in a async scenario since
{@link EmbeddedChannel} only provides blocking semantics.
@throws IOException
ambry-rest/src/test/java/com/github/ambry/rest/NettyResponseChannelTest.java