Skip to content

Commit 76cd363

Browse files
test: e2e tests with java 21 (#1517)
* e2e tests with java 21 * Run Java21 tests using the Java17 compiler * Run all of the E2E tests in parallel, not just the first 3 * Try again * . * Let's try again * Add some comment on Java21 to the repo * Add caveat about lambda runtimes * Clean up wording a little --------- Co-authored-by: Scott Gerring <[email protected]>
1 parent 0c9b9ab commit 76cd363

File tree

6 files changed

+51
-19
lines changed

6 files changed

+51
-19
lines changed

Diff for: .github/workflows/run-e2e-tests.yml

+11-4
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ jobs:
3232
e2e:
3333
runs-on: ubuntu-latest
3434
strategy:
35-
max-parallel: 3
35+
max-parallel: 4
3636
matrix:
37-
java: [ 8, 11, 17 ]
37+
java: [ 8, 11, 17, 21 ]
3838
name: End-to-end tests java${{ matrix.java }}
3939
env:
40-
JAVA_VERSION: ${{ matrix.java }}
4140
AWS_DEFAULT_REGION: eu-west-1
41+
42+
# If matrix.version is 21, use 17, otherwise use matrix.version
43+
# This is because AspectJ does not yet support weaving with Java21; we want
44+
# to test the Java21 runtime, but we can't yet use the JDK21 compiler.
45+
# https://github.com/eclipse-aspectj/aspectj/issues/260#issuecomment-1815920274
46+
JAVA_VERSION: ${{ (matrix.java == 21 && '17') || matrix.java }}
47+
JAVA_LAMBDA_RUNTIME_VERSION: ${{ matrix.java }}
4248
permissions:
4349
id-token: write # needed to interact with GitHub's OIDC Token endpoint.
4450
contents: read
@@ -48,7 +54,8 @@ jobs:
4854
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
4955
with:
5056
distribution: 'corretto'
51-
java-version: ${{ matrix.java }}
57+
# See comment above on JAVA_VERSION env var
58+
java-version: ${{ (matrix.java == 21 && '17') || matrix.java }}
5259
cache: maven
5360
- name: Setup AWS credentials
5461
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0

Diff for: README.md

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ Powertools for AWS Lambda (Java) is a developer toolkit to implement Serverless
99
1010
**[📜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/)**
1111

12+
### Java Compatibility
13+
Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the
14+
[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
15+
16+
AspectJ does not yet support Java 21 [[1]](https://github.com/eclipse-aspectj/aspectj/issues/260), [[2]](https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md).
17+
If you need to use aspects - either Powertools features leveraging aspects or other libraries - you should use the JDK 17 compiler and target either the Java 17 or Java 21
18+
Lambda runtimes.
19+
1220
### Installation
1321

1422
Powertools for AWS Lambda (Java) is available in Maven Central. You can use your favourite dependency management tool to install it

Diff for: docs/index.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ Powertools for AWS Lambda (Java) is a suite of utilities for AWS Lambda Function
1111
Powertools for AWS Lambda is also available for [Python](https://docs.powertools.aws.dev/lambda/python/latest/){target="_blank"}, [TypeScript](https://docs.powertools.aws.dev/lambda/typescript/latest/){target="_blank"}, and [.NET](https://docs.powertools.aws.dev/lambda/dotnet/){target="_blank"}
1212

1313

14-
!!! tip "Looking for a quick run through of the core utilities?"
14+
???+ tip "Looking for a quick run through of the core utilities?"
1515
Check out [this detailed blog post](https://aws.amazon.com/blogs/opensource/simplifying-serverless-best-practices-with-aws-lambda-powertools-java/) with a practical example. To dive deeper,
1616
the [Powertools for AWS Lambda (Java) workshop](https://catalog.us-east-1.prod.workshops.aws/workshops/a7011c82-e4af-4a52-80fa-fcd61f1dacd9/en-US/introduction) is a great next step.
1717

18+
???+ tip "Java Compatability"
19+
Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the
20+
[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
21+
22+
AspectJ does not yet support Java 21 [[1]](https://github.com/eclipse-aspectj/aspectj/issues/260), [[2]](https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md).
23+
If you need to use aspects - either Powertools features leveraging aspects or other libraries - you should use the JDK 17 compiler and target either the Java 17 or Java 21
24+
Lambda runtimes.
25+
1826
## Tenets
1927

2028
This project separates core utilities that will be available in other runtimes vs general utilities that might not be available across all runtimes.

Diff for: powertools-e2e-tests/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<maven.compiler.source>1.8</maven.compiler.source>
3232
<maven.compiler.target>1.8</maven.compiler.target>
3333
<constructs.version>10.3.0</constructs.version>
34-
<cdk.version>2.100.0</cdk.version>
34+
<cdk.version>2.109.0</cdk.version>
3535
</properties>
3636

3737
<dependencies>

Diff for: powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java

+20-12
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public class Infrastructure {
114114
private final String queue;
115115
private final String kinesisStream;
116116
private final String largeMessagesBucket;
117+
private final JavaRuntime lambdaRuntimeVersion;
117118
private String ddbStreamsTableName;
118119
private String functionName;
119120
private Object cfnTemplate;
@@ -124,6 +125,7 @@ private Infrastructure(Builder builder) {
124125
this.tracing = builder.tracing;
125126
this.envVar = builder.environmentVariables;
126127
this.runtime = builder.runtime;
128+
this.lambdaRuntimeVersion = builder.lambdaRuntimeVersion;
127129
this.timeout = builder.timeoutInSeconds;
128130
this.pathToFunction = builder.pathToFunction;
129131
this.idempotencyTable = builder.idemPotencyTable;
@@ -204,6 +206,7 @@ public void destroy() {
204206
private Stack createStackWithLambda() {
205207
boolean createTableForAsyncTests = false;
206208
Stack stack = new Stack(app, stackName);
209+
207210
List<String> packagingInstruction = Arrays.asList(
208211
"/bin/sh",
209212
"-c",
@@ -247,7 +250,7 @@ private Stack createStackWithLambda() {
247250
.handler("software.amazon.lambda.powertools.e2e.Function::handleRequest")
248251
.memorySize(1024)
249252
.timeout(Duration.seconds(timeout))
250-
.runtime(runtime.getCdkRuntime())
253+
.runtime(lambdaRuntimeVersion.getCdkRuntime())
251254
.environment(envVar)
252255
.tracing(tracing ? Tracing.ACTIVE : Tracing.DISABLED)
253256
.build();
@@ -504,29 +507,34 @@ public static class Builder {
504507
private String queue;
505508
private String kinesisStream;
506509
private String ddbStreamsTableName;
510+
private JavaRuntime lambdaRuntimeVersion;
507511

508512
private Builder() {
509-
getJavaRuntime();
513+
runtime = mapRuntimeVersion("JAVA_VERSION");
514+
lambdaRuntimeVersion = mapRuntimeVersion("JAVA_LAMBDA_RUNTIME_VERSION");
510515
}
511516

512-
/**
513-
* Retrieve the java runtime to use for the lambda function.
514-
*/
515-
private void getJavaRuntime() {
516-
String javaVersion = System.getenv("JAVA_VERSION"); // must be set in GitHub actions
517+
518+
519+
private JavaRuntime mapRuntimeVersion(String environmentVariableName) {
520+
String javaVersion = System.getenv(environmentVariableName); // must be set in GitHub actions
521+
JavaRuntime ret = null;
517522
if (javaVersion == null) {
518-
throw new IllegalArgumentException("JAVA_VERSION is not set");
523+
throw new IllegalArgumentException("JAVA_LAMBDA_RUNTIME_VERSION is not set");
519524
}
520525
if (javaVersion.startsWith("8")) {
521-
runtime = JavaRuntime.JAVA8AL2;
526+
ret = JavaRuntime.JAVA8AL2;
522527
} else if (javaVersion.startsWith("11")) {
523-
runtime = JavaRuntime.JAVA11;
528+
ret = JavaRuntime.JAVA11;
524529
} else if (javaVersion.startsWith("17")) {
525-
runtime = JavaRuntime.JAVA17;
530+
ret = JavaRuntime.JAVA17;
531+
} else if (javaVersion.startsWith("21")) {
532+
ret = JavaRuntime.JAVA21;
526533
} else {
527534
throw new IllegalArgumentException("Unsupported Java version " + javaVersion);
528535
}
529-
LOG.debug("Java Version set to {}, using runtime {}", javaVersion, runtime.getRuntime());
536+
LOG.debug("Java Version set to {}, using runtime variable {}", ret, javaVersion);
537+
return ret;
530538
}
531539

532540
public Infrastructure build() {

Diff for: powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/JavaRuntime.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public enum JavaRuntime {
2020
JAVA8("java8", Runtime.JAVA_8, "1.8"),
2121
JAVA8AL2("java8.al2", Runtime.JAVA_8_CORRETTO, "1.8"),
2222
JAVA11("java11", Runtime.JAVA_11, "11"),
23-
JAVA17("java17", Runtime.JAVA_17, "17");
23+
JAVA17("java17", Runtime.JAVA_17, "17"),
24+
JAVA21("java21", Runtime.JAVA_21, "21");
2425

2526
private final String runtime;
2627
private final Runtime cdkRuntime;

0 commit comments

Comments
 (0)