Skip to content

test: e2e tests with java 21 #1517

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
merged 9 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
15 changes: 11 additions & 4 deletions .github/workflows/run-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ jobs:
e2e:
runs-on: ubuntu-latest
strategy:
max-parallel: 3
max-parallel: 4
matrix:
java: [ 8, 11, 17 ]
java: [ 8, 11, 17, 21 ]
name: End-to-end tests java${{ matrix.java }}
env:
JAVA_VERSION: ${{ matrix.java }}
AWS_DEFAULT_REGION: eu-west-1

# If matrix.version is 21, use 17, otherwise use matrix.version
# This is because AspectJ does not yet support weaving with Java21; we want
# to test the Java21 runtime, but we can't yet use the JDK21 compiler.
# https://github.com/eclipse-aspectj/aspectj/issues/260#issuecomment-1815920274
JAVA_VERSION: ${{ (matrix.java == 21 && '17') || matrix.java }}
JAVA_LAMBDA_RUNTIME_VERSION: ${{ matrix.java }}
permissions:
id-token: write # needed to interact with GitHub's OIDC Token endpoint.
contents: read
Expand All @@ -48,7 +54,8 @@ jobs:
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
with:
distribution: 'corretto'
java-version: ${{ matrix.java }}
# See comment above on JAVA_VERSION env var
java-version: ${{ (matrix.java == 21 && '17') || matrix.java }}
cache: maven
- name: Setup AWS credentials
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ Powertools for AWS Lambda (Java) is a developer toolkit to implement Serverless

**[📜Documentation](https://docs.powertools.aws.dev/lambda-java/)** | **[Feature request](https://github.com/aws-powertools/powertools-lambda-java/issues/new?assignees=&labels=feature-request%2C+triage&template=feature_request.md&title=)** | **[🐛Bug Report](https://github.com/aws-powertools/powertools-lambda-java/issues/new?assignees=&labels=bug%2C+triage&template=bug_report.md&title=)** | **[Detailed blog post](https://aws.amazon.com/blogs/opensource/simplifying-serverless-best-practices-with-aws-lambda-powertools-java/)**

### Java Compatibility
Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the
[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).

Note: [AspectJ does not yet support Java 21](https://github.com/eclipse-aspectj/aspectj/issues/260).
With Java 21, you can use Powertools features that do not need AspectJ such as
[Batch Processing](https://docs.powertools.aws.dev/lambda-java/guides/batch-processing.html) as you normally would.
If you need aspect features you should use the JDK 17 compiler and target either the Java 17 or Java 21
runtimes at deployment Lambda.

### Installation

Powertools for AWS Lambda (Java) is available in Maven Central. You can use your favourite dependency management tool to install it
Expand Down
2 changes: 1 addition & 1 deletion powertools-e2e-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<constructs.version>10.3.0</constructs.version>
<cdk.version>2.100.0</cdk.version>
<cdk.version>2.109.0</cdk.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public class Infrastructure {
private final String queue;
private final String kinesisStream;
private final String largeMessagesBucket;
private final JavaRuntime lambdaRuntimeVersion;
private String ddbStreamsTableName;
private String functionName;
private Object cfnTemplate;
Expand All @@ -124,6 +125,7 @@ private Infrastructure(Builder builder) {
this.tracing = builder.tracing;
this.envVar = builder.environmentVariables;
this.runtime = builder.runtime;
this.lambdaRuntimeVersion = builder.lambdaRuntimeVersion;
this.timeout = builder.timeoutInSeconds;
this.pathToFunction = builder.pathToFunction;
this.idempotencyTable = builder.idemPotencyTable;
Expand Down Expand Up @@ -204,6 +206,7 @@ public void destroy() {
private Stack createStackWithLambda() {
boolean createTableForAsyncTests = false;
Stack stack = new Stack(app, stackName);

List<String> packagingInstruction = Arrays.asList(
"/bin/sh",
"-c",
Expand Down Expand Up @@ -247,7 +250,7 @@ private Stack createStackWithLambda() {
.handler("software.amazon.lambda.powertools.e2e.Function::handleRequest")
.memorySize(1024)
.timeout(Duration.seconds(timeout))
.runtime(runtime.getCdkRuntime())
.runtime(lambdaRuntimeVersion.getCdkRuntime())
.environment(envVar)
.tracing(tracing ? Tracing.ACTIVE : Tracing.DISABLED)
.build();
Expand Down Expand Up @@ -504,29 +507,34 @@ public static class Builder {
private String queue;
private String kinesisStream;
private String ddbStreamsTableName;
private JavaRuntime lambdaRuntimeVersion;

private Builder() {
getJavaRuntime();
runtime = mapRuntimeVersion("JAVA_VERSION");
lambdaRuntimeVersion = mapRuntimeVersion("JAVA_LAMBDA_RUNTIME_VERSION");
}

/**
* Retrieve the java runtime to use for the lambda function.
*/
private void getJavaRuntime() {
String javaVersion = System.getenv("JAVA_VERSION"); // must be set in GitHub actions


private JavaRuntime mapRuntimeVersion(String environmentVariableName) {
String javaVersion = System.getenv(environmentVariableName); // must be set in GitHub actions
JavaRuntime ret = null;
if (javaVersion == null) {
throw new IllegalArgumentException("JAVA_VERSION is not set");
throw new IllegalArgumentException("JAVA_LAMBDA_RUNTIME_VERSION is not set");
}
if (javaVersion.startsWith("8")) {
runtime = JavaRuntime.JAVA8AL2;
ret = JavaRuntime.JAVA8AL2;
} else if (javaVersion.startsWith("11")) {
runtime = JavaRuntime.JAVA11;
ret = JavaRuntime.JAVA11;
} else if (javaVersion.startsWith("17")) {
runtime = JavaRuntime.JAVA17;
ret = JavaRuntime.JAVA17;
} else if (javaVersion.startsWith("21")) {
ret = JavaRuntime.JAVA21;
} else {
throw new IllegalArgumentException("Unsupported Java version " + javaVersion);
}
LOG.debug("Java Version set to {}, using runtime {}", javaVersion, runtime.getRuntime());
LOG.debug("Java Version set to {}, using runtime variable {}", ret, javaVersion);
return ret;
}

public Infrastructure build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public enum JavaRuntime {
JAVA8("java8", Runtime.JAVA_8, "1.8"),
JAVA8AL2("java8.al2", Runtime.JAVA_8_CORRETTO, "1.8"),
JAVA11("java11", Runtime.JAVA_11, "11"),
JAVA17("java17", Runtime.JAVA_17, "17");
JAVA17("java17", Runtime.JAVA_17, "17"),
JAVA21("java21", Runtime.JAVA_21, "21");

private final String runtime;
private final Runtime cdkRuntime;
Expand Down