@Test
  public void errorResponseTrackingHeadersTest() {
    EmbeddedChannel channel = createEmbeddedChannel();
    for (boolean shouldTrackingHeadersExist : new boolean[]{true, false}) {
      TestingUri uri;
      HttpHeaders httpHeaders;
      HttpResponse response;
      for (RestServiceErrorCode errorCode : RestServiceErrorCode.values()) {
        httpHeaders = new DefaultHttpHeaders();
        if (shouldTrackingHeadersExist) {
          addTrackingHeaders(httpHeaders);
        }
        uri = shouldTrackingHeadersExist ? TestingUri.CopyHeadersAndOnResponseCompleteWithRestException
            : TestingUri.OnResponseCompleteWithRestException;
        httpHeaders.set(MockNettyMessageProcessor.REST_SERVICE_ERROR_CODE_HEADER_NAME, errorCode);
        channel.writeInbound(RestTestUtils.createRequest(HttpMethod.HEAD, uri.toString(), httpHeaders));
        response = channel.readOutbound();
        verifyTrackingHeaders(response, shouldTrackingHeadersExist);
      }
      httpHeaders = new DefaultHttpHeaders();
      if (shouldTrackingHeadersExist) {
        addTrackingHeaders(httpHeaders);
      }
      uri = shouldTrackingHeadersExist ? TestingUri.CopyHeadersAndOnResponseCompleteWithNonRestException
          : TestingUri.OnResponseCompleteWithNonRestException;
      channel.writeInbound(RestTestUtils.createRequest(HttpMethod.HEAD, uri.toString(), httpHeaders));
      response = channel.readOutbound();
      verifyTrackingHeaders(response, shouldTrackingHeadersExist);
    }
  }
Tests that tracking headers are copied over correctly for error responses.
ambry-rest/src/test/java/com/github/ambry/rest/NettyResponseChannelTest.java