Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae committed Sep 17, 2024
1 parent b95668f commit a237a19
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import gov.cms.ab2d.eventclient.messages.TraceAndAlertSQSMessage;
import gov.cms.ab2d.eventclient.messages.TraceSQSMessage;
import java.util.List;
import java.util.concurrent.ExecutionException;

import lombok.extern.slf4j.Slf4j;
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
Expand Down Expand Up @@ -110,17 +109,15 @@ public void sendMessage(SQSMessages message) {
GetQueueUrlRequest getQueueRequest = GetQueueUrlRequest.builder()
.queueName(queueName)
.build();

String queueUrl = amazonSQS.getQueueUrl(getQueueRequest).get().queueUrl();
String queueUrl = amazonSQS.getQueueUrl(getQueueRequest).join().queueUrl();
SendMessageRequest sendMessageRequest = SendMessageRequest.builder()
.queueUrl(queueUrl)
.messageBody(mapper.writeValueAsString(message))
.build();

amazonSQS.sendMessage(sendMessageRequest);

} catch (JsonProcessingException | UnsupportedOperationException | SqsException | InterruptedException |
ExecutionException e) {
} catch (JsonProcessingException | UnsupportedOperationException | SqsException e) {
log.info(e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
@JsonSubTypes.Type(value = TraceSQSMessage.class, name = "TraceSQSMessage"),
})
public abstract class SQSMessages {
public SQSMessages() { }
protected SQSMessages() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public class SendSqsEventTest {
private final ObjectMapper mapper = SQSConfig.objectMapper();

@Test
void testQueueUrl() throws ExecutionException, InterruptedException {
String url = amazonSQS.getQueueUrl(GetQueueUrlRequest.builder().queueName(LOCAL_EVENTS_SQS).build()).get().queueUrl();
void testQueueUrl() {
String url = amazonSQS.getQueueUrl(GetQueueUrlRequest.builder().queueName(LOCAL_EVENTS_SQS).build()).join().queueUrl();
assertTrue(url.contains(LOCAL_EVENTS_SQS));
}

@Test
void testSendMessages() throws JsonProcessingException, ExecutionException, InterruptedException {
void testSendMessages() throws JsonProcessingException {
SqsAsyncClient amazonSQSSpy = Mockito.spy(amazonSQS);
SQSEventClient sqsEventClient = new SQSEventClient(amazonSQSSpy, mapper, LOCAL_EVENTS_SQS);

Expand All @@ -71,15 +71,15 @@ void testSendMessages() throws JsonProcessingException, ExecutionException, Inte

Mockito.verify(amazonSQSSpy, timeout(1000).times(2)).sendMessage(any(SendMessageRequest.class));

List<Message> message1 = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).get().messages();
List<Message> message2 = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).get().messages();
List<Message> message1 = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).join().messages();
List<Message> message2 = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).join().messages();

assertTrue(message1.get(0).body().contains(mapper.writeValueAsString(sentApiRequestEvent)));
assertTrue(message2.get(0).body().contains(mapper.writeValueAsString(sentApiResponseEvent)));
}

@Test
void testSendMessagesDifferentQueue() throws JsonProcessingException, ExecutionException, InterruptedException {
void testSendMessagesDifferentQueue() throws JsonProcessingException {
amazonSQS.createQueue( CreateQueueRequest.builder()
.queueName("ab2d-dev-events-sqs")
.build());
Expand All @@ -95,15 +95,15 @@ void testSendMessagesDifferentQueue() throws JsonProcessingException, ExecutionE

Mockito.verify(amazonSQSSpy, timeout(1000).times(2)).sendMessage(any(SendMessageRequest.class));

List<Message> message1 = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(DEV_EVENTS_SQS).build()).get().messages();
List<Message> message2 = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(DEV_EVENTS_SQS).build()).get().messages();
List<Message> message1 = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(DEV_EVENTS_SQS).build()).join().messages();
List<Message> message2 = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(DEV_EVENTS_SQS).build()).join().messages();

assertTrue(message1.get(0).body().contains(mapper.writeValueAsString(sentApiRequestEvent)));
assertTrue(message2.get(0).body().contains(mapper.writeValueAsString(sentApiResponseEvent)));
}

@Test
void logWithSQS() throws ExecutionException, InterruptedException {
void logWithSQS() {
SqsAsyncClient amazonSQSSpy = Mockito.spy(amazonSQS);
SQSEventClient sqsEventClient = new SQSEventClient(amazonSQSSpy, mapper, LOCAL_EVENTS_SQS);

Expand All @@ -122,25 +122,25 @@ void logWithSQS() throws ExecutionException, InterruptedException {

Mockito.verify(amazonSQSSpy, timeout(1000).times(7)).sendMessage(any(SendMessageRequest.class));

List<Message> message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).get().messages();
List<Message> message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).join().messages();
assertTrue(message.get(0).body().contains("GeneralSQSMessage"));

message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).get().messages();
message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).join().messages();
assertTrue(message.get(0).body().contains("TraceSQSMessage"));

message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).get().messages();
message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).join().messages();
assertTrue(message.get(0).body().contains("AlertSQSMessage"));

message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).get().messages();
message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).join().messages();
assertTrue(message.get(0).body().contains("SlackSQSMessage"));

message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).get().messages();
message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).join().messages();
assertTrue(message.get(0).body().contains("KinesisSQSMessage"));

message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).get().messages();
message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).join().messages();
assertTrue(message.get(0).body().contains("TraceAndAlertSQSMessage"));

message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).get().messages();
message = amazonSQS.receiveMessage(ReceiveMessageRequest.builder().queueUrl(LOCAL_EVENTS_SQS).build()).join().messages();
assertTrue(message.get(0).body().contains("LogAndTraceSQSMessage"));
}

Expand Down

0 comments on commit a237a19

Please sign in to comment.