Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix formatting #1295

Merged
merged 1 commit into from
Dec 14, 2024
Merged
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 @@ -20,9 +20,6 @@
import static org.assertj.core.api.Assertions.assertThatNoException;

import com.fasterxml.jackson.databind.ObjectMapper;

import net.bytebuddy.utility.RandomString;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -32,6 +29,7 @@
import java.time.Duration;
import java.util.Base64;
import java.util.List;
import net.bytebuddy.utility.RandomString;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
Expand Down Expand Up @@ -342,7 +340,8 @@ private String calculateContentMD5(String content) {
byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
byte[] mdBytes = md.digest(contentBytes);
return Base64.getEncoder().encodeToString(mdBytes);
} catch (Exception exception) {
}
catch (Exception exception) {
throw new RuntimeException("Failed to calculate Content-MD5", exception);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,11 @@ private Integer getDelaySeconds(Message message) {
private Map<MessageSystemAttributeNameForSends, MessageSystemAttributeValue> mapMessageSystemAttributes(
Message message) {
return message.attributes().entrySet().stream().filter(Predicate.not(entry -> isSkipAttribute(entry.getKey())))
.collect(Collectors.toMap(entry -> MessageSystemAttributeNameForSends.fromValue(entry.getKey().toString()),
entry -> MessageSystemAttributeValue.builder().dataType(MessageAttributeDataTypes.STRING)
.stringValue(entry.getValue()).build()));
.collect(Collectors
.toMap(entry -> MessageSystemAttributeNameForSends.fromValue(entry.getKey().toString()),
entry -> MessageSystemAttributeValue.builder()
.dataType(MessageAttributeDataTypes.STRING).stringValue(entry.getValue())
.build()));
}

private boolean isSkipAttribute(MessageSystemAttributeName name) {
Expand Down Expand Up @@ -605,7 +607,7 @@ private ReceiveMessageRequest doCreateReceiveMessageRequest(Duration pollTimeout
.waitTimeSeconds(toInt(pollTimeout.toSeconds()));
if (additionalHeaders.containsKey(SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER)) {
builder.visibilityTimeout(
toInt(getValueAs(additionalHeaders, SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER, Duration.class)
toInt(getValueAs(additionalHeaders, SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER, Duration.class)
.toSeconds()));
}
if (additionalHeaders.containsKey(SqsHeaders.SQS_RECEIVE_REQUEST_ATTEMPT_ID_HEADER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ private Object fromGenericMessages(List<GenericMessage<?>> messages, Class<?> ta
Type resolvedType = getResolvedType(targetClass, conversionHint);
Class<?> resolvedClazz = ResolvableType.forType(resolvedType).resolve();

Object hint = targetClass.isAssignableFrom(List.class) &&
conversionHint instanceof MethodParameter mp ? mp.nested() : conversionHint;
Object hint = targetClass.isAssignableFrom(List.class) && conversionHint instanceof MethodParameter mp
? mp.nested()
: conversionHint;

return messages.stream().map(message -> fromGenericMessage(message, resolvedClazz, hint)).toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Message fromHeaders(MessageHeaders headers) {
}
if (headers.containsKey(SqsHeaders.MessageSystemAttributes.SQS_AWS_TRACE_HEADER)) {
attributes.put(MessageSystemAttributeName.AWS_TRACE_HEADER,
headers.get(SqsHeaders.MessageSystemAttributes.SQS_AWS_TRACE_HEADER, String.class));
headers.get(SqsHeaders.MessageSystemAttributes.SQS_AWS_TRACE_HEADER, String.class));
}
Map<String, MessageAttributeValue> messageAttributes = headers.entrySet().stream()
.filter(entry -> !isSkipHeader(entry.getKey())).collect(Collectors.toMap(Map.Entry::getKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1196,19 +1196,16 @@ void shouldPropagateTracingAsMessageSystemAttribute() {
String queue = "test-queue";
GetQueueUrlResponse urlResponse = GetQueueUrlResponse.builder().queueUrl(queue).build();
given(mockClient.getQueueUrl(any(GetQueueUrlRequest.class)))
.willReturn(CompletableFuture.completedFuture(urlResponse));
.willReturn(CompletableFuture.completedFuture(urlResponse));
mockQueueAttributes(mockClient, Map.of());
SendMessageResponse response = SendMessageResponse.builder().messageId(UUID.randomUUID().toString())
.sequenceNumber("123").build();
.sequenceNumber("123").build();
given(mockClient.sendMessage(any(SendMessageRequest.class)))
.willReturn(CompletableFuture.completedFuture(response));
.willReturn(CompletableFuture.completedFuture(response));

SqsOperations sqsOperations = SqsTemplate.newSyncTemplate(mockClient);
SendResult<Object> result = sqsOperations.send(options -> options
.queue(queue)
.header(SqsHeaders.MessageSystemAttributes.SQS_AWS_TRACE_HEADER, "abc")
.payload("test")
);
SendResult<Object> result = sqsOperations.send(options -> options.queue(queue)
.header(SqsHeaders.MessageSystemAttributes.SQS_AWS_TRACE_HEADER, "abc").payload("test"));

assertThat(result).isNotNull();

Expand All @@ -1217,9 +1214,8 @@ void shouldPropagateTracingAsMessageSystemAttribute() {
SendMessageRequest sendMessageRequest = captor.getValue();

assertThat(sendMessageRequest.messageSystemAttributes()).hasEntrySatisfying(
MessageSystemAttributeNameForSends.AWS_TRACE_HEADER,
value -> assertThat(value.stringValue()).isEqualTo("abc")
);
MessageSystemAttributeNameForSends.AWS_TRACE_HEADER,
value -> assertThat(value.stringValue()).isEqualTo("abc"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@

import static org.assertj.core.api.Assertions.assertThat;

import io.awspring.cloud.sqs.listener.SqsHeaders;
import java.math.BigDecimal;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Stream;

import io.awspring.cloud.sqs.listener.SqsHeaders;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -145,31 +144,25 @@ void shouldAddNumberMessageAttributes() {
@Test
void shouldCreateMessageWithSystemAttributesFromHeaders() {
MessageHeaders headers = new MessageHeaders(
Map.of(
SqsHeaders.MessageSystemAttributes.SQS_MESSAGE_GROUP_ID_HEADER, "value1",
SqsHeaders.MessageSystemAttributes.SQS_MESSAGE_DEDUPLICATION_ID_HEADER, "value2",
SqsHeaders.MessageSystemAttributes.SQS_AWS_TRACE_HEADER, "value3",
"customHeaderString", "customValueString",
"customHeaderNumber", 42
)
);
Map.of(SqsHeaders.MessageSystemAttributes.SQS_MESSAGE_GROUP_ID_HEADER, "value1",
SqsHeaders.MessageSystemAttributes.SQS_MESSAGE_DEDUPLICATION_ID_HEADER, "value2",
SqsHeaders.MessageSystemAttributes.SQS_AWS_TRACE_HEADER, "value3", "customHeaderString",
"customValueString", "customHeaderNumber", 42));

SqsHeaderMapper mapper = new SqsHeaderMapper();
Message message = mapper.fromHeaders(headers);

assertThat(message.attributes())
.hasSize(3)
.containsExactlyInAnyOrderEntriesOf(Map.of(
MessageSystemAttributeName.MESSAGE_GROUP_ID, "value1",
MessageSystemAttributeName.MESSAGE_DEDUPLICATION_ID, "value2",
MessageSystemAttributeName.AWS_TRACE_HEADER, "value3"
));
assertThat(message.messageAttributes())
.hasSize(2)
.containsExactlyInAnyOrderEntriesOf(Map.of(
"customHeaderString", MessageAttributeValue.builder().dataType(MessageAttributeDataTypes.STRING).stringValue("customValueString").build(),
"customHeaderNumber", MessageAttributeValue.builder().dataType(MessageAttributeDataTypes.NUMBER + ".java.lang.Integer").stringValue("42").build()
));
assertThat(message.attributes()).hasSize(3)
.containsExactlyInAnyOrderEntriesOf(Map.of(MessageSystemAttributeName.MESSAGE_GROUP_ID, "value1",
MessageSystemAttributeName.MESSAGE_DEDUPLICATION_ID, "value2",
MessageSystemAttributeName.AWS_TRACE_HEADER, "value3"));
assertThat(message.messageAttributes()).hasSize(2)
.containsExactlyInAnyOrderEntriesOf(Map.of("customHeaderString", MessageAttributeValue.builder()
.dataType(MessageAttributeDataTypes.STRING).stringValue("customValueString").build(),
"customHeaderNumber",
MessageAttributeValue.builder()
.dataType(MessageAttributeDataTypes.NUMBER + ".java.lang.Integer").stringValue("42")
.build()));
}

@ParameterizedTest
Expand Down
Loading