Skip to content

Commit

Permalink
Fix formatting (#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejwalkowiak authored Dec 14, 2024
1 parent 18b1ea8 commit 99f961f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 45 deletions.
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

0 comments on commit 99f961f

Please sign in to comment.