Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,14 @@ private <T> CompletableFuture<SendResult.Batch<T>> wrapSendException(Collection<
}

private <T> CompletableFuture<SendResult.Batch<T>> handleFailedSendBatch(String endpoint,
SendResult.Batch<T> result) {
return CompletableFuture.failedFuture(new SendBatchOperationFailedException("", endpoint, result));
SendResult.Batch<T> result) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not use spaces to align, you can run mvn spotless:apply to fix this.

return CompletableFuture.failedFuture(new SendBatchOperationFailedException(
"Batch send operation failed for %d of %d messages to endpoint %s. Failed message IDs: %s. Errors: %s"
.formatted(result.failed().size(),
result.failed().size() + result.successful().size(), endpoint,
MessageHeaderUtils.getId(result.failed().stream().map(SendResult.Failed::message).toList()),
result.failed().stream().map(SendResult.Failed::errorMessage)
.collect(Collectors.joining("; "))), endpoint, result));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern here would be that we already use ; to join the ids in MessageHeaderUtils.getId().

How about we pair the ids with the corresponding error message instead?

Also, let's guard against a possibly null message.

}

private <T> Collection<S> convertMessagesToSend(Collection<Message<T>> messages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,37 @@ void shouldThrowIfHasFailedMessagesInBatchByDefault() {
});
}

@Test
void shouldIncludeFailureDetailsInBatchExceptionMessage() {
String queue = "test-queue";
Message<String> message1 = MessageBuilder.withPayload("test-payload-1").build();
Message<String> message2 = MessageBuilder.withPayload("test-payload-2").build();

GetQueueUrlResponse urlResponse = GetQueueUrlResponse.builder().queueUrl(queue).build();
given(mockClient.getQueueUrl(any(GetQueueUrlRequest.class)))
.willReturn(CompletableFuture.completedFuture(urlResponse));
mockQueueAttributes(mockClient, Map.of());
SendMessageBatchResponse response = SendMessageBatchResponse.builder()
.successful(builder -> builder.id(message1.getHeaders().getId().toString())
.messageId(UUID.randomUUID().toString()))
.failed(builder -> builder.id(message2.getHeaders().getId().toString()).message("send failed")
.code("BC01").senderFault(true))
.build();
given(mockClient.sendMessageBatch(any(SendMessageBatchRequest.class)))
.willReturn(CompletableFuture.completedFuture(response));

SqsOperations template = SqsTemplate.newSyncTemplate(mockClient);
assertThatThrownBy(() -> template.sendMany(queue, List.of(message1, message2)))
.isInstanceOf(SendBatchOperationFailedException.class)
.isInstanceOfSatisfying(SendBatchOperationFailedException.class, ex -> {
assertThat(ex.getMessage())
.contains("1 of 2")
.contains(queue)
.contains(message2.getHeaders().getId().toString())
.contains("send failed");
});
}

@Test
void shouldCreateByDefaultIfQueueNotFound() {
String queue = "test-queue";
Expand Down
Loading