-
Notifications
You must be signed in to change notification settings - Fork 90
feat: end-to-end tests for core modules and idempotency #970
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
Merged
jeromevdl
merged 14 commits into
aws-powertools:master
from
jeromevdl:feat/integration-tests
Mar 21, 2023
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6cef3eb
add e2e tests for logging
jeromevdl 0d60b9d
add e2e tests for metrics
jeromevdl 40c8bc4
add e2e tests for idempotency
jeromevdl 5a79635
add e2e tests for tracing
jeromevdl 0dc6671
refactoring
jeromevdl 8709ca0
maven setup for e2e tests
jeromevdl acbf705
clean poms and have a parent to simplify version bump
jeromevdl 1a69b2a
add github action for e2e
jeromevdl 6e5fadb
add maven cache to github actions
jeromevdl 4c1b6d2
remove github actions e2e tests
jeromevdl 841269e
cleaning poms
jeromevdl 7b81e22
improve documentation
jeromevdl 09fd6eb
jdk8 compatible
jeromevdl 1b159cd
Merge branch 'master' into feat/integration-tests
jeromevdl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## End-to-end tests | ||
This module is internal and meant to be used for end-to-end (E2E) testing of Lambda Powertools for Java. | ||
|
||
__Prerequisites__: | ||
- An AWS account is needed as well as a local environment able to reach this account | ||
([credentials](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials.html)). | ||
- [Java 11+](https://docs.aws.amazon.com/corretto/latest/corretto-11-ug/downloads-list.html) | ||
- [Docker](https://docs.docker.com/engine/install/) | ||
|
||
To execute the E2E tests, use the following command: `export JAVA_VERSION=11 && mvn clean verify -Pe2e` | ||
|
||
### Under the hood | ||
This module leverages the following components: | ||
- AWS CDK to define the infrastructure and synthesize a CloudFormation template and the assets (lambda function packages) | ||
- The AWS S3 SDK to push the assets on S3 | ||
- The AWS CloudFormation SDK to deploy the template | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>e2e-test-handlers-parent</artifactId> | ||
<version>1.0.0</version> | ||
</parent> | ||
|
||
<artifactId>e2e-test-handler-idempotency</artifactId> | ||
<packaging>jar</packaging> | ||
<name>A Lambda function using powertools idempotency</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-idempotency</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
jeromevdl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<artifactId>aws-lambda-java-events</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>aspectj-maven-plugin</artifactId> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<complianceLevel>${maven.compiler.target}</complianceLevel> | ||
<aspectLibraries> | ||
<aspectLibrary> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-idempotency</artifactId> | ||
</aspectLibrary> | ||
</aspectLibraries> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
48 changes: 48 additions & 0 deletions
48
...ts/handlers/idempotency/src/main/java/software/amazon/lambda/powertools/e2e/Function.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package software.amazon.lambda.powertools.e2e; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.dynamodb.DynamoDbClient; | ||
import software.amazon.lambda.powertools.idempotency.Idempotency; | ||
import software.amazon.lambda.powertools.idempotency.IdempotencyConfig; | ||
import software.amazon.lambda.powertools.idempotency.Idempotent; | ||
import software.amazon.lambda.powertools.idempotency.persistence.DynamoDBPersistenceStore; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.TimeZone; | ||
|
||
|
||
public class Function implements RequestHandler<Input, String> { | ||
|
||
public Function() { | ||
this(DynamoDbClient | ||
.builder() | ||
.httpClient(UrlConnectionHttpClient.builder().build()) | ||
.region(Region.of(System.getenv("AWS_REGION"))) | ||
.build()); | ||
} | ||
|
||
public Function(DynamoDbClient client) { | ||
Idempotency.config().withConfig( | ||
IdempotencyConfig.builder() | ||
.withExpiration(Duration.of(10, ChronoUnit.SECONDS)) | ||
.build()) | ||
.withPersistenceStore( | ||
DynamoDBPersistenceStore.builder() | ||
.withDynamoDbClient(client) | ||
.withTableName(System.getenv("IDEMPOTENCY_TABLE")) | ||
.build() | ||
).configure(); | ||
} | ||
|
||
@Idempotent | ||
public String handleRequest(Input input, Context context) { | ||
DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE_TIME.withZone(TimeZone.getTimeZone("UTC").toZoneId()); | ||
return dtf.format(Instant.now()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...tests/handlers/idempotency/src/main/java/software/amazon/lambda/powertools/e2e/Input.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package software.amazon.lambda.powertools.e2e; | ||
|
||
public class Input { | ||
private String message; | ||
|
||
public Input(String message) { | ||
this.message = message; | ||
} | ||
|
||
public Input() { | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>e2e-test-handlers-parent</artifactId> | ||
<version>1.0.0</version> | ||
</parent> | ||
|
||
<artifactId>e2e-test-handler-logging</artifactId> | ||
<packaging>jar</packaging> | ||
<name>A Lambda function using powertools logging</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-logging</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
jeromevdl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<artifactId>aws-lambda-java-events</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>aspectj-maven-plugin</artifactId> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<complianceLevel>${maven.compiler.target}</complianceLevel> | ||
<aspectLibraries> | ||
<aspectLibrary> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-logging</artifactId> | ||
</aspectLibrary> | ||
</aspectLibraries> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
22 changes: 22 additions & 0 deletions
22
...-tests/handlers/logging/src/main/java/software/amazon/lambda/powertools/e2e/Function.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package software.amazon.lambda.powertools.e2e; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import software.amazon.lambda.powertools.logging.Logging; | ||
import software.amazon.lambda.powertools.logging.LoggingUtils; | ||
|
||
public class Function implements RequestHandler<Input, String> { | ||
|
||
private static final Logger LOG = LogManager.getLogger(Function.class); | ||
|
||
@Logging | ||
public String handleRequest(Input input, Context context) { | ||
|
||
LoggingUtils.appendKeys(input.getKeys()); | ||
LOG.info(input.getMessage()); | ||
|
||
return "OK"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...e2e-tests/handlers/logging/src/main/java/software/amazon/lambda/powertools/e2e/Input.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package software.amazon.lambda.powertools.e2e; | ||
|
||
import java.util.Map; | ||
|
||
public class Input { | ||
private String message; | ||
private Map<String, String> keys; | ||
|
||
public Input() { | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public Map<String, String> getKeys() { | ||
return keys; | ||
} | ||
|
||
public void setKeys(Map<String, String> keys) { | ||
this.keys = keys; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
powertools-e2e-tests/handlers/logging/src/main/resources/log4j2.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration> | ||
<Appenders> | ||
<Console name="JsonAppender" target="SYSTEM_OUT"> | ||
<JsonTemplateLayout eventTemplateUri="classpath:LambdaJsonLayout.json" /> | ||
</Console> | ||
</Appenders> | ||
<Loggers> | ||
<Root level="INFO"> | ||
<AppenderRef ref="JsonAppender"/> | ||
</Root> | ||
<Logger name="JsonLogger" level="INFO" additivity="false"> | ||
<AppenderRef ref="JsonAppender"/> | ||
</Logger> | ||
</Loggers> | ||
</Configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>e2e-test-handlers-parent</artifactId> | ||
<version>1.0.0</version> | ||
</parent> | ||
|
||
<artifactId>e2e-test-handler-metrics</artifactId> | ||
<packaging>jar</packaging> | ||
<name>A Lambda function using powertools metrics</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-metrics</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-lambda-java-events</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>aspectj-maven-plugin</artifactId> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<complianceLevel>${maven.compiler.target}</complianceLevel> | ||
<aspectLibraries> | ||
<aspectLibrary> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-metrics</artifactId> | ||
</aspectLibrary> | ||
</aspectLibraries> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
26 changes: 26 additions & 0 deletions
26
...-tests/handlers/metrics/src/main/java/software/amazon/lambda/powertools/e2e/Function.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package software.amazon.lambda.powertools.e2e; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger; | ||
import software.amazon.cloudwatchlogs.emf.model.DimensionSet; | ||
import software.amazon.cloudwatchlogs.emf.model.Unit; | ||
import software.amazon.lambda.powertools.metrics.Metrics; | ||
import software.amazon.lambda.powertools.metrics.MetricsUtils; | ||
|
||
public class Function implements RequestHandler<Input, String> { | ||
|
||
MetricsLogger metricsLogger = MetricsUtils.metricsLogger(); | ||
|
||
@Metrics(captureColdStart = true) | ||
public String handleRequest(Input input, Context context) { | ||
|
||
DimensionSet dimensionSet = new DimensionSet(); | ||
input.getDimensions().forEach((key, value) -> dimensionSet.addDimension(key, value)); | ||
metricsLogger.putDimensions(dimensionSet); | ||
|
||
input.getMetrics().forEach((key, value) -> metricsLogger.putMetric(key, value, Unit.COUNT)); | ||
|
||
return "OK"; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.