com.amazonaws.http.HttpResponse Java Examples

The following examples show how to use com.amazonaws.http.HttpResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleAwsResponseHandlerTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * {@link SimpleAwsResponseHandler} can throw AmazonServiceException
 * in case the response status is not in the expected range.
 */
@Test
public void throwsAwsExceptionOnBadStatus() {
    HttpResponse response = Mockito.mock(HttpResponse.class);
    Mockito.when(response.getStatusCode()).thenReturn(HttpURLConnection.HTTP_BAD_METHOD);
    String content = "bad request message";
    Mockito.when(response.getContent())
        .thenReturn(
            new ByteArrayInputStream(content.getBytes())
        );
    try {
        new SimpleAwsResponseHandler(true).handle(response);
        fail("AmazonServiceException should have been thrown!");
    } catch (AmazonServiceException awsEx) {
        assertTrue(awsEx.getErrorMessage().equals(content));
        assertTrue(awsEx.getStatusCode() == HttpURLConnection.HTTP_BAD_METHOD);
    }
}
 
Example #2
Source File: SimpleAwsResponseHandlerTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * SimpleAwsResponseHandler returns the plain response as is, since the status is
 * in range [200, 300)
 * @throws Exception If something goes wrong.
 */
@Test
public void responseStatusInRange() throws Exception {
    HttpResponse response = Mockito.mock(HttpResponse.class);
    Mockito.when(response.getStatusCode()).thenReturn(HttpURLConnection.HTTP_OK);
    String content = "This content should not be affected!";
    Mockito.when(response.getContent()).thenReturn(
        new ByteArrayInputStream(content.getBytes())
    );
    SimpleAwsResponseHandler handler = new SimpleAwsResponseHandler(false);
    assertFalse(handler.needsConnectionLeftOpen());
    HttpResponse handled = handler.handle(response);
    assertTrue(handled.getStatusCode() == HttpURLConnection.HTTP_OK);
    String expected = new String(IOUtils.toByteArray(handled.getContent()));
    assertTrue(expected.equals(content));
}
 
Example #3
Source File: CreateSpeechResultUnmarshaller.java    From ivona-speechcloud-sdk-java with Apache License 2.0 6 votes vote down vote up
@Override
public CreateSpeechResult unmarshall(HttpResponse response) {
    String requestId = response.getHeaders().get(HEADER_AMZN_REQUEST_ID);
    String ttsRequestId = response.getHeaders().get(HEADER_IVONA_TTS_REQUEST_ID);
    String contentType = response.getHeaders().get(HEADER_CONTENT_TYPE);
    int requestCharacters = Integer.parseInt(response.getHeaders().get(HEADER_TTS_REQUEST_CHARACTERS));
    int requestUnits = Integer.parseInt(response.getHeaders().get(HEADER_TTS_REQUEST_UNITS));

    CreateSpeechResult createSpeechResult = new CreateSpeechResult();
    createSpeechResult.setRequestId(requestId);
    createSpeechResult.setTtsRequestId(ttsRequestId);
    createSpeechResult.setContentType(contentType);
    createSpeechResult.setTtsRequestCharacters(requestCharacters);
    createSpeechResult.setTtsRequestUnits(requestUnits);
    createSpeechResult.setBody(response.getContent());
    return createSpeechResult;
}
 
Example #4
Source File: SpectatorRequestMetricCollectorTest.java    From spectator with Apache License 2.0 6 votes vote down vote up
private void execRequest(String endpoint, int status) {
  AWSRequestMetrics metrics = new AWSRequestMetricsFullSupport();
  metrics.addProperty(AWSRequestMetrics.Field.ServiceName, "AmazonCloudWatch");
  metrics.addProperty(AWSRequestMetrics.Field.ServiceEndpoint, endpoint);
  metrics.addProperty(AWSRequestMetrics.Field.StatusCode, "" + status);
  if (status == 503) {
    metrics.addProperty(AWSRequestMetrics.Field.AWSErrorCode, "Throttled");
  }
  String counterName = "BytesProcessed";
  String timerName = "ClientExecuteTime";
  metrics.setCounter(counterName, 12345);
  metrics.getTimingInfo().addSubMeasurement(timerName, TimingInfo.unmodifiableTimingInfo(100000L, 200000L));

  Request<?> req = new DefaultRequest(new ListMetricsRequest(), "AmazonCloudWatch");
  req.setAWSRequestMetrics(metrics);
  req.setEndpoint(URI.create(endpoint));

  HttpResponse hr = new HttpResponse(req, new HttpPost(endpoint));
  hr.setStatusCode(status);
  Response<?> resp = new Response<>(null, new HttpResponse(req, new HttpPost(endpoint)));

  collector.collectMetrics(req, resp);
}
 
Example #5
Source File: PublishResultCodersTest.java    From beam with Apache License 2.0 5 votes vote down vote up
private PublishResult buildFullPublishResult() {
  PublishResult publishResult = new PublishResult().withMessageId(UUID.randomUUID().toString());
  publishResult.setSdkResponseMetadata(
      new ResponseMetadata(
          ImmutableMap.of(ResponseMetadata.AWS_REQUEST_ID, UUID.randomUUID().toString())));
  HttpResponse httpResponse = new HttpResponse(null, null);
  httpResponse.setStatusCode(200);
  httpResponse.addHeader("Content-Type", "application/json");
  publishResult.setSdkHttpMetadata(SdkHttpMetadata.from(httpResponse));
  return publishResult;
}
 
Example #6
Source File: SearchResponseHandlerTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * SearchResponseHandler can throw AmazonServiceException in case the response status is not
 * in the expected range.
 */
@Test
public void throwsAwsExceptionOnBadStatus() {
    HttpResponse response = Mockito.mock(HttpResponse.class);
    Mockito.when(response.getStatusCode()).thenReturn(HttpURLConnection.HTTP_NOT_FOUND);
    try {
        new SearchResponseHandler().handle(response);
        fail("AmazonServiceException should have been thrown!");
    } catch (AmazonServiceException awsEx) {
           assertTrue(awsEx.getErrorMessage().equals("Unexpected status: 404"));
        assertTrue(awsEx.getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND);
    }
}
 
Example #7
Source File: SearchResponseHandlerTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * SearchResponseHandler can build the search results page from an
 * aws HttpResponse
 * @throws Exception If something goes wrong.
 */
@Test
public void buildsSearchResultsPage() throws Exception {
    HttpResponse response = Mockito.mock(HttpResponse.class);
    Mockito.when(response.getStatusCode()).thenReturn(HttpURLConnection.HTTP_OK);
    Mockito.when(response.getContent()).thenReturn(
         new FileInputStream(
            new File("src/test/resources/esSearchResponse.json")
         )
    );
    SearchResultsPage page = new SearchResponseHandler().handle(response);
    assertTrue(page.totalHits() == 27);
    assertTrue(page.results().size() == 10);
    SearchResult first = page.results().get(0);
    assertTrue(first.link().equals("http://amihaiemil.com/page.html"));
    assertTrue(first.category().equals("tech"));

    SearchResult last = page.results().get(9);
    assertTrue(last.link().equals("http://amihaiemil.com/some/other/page.html"));
    assertTrue(last.category().equals("mischelaneous"));
}
 
Example #8
Source File: SimpleAwsResponseHandler.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public HttpResponse handle(HttpResponse response) {

    int status = response.getStatusCode();
    if(status < 200 || status >= 300) {
        String content;
        final StringWriter writer = new StringWriter();
        try {
            IOUtils.copy(response.getContent(), writer, "UTF-8");
            content = writer.toString();
        } catch (final IOException e) {
        	content = "Couldn't get response content!";
        }
        AmazonServiceException ase = new AmazonServiceException(content);
        ase.setStatusCode(status);
        throw ase;
    }

    return response;
    
}
 
Example #9
Source File: AmazonElasticSearch.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void delete(final String type, final String id) {
    final AwsHttpRequest<HttpResponse> deleteDoc =
        new SignedRequest<>(
            new AwsDelete<>(
                new EsHttpRequest<>(
                    this.esEdp,
                    this.indexName + "/" + type + "/" + id,
                    new SimpleAwsResponseHandler(false),
                    new SimpleAwsErrorHandler(false)
                )
            ),
            this.accesskey,
            this.secretKey,
            this.reg
       );
       deleteDoc.perform();
}
 
Example #10
Source File: AmazonElasticSearch.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void delete() {
    final AwsHttpRequest<HttpResponse> deleteIndex =
        new SignedRequest<>(
            new AwsDelete<>(
                new EsHttpRequest<>(
                    this.esEdp,
                    this.indexName,
                    new SimpleAwsResponseHandler(false),
                    new SimpleAwsErrorHandler(false)
                )
            ),
            this.accesskey,
            this.secretKey,
            this.reg
       );
   deleteIndex.perform();
}
 
Example #11
Source File: AmazonElasticSearch.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void export(List<WebPage> pages) throws DataExportException {
    try {
        String data = new EsBulkJson(this.indexName, pages).structure();
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Content-Type", "application/json");
        final AwsHttpRequest<HttpResponse> index =
            new SignedRequest<>(
                new AwsHttpHeaders<>(
                    new AwsPost<>(
                        new EsHttpRequest<>(
                            this.esEdp,
                            "_bulk",
                            new SimpleAwsResponseHandler(false),
                            new SimpleAwsErrorHandler(false)
                        ),
                        new ByteArrayInputStream(data.getBytes())
                    ), headers
                 ),
                 this.accesskey,
                 this.secretKey,
                 this.reg
            );
            index.perform();
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
        throw new DataExportException(e.getMessage());
    }
}
 
Example #12
Source File: SimpleAwsErrorHandlerTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * SimpleAwsErrorHandler returns an {@link AmazonServiceException}
 * from an {@link HttpResponse}.
 */
@Test
public void returnsAwsException() {
    HttpResponse resp = Mockito.mock(HttpResponse.class);
    Mockito.when(resp.getStatusCode()).thenReturn(HttpURLConnection.HTTP_NOT_FOUND);
    Mockito.when(resp.getStatusText()).thenReturn("Test not-found response");
    SimpleAwsErrorHandler handler = new SimpleAwsErrorHandler(false);
    assertFalse(handler.needsConnectionLeftOpen());
    
    AmazonServiceException aes = handler.handle(resp);
    assertTrue(aes.getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND);
    assertTrue(aes.getErrorMessage().equals("Test not-found response"));
}
 
Example #13
Source File: BooleanAwsResponseHandler.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Boolean handle(HttpResponse response) {
    int status = response.getStatusCode();
    if (status != HttpStatus.SC_OK && status != HttpStatus.SC_NOT_FOUND) {
        AmazonServiceException ase = new AmazonServiceException(
                "Unexpected status: " + status);
        ase.setStatusCode(status);
        throw ase;
    }
    return status == HttpStatus.SC_OK ? true : false;
}
 
Example #14
Source File: SearchResponseHandler.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ElasticSearchResults handle(HttpResponse response) {
    int status = response.getStatusCode();
    if(status < 200 || status >= 300) {
        AmazonServiceException ase = new AmazonServiceException("Unexpected status: " + status);
        ase.setStatusCode(status);
        throw ase;
    }
    return new ElasticSearchResults(
        Json.createReader(
            response.getContent()
        ).readObject()
    );
}
 
Example #15
Source File: AwsCoders.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public SdkHttpMetadata decode(InputStream inStream) throws CoderException, IOException {
  final int httpStatusCode = STATUS_CODE_CODER.decode(inStream);
  HttpResponse httpResponse = new HttpResponse(null, null);
  httpResponse.setStatusCode(httpStatusCode);
  if (includeHeaders) {
    Optional.ofNullable(HEADERS_ENCODER.decode(inStream))
        .ifPresent(
            headers ->
                headers.keySet().forEach(k -> httpResponse.addHeader(k, headers.get(k))));
  }
  return SdkHttpMetadata.from(httpResponse);
}
 
Example #16
Source File: AmazonKinesisMock.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public DescribeStreamResult describeStream(String streamName, String exclusiveStartShardId) {
  if (rateLimitDescribeStream-- > 0) {
    throw new LimitExceededException("DescribeStream rate limit exceeded");
  }
  int nextShardId = 0;
  if (exclusiveStartShardId != null) {
    nextShardId = parseInt(exclusiveStartShardId) + 1;
  }
  boolean hasMoreShards = nextShardId + 1 < shardedData.size();

  List<Shard> shards = new ArrayList<>();
  if (nextShardId < shardedData.size()) {
    shards.add(new Shard().withShardId(Integer.toString(nextShardId)));
  }

  HttpResponse response = new HttpResponse(null, null);
  response.setStatusCode(200);
  DescribeStreamResult result = new DescribeStreamResult();
  result.setSdkHttpMetadata(SdkHttpMetadata.from(response));
  result.withStreamDescription(
      new StreamDescription()
          .withHasMoreShards(hasMoreShards)
          .withShards(shards)
          .withStreamName(streamName));
  return result;
}
 
Example #17
Source File: V1DynamoDbAttributeValue.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Benchmark
public Object getItem(GetItemState s) {
    HttpResponse resp = new HttpResponse(null, null);
    resp.setContent(new ByteArrayInputStream(s.testItem.utf8()));
    try {
        return getItemJsonResponseHandler().handle(resp);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #18
Source File: TracingHandler.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
private HashMap<String, Object> extractHttpResponseInformation(HttpResponse httpResponse) {
    HashMap<String, Object> ret = new HashMap<>();
    HashMap<String, Object> response = new HashMap<>();

    response.put(EntityDataKeys.HTTP.STATUS_CODE_KEY, httpResponse.getStatusCode());
    try {
        if (null != httpResponse.getHeaders().get(EntityHeaderKeys.HTTP.CONTENT_LENGTH_HEADER)) {
            response.put(EntityDataKeys.HTTP.CONTENT_LENGTH_KEY,
                         Long.parseLong(httpResponse.getHeaders().get(EntityHeaderKeys.HTTP.CONTENT_LENGTH_HEADER)));
        }
    } catch (NumberFormatException nfe) {
        logger.warn("Unable to parse Content-Length header.", nfe);
    }

    ret.put(EntityDataKeys.HTTP.RESPONSE_KEY, response);
    return ret;
}
 
Example #19
Source File: StreamResponseHandler.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
    AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>();
    T result = responseUnmarshaller.unmarshall(response);
    awsResponse.setResult(result);
    return awsResponse;
}
 
Example #20
Source File: GenericApiGatewayResponse.java    From apigateway-generic-java-sdk with Apache License 2.0 5 votes vote down vote up
public GenericApiGatewayResponse(HttpResponse httpResponse) throws IOException {
    this.httpResponse = httpResponse;
    if (httpResponse.getContent()!= null) {
        this.body = IOUtils.toString(httpResponse.getContent());
    } else {
        this.body = null;
    }
}
 
Example #21
Source File: MemoryOverwritingRequestHandlerTest.java    From fernet-java8 with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyAfterErrorClearsSecret() {
    // given
    final ByteBuffer secretBinary = ByteBuffer.wrap(new byte[] { 1, 1, 2, 3, 5, 8 });
    assertTrue(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8}));
    final PutSecretValueRequest originalRequest = new PutSecretValueRequest();
    originalRequest.setSecretBinary(secretBinary);
    final Request<PutSecretValueRequest> request = new DefaultRequest<PutSecretValueRequest>(originalRequest,
            "AWSSecretsManager");
    final PutSecretValueResult result = mock(PutSecretValueResult.class);
    final HttpResponse httpResponse = mock(HttpResponse.class);
    final Response<PutSecretValueResult> response = new Response<PutSecretValueResult>(result, httpResponse);

    // when
    handler.afterError(request, response, new Exception());

    // then
    assertFalse(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8}));
}
 
Example #22
Source File: MemoryOverwritingRequestHandlerTest.java    From fernet-java8 with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyAfterResponseClearsSecret() {
    // given
    final ByteBuffer secretBinary = ByteBuffer.wrap(new byte[] { 1, 1, 2, 3, 5, 8 });
    assertTrue(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8}));
    final PutSecretValueRequest originalRequest = new PutSecretValueRequest();
    originalRequest.setSecretBinary(secretBinary);
    final Request<PutSecretValueRequest> request = new DefaultRequest<PutSecretValueRequest>(originalRequest,
            "AWSSecretsManager");
    final PutSecretValueResult result = mock(PutSecretValueResult.class);
    final HttpResponse httpResponse = mock(HttpResponse.class);
    final Response<PutSecretValueResult> response = new Response<PutSecretValueResult>(result, httpResponse);

    // when
    handler.afterResponse(request, response);

    // then
    assertFalse(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8}));
}
 
Example #23
Source File: GenericApiGatewayResponse.java    From nifi with Apache License 2.0 5 votes vote down vote up
public GenericApiGatewayResponse(HttpResponse httpResponse) throws IOException {
    this.httpResponse = httpResponse;
    if(httpResponse.getContent() != null) {
        this.body = IOUtils.toString(httpResponse.getContent());
    }else {
        this.body = null;
    }
}
 
Example #24
Source File: ErrorResponseHandler.java    From getting-started with MIT License 5 votes vote down vote up
@Override
public AmazonServiceException handle(final HttpResponse response) {
  final AmazonServiceException ase = new AmazonServiceException(response.getStatusText());
  ase.setStatusCode(response.getStatusCode());
  try {
    final String content = IOUtils.toString(response.getContent()).trim();
    ase.setRawResponseContent(content);
  } catch (IOException exception) {
    System.err.println("Exception thrown while reading the response's content: " + exception);
  }

  return ase;
}
 
Example #25
Source File: GenericApiGatewayResponse.java    From nifi with Apache License 2.0 4 votes vote down vote up
public HttpResponse getHttpResponse() {
    return httpResponse;
}
 
Example #26
Source File: StreamResponseHandler.java    From ivona-speechcloud-sdk-java with Apache License 2.0 4 votes vote down vote up
public StreamResponseHandler(Unmarshaller<T, HttpResponse> responseUnmarshaller) {
    this.responseUnmarshaller = responseUnmarshaller;
}
 
Example #27
Source File: SimpleAwsErrorHandler.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public AmazonServiceException handle(HttpResponse response) {
    AmazonServiceException ase = new AmazonServiceException(response.getStatusText());
    ase.setStatusCode(response.getStatusCode());
    return ase;
}
 
Example #28
Source File: AwsCodersTest.java    From beam with Apache License 2.0 4 votes vote down vote up
private SdkHttpMetadata buildSdkHttpMetadata() {
  HttpResponse httpResponse = new HttpResponse(null, null);
  httpResponse.setStatusCode(200);
  httpResponse.addHeader("Content-Type", "application/json");
  return SdkHttpMetadata.from(httpResponse);
}
 
Example #29
Source File: AWSAppAutoScalingClientTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Test
public void deleteScalableTargetIsIdempotent() {
    String jobId = UUID.randomUUID().toString();
    String policyId = UUID.randomUUID().toString();

    AWSApplicationAutoScalingAsync clientAsync = mock(AWSApplicationAutoScalingAsync.class);
    AWSAppScalingConfig config = mock(AWSAppScalingConfig.class);
    AWSAppAutoScalingClient autoScalingClient = new AWSAppAutoScalingClient(clientAsync, config, new NoopRegistry());

    AtomicBoolean isDeleted = new AtomicBoolean(false);
    when(clientAsync.deregisterScalableTargetAsync(any(), any())).thenAnswer(invocation -> {
        DeregisterScalableTargetRequest request = invocation.getArgument(0);
        AsyncHandler<DeregisterScalableTargetRequest, DeregisterScalableTargetResult> handler = invocation.getArgument(1);
        if (isDeleted.get()) {
            ObjectNotFoundException notFoundException = new ObjectNotFoundException(policyId + " does not exist");
            handler.onError(notFoundException);
            return Future.failed(notFoundException);
        }

        DeregisterScalableTargetResult resultSuccess = new DeregisterScalableTargetResult();
        HttpResponse successResponse = new HttpResponse(null, null);
        successResponse.setStatusCode(200);
        resultSuccess.setSdkHttpMetadata(SdkHttpMetadata.from(successResponse));

        isDeleted.set(true);
        handler.onSuccess(request, resultSuccess);
        return Future.successful(resultSuccess);
    });

    AssertableSubscriber<Void> firstCall = autoScalingClient.deleteScalableTarget(jobId).test();
    firstCall.awaitTerminalEvent(2, TimeUnit.SECONDS);
    firstCall.assertNoErrors();
    firstCall.assertCompleted();
    verify(clientAsync, times(1)).deregisterScalableTargetAsync(any(), any());

    // second should complete fast when NotFound and not retry with exponential backoff
    AssertableSubscriber<Void> secondCall = autoScalingClient.deleteScalableTarget(jobId).test();
    secondCall.awaitTerminalEvent(2, TimeUnit.SECONDS);
    secondCall.assertNoErrors();
    secondCall.assertCompleted();
    verify(clientAsync, times(2)).deregisterScalableTargetAsync(any(), any());
}
 
Example #30
Source File: AWSAppAutoScalingClientTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Test
public void deleteScalingPolicyIsIdempotent() {
    String jobId = UUID.randomUUID().toString();
    String policyId = UUID.randomUUID().toString();

    AWSApplicationAutoScalingAsync clientAsync = mock(AWSApplicationAutoScalingAsync.class);
    AWSAppScalingConfig config = mock(AWSAppScalingConfig.class);
    AWSAppAutoScalingClient autoScalingClient = new AWSAppAutoScalingClient(clientAsync, config, new NoopRegistry());

    // delete happens successfully on the first attempt
    AtomicBoolean isDeleted = new AtomicBoolean(false);
    when(clientAsync.deleteScalingPolicyAsync(any(), any())).thenAnswer(invocation -> {
        DeleteScalingPolicyRequest request = invocation.getArgument(0);
        AsyncHandler<DeleteScalingPolicyRequest, DeleteScalingPolicyResult> handler = invocation.getArgument(1);

        if (isDeleted.get()) {
            ObjectNotFoundException notFoundException = new ObjectNotFoundException(policyId + " does not exist");
            handler.onError(notFoundException);
            return Future.failed(notFoundException);
        }

        DeleteScalingPolicyResult resultSuccess = new DeleteScalingPolicyResult();
        HttpResponse successResponse = new HttpResponse(null, null);
        successResponse.setStatusCode(200);
        resultSuccess.setSdkHttpMetadata(SdkHttpMetadata.from(successResponse));

        isDeleted.set(true);
        handler.onSuccess(request, resultSuccess);
        return Future.successful(resultSuccess);
    });

    AssertableSubscriber<Void> firstCall = autoScalingClient.deleteScalingPolicy(policyId, jobId).test();
    firstCall.awaitTerminalEvent(2, TimeUnit.SECONDS);
    firstCall.assertNoErrors();
    firstCall.assertCompleted();
    verify(clientAsync, times(1)).deleteScalingPolicyAsync(any(), any());

    // second should complete fast when NotFound and not retry with exponential backoff
    AssertableSubscriber<Void> secondCall = autoScalingClient.deleteScalingPolicy(policyId, jobId).test();
    secondCall.awaitTerminalEvent(2, TimeUnit.SECONDS);
    secondCall.assertNoErrors();
    secondCall.assertCompleted();
    verify(clientAsync, times(2)).deleteScalingPolicyAsync(any(), any());
}