@Test public void testConsumeCompletionWithReceiveFailure() { urlSetup("receiveFailure", "receiveFailureUrl"); CompletableFuture<ReceiveMessageResponse> receiveMessage = new CompletableFuture<>(); receiveMessage.completeExceptionally(new Exception()); ReceiveMessageRequest testRequest = ReceiveMessageRequest.builder() .queueUrl("receiveFailureUrl") .maxNumberOfMessages(1) .waitTimeSeconds(AsyncSqsClientConfiguration.DEFAULT_RECEIVE_WAIT_SECONDS) .build(); when(awsAsyncSqsClient.receiveMessage(testRequest)).thenReturn(receiveMessage); Consumer<String> function = System.out::println; CompletableFuture<Boolean> result = asyncClient.consume(function, "receiveFailure"); try { result.get(1000, TimeUnit.MICROSECONDS); } catch (TimeoutException timeout) { fail("Future does not seem to complete when failure in receiveMessage."); } catch (Exception ex) { } urlFailureSetup("receiveFailure"); result = asyncClient.consume(function, "receiveFailure"); try { result.get(1000, TimeUnit.MILLISECONDS); } catch (TimeoutException timeout) { fail("Future does not seem to complete when failure in getQueueUrl within receiveMessage."); } catch (Exception ex) { } }
@Override public CompletableFuture<Boolean> consume( @NonNull final Consumer<String> consumer, @NonNull final String queueName) { return consumeInternal( (body, executor) -> CompletableFuture.runAsync(() -> consumer.accept(body), executor), queueName); }
AsyncSqsClientImpl implements AsyncSqsClient { @Override public CompletableFuture<Boolean> consume( @NonNull final Consumer<String> consumer, @NonNull final String queueName) { return consumeInternal( (body, executor) -> CompletableFuture.runAsync(() -> consumer.accept(body), executor), queueName); } }
AsyncSqsClientImpl implements AsyncSqsClient { @Override public CompletableFuture<Boolean> consume( @NonNull final Consumer<String> consumer, @NonNull final String queueName) { return consumeInternal( (body, executor) -> CompletableFuture.runAsync(() -> consumer.accept(body), executor), queueName); } @Inject  AsyncSqsClientImpl(
      @NonNull final SqsAsyncClient client,
      @NonNull final AsyncConveyorMetrics metrics,
      @NonNull final ExecutorService executor);   AsyncSqsClientImpl(
      @NonNull final SqsAsyncClient client,
      @NonNull final AsyncConveyorMetrics metrics,
      @NonNull final ExecutorService executor,
      long maxCacheSize,
      int receiveWaitTimeoutSeconds,
      int bulkheadMaxWaitMillis,
      int consumerConcurrency); }
AsyncSqsClientImpl implements AsyncSqsClient { @Override public CompletableFuture<Boolean> consume( @NonNull final Consumer<String> consumer, @NonNull final String queueName) { return consumeInternal( (body, executor) -> CompletableFuture.runAsync(() -> consumer.accept(body), executor), queueName); } @Inject  AsyncSqsClientImpl(
      @NonNull final SqsAsyncClient client,
      @NonNull final AsyncConveyorMetrics metrics,
      @NonNull final ExecutorService executor);   AsyncSqsClientImpl(
      @NonNull final SqsAsyncClient client,
      @NonNull final AsyncConveyorMetrics metrics,
      @NonNull final ExecutorService executor,
      long maxCacheSize,
      int receiveWaitTimeoutSeconds,
      int bulkheadMaxWaitMillis,
      int consumerConcurrency); @Override CompletableFuture<Void> add(
      @NonNull final String message, @NonNull final String queueName); @Override CompletableFuture<Void> add(
      @NonNull final String message, @NonNull final String queueName, int delaySeconds); @Override CompletableFuture<Boolean> consume(
      @NonNull final Consumer<String> consumer, @NonNull final String queueName); @Override CompletableFuture<Boolean> consume(AsyncConsumer<String> consumer, String queueName); @Override void close(); }
AsyncSqsClientImpl implements AsyncSqsClient { @Override public CompletableFuture<Boolean> consume( @NonNull final Consumer<String> consumer, @NonNull final String queueName) { return consumeInternal( (body, executor) -> CompletableFuture.runAsync(() -> consumer.accept(body), executor), queueName); } @Inject  AsyncSqsClientImpl(
      @NonNull final SqsAsyncClient client,
      @NonNull final AsyncConveyorMetrics metrics,
      @NonNull final ExecutorService executor);   AsyncSqsClientImpl(
      @NonNull final SqsAsyncClient client,
      @NonNull final AsyncConveyorMetrics metrics,
      @NonNull final ExecutorService executor,
      long maxCacheSize,
      int receiveWaitTimeoutSeconds,
      int bulkheadMaxWaitMillis,
      int consumerConcurrency); @Override CompletableFuture<Void> add(
      @NonNull final String message, @NonNull final String queueName); @Override CompletableFuture<Void> add(
      @NonNull final String message, @NonNull final String queueName, int delaySeconds); @Override CompletableFuture<Boolean> consume(
      @NonNull final Consumer<String> consumer, @NonNull final String queueName); @Override CompletableFuture<Boolean> consume(AsyncConsumer<String> consumer, String queueName); @Override void close();  }