Skip to content

Commit

Permalink
Formatting (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejwalkowiak committed Mar 3, 2024
1 parent e189ea5 commit 299ff1b
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ public SesClient sesClient(SesProperties properties, AwsClientBuilderConfigurer
@Bean
@ConditionalOnMissingClass("jakarta.mail.Session")
public MailSender simpleMailSender(SesClient sesClient, SesProperties properties) {
return new SimpleEmailServiceMailSender(sesClient, properties.getSourceArn(), properties.getConfigurationSetName());
return new SimpleEmailServiceMailSender(sesClient, properties.getSourceArn(),
properties.getConfigurationSetName());
}

@Bean
@ConditionalOnClass(name = "jakarta.mail.Session")
public JavaMailSender javaMailSender(SesClient sesClient, SesProperties properties) {
return new SimpleEmailServiceJavaMailSender(sesClient, properties.getSourceArn(), properties.getConfigurationSetName());
return new SimpleEmailServiceJavaMailSender(sesClient, properties.getSourceArn(),
properties.getConfigurationSetName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ void propertyIsNotResolvedWhenIntegrationIsDisabled() {
application.setWebApplicationType(WebApplicationType.NONE);

try (ConfigurableApplicationContext context = application.run(
"--spring.config.import=aws-secretsmanager:/config/spring;/config/second",
"--spring.cloud.aws.secretsmanager.enabled=false", "--spring.cloud.aws.credentials.secret-key=noop",
"--spring.cloud.aws.endpoint=" + localstack.getEndpoint(),
"--spring.cloud.aws.credentials.access-key=noop", "--spring.cloud.aws.credentials.secret-key=noop",
"--spring.cloud.aws.region.static=eu-west-1")) {
"--spring.config.import=aws-secretsmanager:/config/spring;/config/second",
"--spring.cloud.aws.secretsmanager.enabled=false", "--spring.cloud.aws.credentials.secret-key=noop",
"--spring.cloud.aws.endpoint=" + localstack.getEndpoint(),
"--spring.cloud.aws.credentials.access-key=noop", "--spring.cloud.aws.credentials.secret-key=noop",
"--spring.cloud.aws.region.static=eu-west-1")) {
assertThat(context.getEnvironment().getProperty("message")).isNull();
assertThat(context.getBeanProvider(SecretsManagerClient.class).getIfAvailable()).isNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public SimpleEmailServiceJavaMailSender(SesClient sesClient, @Nullable String so
this(sesClient, sourceArn, null);
}

public SimpleEmailServiceJavaMailSender(SesClient sesClient, @Nullable String sourceArn, @Nullable String configurationSetName) {
public SimpleEmailServiceJavaMailSender(SesClient sesClient, @Nullable String sourceArn,
@Nullable String configurationSetName) {
super(sesClient, sourceArn, configurationSetName);
}

Expand Down Expand Up @@ -211,8 +212,8 @@ public void send(MimeMessage... mimeMessages) throws MailException {
RawMessage rawMessage = createRawMessage(mimeMessage);

SendRawEmailResponse sendRawEmailResponse = getEmailService()
.sendRawEmail(SendRawEmailRequest.builder().sourceArn(getSourceArn())
.configurationSetName(getConfigurationSetName()).rawMessage(rawMessage).build());
.sendRawEmail(SendRawEmailRequest.builder().sourceArn(getSourceArn())
.configurationSetName(getConfigurationSetName()).rawMessage(rawMessage).build());

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Message with id: {} successfully sent", sendRawEmailResponse.messageId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public SimpleEmailServiceMailSender(SesClient sesClient, @Nullable String source
this(sesClient, sourceArn, null);
}

public SimpleEmailServiceMailSender(SesClient sesClient, @Nullable String sourceArn, @Nullable String configurationSetName) {
public SimpleEmailServiceMailSender(SesClient sesClient, @Nullable String sourceArn,
@Nullable String configurationSetName) {
this.sesClient = sesClient;
this.sourceArn = sourceArn;
this.configurationSetName = configurationSetName;
Expand Down Expand Up @@ -139,8 +140,8 @@ private SendEmailRequest prepareMessage(SimpleMailMessage simpleMailMessage) {
Message message = Message.builder().body(body).subject(subject).build();

SendEmailRequest.Builder emailRequestBuilder = SendEmailRequest.builder()
.destination(destinationBuilder.build()).source(simpleMailMessage.getFrom()).sourceArn(getSourceArn())
.configurationSetName(getConfigurationSetName()).message(message);
.destination(destinationBuilder.build()).source(simpleMailMessage.getFrom()).sourceArn(getSourceArn())
.configurationSetName(getConfigurationSetName()).message(message);

if (StringUtils.hasText(simpleMailMessage.getReplyTo())) {
emailRequestBuilder.replyToAddresses(simpleMailMessage.getReplyTo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void testSendMimeMessageWithConfigurationSetNameSet() throws MessagingException
JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(emailService, null, "Configuration Set");
ArgumentCaptor<SendRawEmailRequest> request = ArgumentCaptor.forClass(SendRawEmailRequest.class);
when(emailService.sendRawEmail(request.capture()))
.thenReturn(SendRawEmailResponse.builder().messageId("123").build());
.thenReturn(SendRawEmailResponse.builder().messageId("123").build());
MimeMessage mimeMessage = createMimeMessage();

mailSender.send(mimeMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ void testSendSimpleMailWithMinimalProperties() {
@Test
void testSendSimpleMailWithConfigurationSetNameSet() {
SesClient emailService = mock(SesClient.class);
SimpleEmailServiceMailSender mailSender = new SimpleEmailServiceMailSender(emailService,
null, "Configuration Set");
SimpleEmailServiceMailSender mailSender = new SimpleEmailServiceMailSender(emailService, null,
"Configuration Set");
SimpleMailMessage simpleMailMessage = createSimpleMailMessage();
ArgumentCaptor<SendEmailRequest> request = ArgumentCaptor.forClass(SendEmailRequest.class);
when(emailService.sendEmail(request.capture()))
.thenReturn(SendEmailResponse.builder().messageId("123").build());
.thenReturn(SendEmailResponse.builder().messageId("123").build());

mailSender.send(simpleMailMessage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void addMessageToBuffer(Message<T> polledMessage) {
this.context.lock();
try {
this.acksBuffer.computeIfAbsent(this.messageGroupingFunction.apply(polledMessage),
newGroup -> new LinkedBlockingQueue<>()).add(polledMessage);
newGroup -> new LinkedBlockingQueue<>()).add(polledMessage);
}
finally {
this.context.unlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ private void logAckResult(Collection<Message<T>> messagesToAck, Throwable t, Sto
watch.stop();
long totalTimeMillis = watch.getTotalTimeMillis();
if (totalTimeMillis > 10000) {
logger.warn("Acknowledgement operation took {}ms to finish in queue {} for messages {}",
totalTimeMillis, this.queueName, MessageHeaderUtils.getId(messagesToAck));
logger.warn("Acknowledgement operation took {}ms to finish in queue {} for messages {}", totalTimeMillis,
this.queueName, MessageHeaderUtils.getId(messagesToAck));
}
if (t != null) {
logger.error("Error acknowledging in queue {} messages {} in {}ms", this.queueName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ protected static CompletableFuture<?> createQueue(SqsAsyncClient client, String
if (purgeQueues) {
String queueUrl = v.queueUrl();
logger.debug("Purging queue {}", queueName);
return client.purgeQueue(req -> req.queueUrl(queueUrl).build())
.thenRun(() -> {
if (waitForPurge) {
logger.info("Waiting 30000 seconds to start sending.");
sleep(30000);
logger.info("Done waiting.");
}
});
return client.purgeQueue(req -> req.queueUrl(queueUrl).build()).thenRun(() -> {
if (waitForPurge) {
logger.info("Waiting 30000 seconds to start sending.");
sleep(30000);
logger.info("Done waiting.");
}
});
}
else {
logger.debug("Skipping purge for queue {}", queueName);
Expand All @@ -117,10 +116,11 @@ protected static CompletableFuture<?> createQueue(SqsAsyncClient client, String
});
}

private static void sleep(int time) {
private static void sleep(int time) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Interrupted while sleeping");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.springframework.core.task.TaskExecutor;
import org.springframework.retry.backoff.BackOffPolicy;
import org.springframework.retry.backoff.BackOffPolicyBuilder;

import software.amazon.awssdk.services.sqs.model.MessageSystemAttributeName;
import software.amazon.awssdk.services.sqs.model.QueueAttributeName;

Expand Down

0 comments on commit 299ff1b

Please sign in to comment.