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

ci: Build with Java 17 #590

Merged
merged 1 commit into from
Oct 22, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
max-parallel: 4
matrix:
# test against latest update of each major Java version, as well as specific updates of LTS versions:
java: [8, 8.0.192, 11.0.x, 11.0.3, 12, 13, 15, 16 ]
java: [8, 8.0.192, 11.0.x, 11.0.3, 12, 13, 15, 16, 17 ]
name: Java ${{ matrix.java }}
env:
OS: ${{ matrix.os }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import software.amazon.lambda.powertools.sqs.SqsMessageHandler;

import static com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;
import static software.amazon.lambda.powertools.sqs.internal.SqsMessageBatchProcessorAspectTest.mockedRandom;
import static software.amazon.lambda.powertools.sqs.internal.SqsMessageBatchProcessorAspectTest.interactionClient;

public class PartialBatchFailureSuppressedHandler implements RequestHandler<SQSEvent, String> {
@Override
Expand All @@ -25,7 +25,7 @@ public String process(SQSMessage message) {
throw new RuntimeException("2e1424d4-f796-459a-8184-9c92662be6da");
}

mockedRandom.nextInt();
interactionClient.listQueues();
return "Success";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import software.amazon.lambda.powertools.sqs.SqsMessageHandler;

import static com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;
import static software.amazon.lambda.powertools.sqs.internal.SqsMessageBatchProcessorAspectTest.mockedRandom;
import static software.amazon.lambda.powertools.sqs.internal.SqsMessageBatchProcessorAspectTest.interactionClient;

public class PartialBatchPartialFailureHandler implements RequestHandler<SQSEvent, String> {
@Override
Expand All @@ -25,7 +25,7 @@ public String process(SQSMessage message) {
throw new RuntimeException("2e1424d4-f796-459a-8184-9c92662be6da");
}

mockedRandom.nextInt();
interactionClient.listQueues();
return "Success";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import software.amazon.lambda.powertools.sqs.SqsMessageHandler;

import static com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;
import static software.amazon.lambda.powertools.sqs.internal.SqsMessageBatchProcessorAspectTest.mockedRandom;
import static software.amazon.lambda.powertools.sqs.internal.SqsMessageBatchProcessorAspectTest.interactionClient;

public class PartialBatchSuccessHandler implements RequestHandler<SQSEvent, String> {
@Override
Expand All @@ -21,7 +21,7 @@ private class InnerMessageHandler implements SqsMessageHandler<Object> {

@Override
public String process(SQSMessage message) {
mockedRandom.nextInt();
interactionClient.listQueues();
return "Success";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import software.amazon.lambda.powertools.sqs.SqsMessageHandler;

import static com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;
import static software.amazon.lambda.powertools.sqs.internal.SqsMessageBatchProcessorAspectTest.mockedRandom;
import static software.amazon.lambda.powertools.sqs.internal.SqsMessageBatchProcessorAspectTest.interactionClient;

public class SqsMessageHandlerWithNonRetryableHandler implements RequestHandler<SQSEvent, String> {

Expand All @@ -30,7 +30,7 @@ public String process(SQSMessage message) {
throw new RuntimeException("Invalid message and should be reprocessed");
}

mockedRandom.nextInt();
interactionClient.listQueues();
return "Success";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import software.amazon.lambda.powertools.sqs.SqsMessageHandler;

import static com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;
import static software.amazon.lambda.powertools.sqs.internal.SqsMessageBatchProcessorAspectTest.mockedRandom;
import static software.amazon.lambda.powertools.sqs.internal.SqsMessageBatchProcessorAspectTest.interactionClient;

public class SqsMessageHandlerWithNonRetryableHandlerWithDelete implements RequestHandler<SQSEvent, String> {

Expand All @@ -32,7 +32,7 @@ public String process(SQSMessage message) {
throw new RuntimeException("Invalid message and should be reprocessed");
}

mockedRandom.nextInt();
interactionClient.listQueues();
return "Success";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package software.amazon.lambda.powertools.sqs.internal;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Random;
import java.util.function.Consumer;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
Expand All @@ -28,6 +29,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.in;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
Expand All @@ -39,7 +41,7 @@
import static software.amazon.lambda.powertools.sqs.SqsUtils.overrideSqsClient;

public class SqsMessageBatchProcessorAspectTest {
public static final Random mockedRandom = mock(Random.class);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mocking Random was causing some weird conflicts with Mockito and java 17.

public static final SqsClient interactionClient = mock(SqsClient.class);
private static final SqsClient sqsClient = mock(SqsClient.class);
private static final ObjectMapper MAPPER = new ObjectMapper();

Expand All @@ -51,7 +53,7 @@ public class SqsMessageBatchProcessorAspectTest {
@BeforeEach
void setUp() throws IOException {
overrideSqsClient(sqsClient);
reset(mockedRandom);
reset(interactionClient);
reset(sqsClient);
setupContext();
event = MAPPER.readValue(this.getClass().getResource("/sampleSqsBatchEvent.json"), SQSEvent.class);
Expand All @@ -62,7 +64,7 @@ void setUp() throws IOException {
void shouldBatchProcessAllMessageSuccessfullyAndNotDeleteFromSQS() {
requestHandler.handleRequest(event, context);

verify(mockedRandom, times(2)).nextInt();
verify(interactionClient, times(2)).listQueues();
verify(sqsClient, times(0)).deleteMessageBatch(any(DeleteMessageBatchRequest.class));
}

Expand All @@ -75,7 +77,7 @@ void shouldBatchProcessMessageWithSuccessDeletedOnFailureInBatchFromSQS() {
.satisfies(e -> {
assertThat(e.getExceptions())
.hasSize(1)
.extracting("detailMessage")
.extracting("message")
.containsExactly("2e1424d4-f796-459a-8184-9c92662be6da");

assertThat(e.getFailures())
Expand All @@ -88,7 +90,7 @@ void shouldBatchProcessMessageWithSuccessDeletedOnFailureInBatchFromSQS() {
.contains("Success");
});

verify(mockedRandom).nextInt();
verify(interactionClient).listQueues();
verify(sqsClient).deleteMessageBatch(any(DeleteMessageBatchRequest.class));
}

Expand All @@ -98,7 +100,7 @@ void shouldBatchProcessMessageWithSuccessDeletedOnFailureWithSuppressionInBatchF

requestHandler.handleRequest(event, context);

verify(mockedRandom).nextInt();
verify(interactionClient).listQueues();
verify(sqsClient).deleteMessageBatch(any(DeleteMessageBatchRequest.class));
}

Expand Down Expand Up @@ -129,7 +131,7 @@ void shouldBatchProcessAndMoveNonRetryableExceptionToDlq() {

requestHandler.handleRequest(event, context);

verify(mockedRandom).nextInt();
verify(interactionClient).listQueues();
verify(sqsClient).deleteMessageBatch(any(DeleteMessageBatchRequest.class));
verify(sqsClient).sendMessageBatch(any(Consumer.class));
}
Expand All @@ -141,7 +143,7 @@ void shouldBatchProcessAndDeleteNonRetryableExceptionMessage() {

requestHandler.handleRequest(event, context);

verify(mockedRandom).nextInt();
verify(interactionClient).listQueues();
ArgumentCaptor<DeleteMessageBatchRequest> captor = ArgumentCaptor.forClass(DeleteMessageBatchRequest.class);
verify(sqsClient).deleteMessageBatch(captor.capture());
verify(sqsClient, never()).sendMessageBatch(any(Consumer.class));
Expand Down Expand Up @@ -169,7 +171,7 @@ void shouldBatchProcessAndFailWithExceptionForNonRetryableExceptionAndNoDlq() {
.satisfies(e -> {
assertThat(e.getExceptions())
.hasSize(1)
.extracting("detailMessage")
.extracting("message")
.containsExactly("Invalid message and was moved to DLQ");

assertThat(e.getFailures())
Expand All @@ -182,7 +184,7 @@ void shouldBatchProcessAndFailWithExceptionForNonRetryableExceptionAndNoDlq() {
.contains("Success");
});

verify(mockedRandom).nextInt();
verify(interactionClient).listQueues();
verify(sqsClient).deleteMessageBatch(any(DeleteMessageBatchRequest.class));
verify(sqsClient, never()).sendMessageBatch(any(Consumer.class));
}
Expand All @@ -206,7 +208,7 @@ void shouldBatchProcessAndFailWithExceptionForNonRetryableExceptionWhenFailedPar
.satisfies(e -> {
assertThat(e.getExceptions())
.hasSize(1)
.extracting("detailMessage")
.extracting("message")
.containsExactly("Invalid message and was moved to DLQ");

assertThat(e.getFailures())
Expand All @@ -219,7 +221,7 @@ void shouldBatchProcessAndFailWithExceptionForNonRetryableExceptionWhenFailedPar
.contains("Success");
});

verify(mockedRandom).nextInt();
verify(interactionClient).listQueues();
verify(sqsClient).deleteMessageBatch(any(DeleteMessageBatchRequest.class));
verify(sqsClient, never()).sendMessageBatch(any(Consumer.class));
}
Expand Down Expand Up @@ -247,7 +249,7 @@ void shouldBatchProcessAndMoveNonRetryableExceptionToDlqAndThrowException() thro
.satisfies(e -> {
assertThat(e.getExceptions())
.hasSize(1)
.extracting("detailMessage")
.extracting("message")
.containsExactly("Invalid message and should be reprocessed");

assertThat(e.getFailures())
Expand All @@ -260,7 +262,7 @@ void shouldBatchProcessAndMoveNonRetryableExceptionToDlqAndThrowException() thro
.contains("Success");
});

verify(mockedRandom).nextInt();
verify(interactionClient).listQueues();
verify(sqsClient).deleteMessageBatch(any(DeleteMessageBatchRequest.class));
verify(sqsClient).sendMessageBatch(any(Consumer.class));
}
Expand Down