private void onResponseCompleteWithRestException() throws RestServiceException {
    String errorCodeStr = (String) request.getArgs().get(REST_SERVICE_ERROR_CODE_HEADER_NAME);
    boolean includeExceptionMessageInResponse =
        request.getArgs().containsKey(INCLUDE_EXCEPTION_MESSAGE_IN_RESPONSE_HEADER_NAME);
    RestServiceErrorCode errorCode = RestServiceErrorCode.valueOf(errorCodeStr);
    if (errorCode == RestServiceErrorCode.NotAllowed) {
      restResponseChannel.setHeader(RestUtils.Headers.ALLOW, METHOD_NOT_ALLOWED_ALLOW_HEADER_VALUE);
    }
    restResponseChannel.onResponseComplete(
        new RestServiceException(errorCodeStr, errorCode, includeExceptionMessageInResponse, false,
            Collections.emptyMap()));
    assertEquals("ResponseStatus does not reflect error", ResponseStatus.getResponseStatus(errorCode),
        restResponseChannel.getStatus());
    assertFalse("Request channel is not closed", request.isOpen());
  }
Forces the response to complete with a Rest Exception for testing purpose.
@throws RestServiceException
ambry-rest/src/test/java/com/github/ambry/rest/NettyResponseChannelTest.java