Skip to content

Commit 34d73e7

Browse files
committed
Add support for generic types.
1 parent 4dc0790 commit 34d73e7

File tree

20 files changed

+593
-55
lines changed

20 files changed

+593
-55
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>software.amazon.lambda</groupId>
7+
<artifactId>e2e-test-handlers-parent</artifactId>
8+
<version>2.5.0</version>
9+
</parent>
10+
11+
<artifactId>e2e-test-handler-idempotency-generics</artifactId>
12+
<packaging>jar</packaging>
13+
<name>E2E test handler – Idempotency Generics</name>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>software.amazon.lambda</groupId>
18+
<artifactId>powertools-idempotency-dynamodb</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>software.amazon.lambda</groupId>
22+
<artifactId>powertools-logging-log4j</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.amazonaws</groupId>
26+
<artifactId>aws-lambda-java-events</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.amazonaws</groupId>
30+
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.amazonaws</groupId>
34+
<artifactId>aws-lambda-java-core</artifactId>
35+
</dependency>
36+
</dependencies>
37+
38+
<build>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-shade-plugin</artifactId>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
47+
<profiles>
48+
<profile>
49+
<id>native-image</id>
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.graalvm.buildtools</groupId>
54+
<artifactId>native-maven-plugin</artifactId>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
</profile>
59+
</profiles>
60+
</project>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
15+
package software.amazon.lambda.powertools.e2e;
16+
17+
import java.time.Duration;
18+
import java.time.Instant;
19+
import java.time.format.DateTimeFormatter;
20+
import java.time.temporal.ChronoUnit;
21+
import java.util.HashMap;
22+
import java.util.Map;
23+
import java.util.TimeZone;
24+
25+
import com.amazonaws.services.lambda.runtime.Context;
26+
import com.amazonaws.services.lambda.runtime.RequestHandler;
27+
import com.fasterxml.jackson.core.type.TypeReference;
28+
29+
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
30+
import software.amazon.awssdk.regions.Region;
31+
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
32+
import software.amazon.lambda.powertools.idempotency.Idempotency;
33+
import software.amazon.lambda.powertools.idempotency.IdempotencyConfig;
34+
import software.amazon.lambda.powertools.idempotency.PowertoolsIdempotency;
35+
import software.amazon.lambda.powertools.idempotency.persistence.dynamodb.DynamoDBPersistenceStore;
36+
37+
public class Function implements RequestHandler<Input, String> {
38+
39+
public Function() {
40+
this(DynamoDbClient
41+
.builder()
42+
.httpClient(UrlConnectionHttpClient.builder().build())
43+
.region(Region.of(System.getenv("AWS_REGION")))
44+
.build());
45+
}
46+
47+
public Function(DynamoDbClient client) {
48+
Idempotency.config().withConfig(
49+
IdempotencyConfig.builder()
50+
.withExpiration(Duration.of(10, ChronoUnit.SECONDS))
51+
.build())
52+
.withPersistenceStore(
53+
DynamoDBPersistenceStore.builder()
54+
.withDynamoDbClient(client)
55+
.withTableName(System.getenv("IDEMPOTENCY_TABLE"))
56+
.build())
57+
.configure();
58+
}
59+
60+
public String handleRequest(Input input, Context context) {
61+
Idempotency.registerLambdaContext(context);
62+
63+
// This is just to test the generic type support using TypeReference.
64+
// We return the same String to run the same assertions as other idempotency E2E handlers.
65+
Map<String, String> result = PowertoolsIdempotency.makeIdempotent(
66+
this::processRequest,
67+
input,
68+
new TypeReference<Map<String, String>>() {});
69+
70+
return result.get("timestamp");
71+
}
72+
73+
private Map<String, String> processRequest(Input input) {
74+
DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE_TIME.withZone(TimeZone.getTimeZone("UTC").toZoneId());
75+
Map<String, String> result = new HashMap<>();
76+
result.put("timestamp", dtf.format(Instant.now()));
77+
return result;
78+
}
79+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
15+
package software.amazon.lambda.powertools.e2e;
16+
17+
public class Input {
18+
private String message;
19+
20+
public String getMessage() {
21+
return message;
22+
}
23+
24+
public void setMessage(String message) {
25+
this.message = message;
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"name":"com.amazonaws.services.lambda.runtime.LambdaRuntime",
4+
"methods":[{"name":"<init>","parameterTypes":[] }],
5+
"fields":[{"name":"logger"}],
6+
"allPublicMethods":true
7+
},
8+
{
9+
"name":"com.amazonaws.services.lambda.runtime.LambdaRuntimeInternal",
10+
"methods":[{"name":"<init>","parameterTypes":[] }],
11+
"allPublicMethods":true
12+
}
13+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[
2+
{
3+
"name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent",
4+
"allDeclaredFields": true,
5+
"allDeclaredMethods": true,
6+
"allDeclaredConstructors": true
7+
},
8+
{
9+
"name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent$ProxyRequestContext",
10+
"allDeclaredFields": true,
11+
"allDeclaredMethods": true,
12+
"allDeclaredConstructors": true
13+
},
14+
{
15+
"name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent$RequestIdentity",
16+
"allDeclaredFields": true,
17+
"allDeclaredMethods": true,
18+
"allDeclaredConstructors": true
19+
},
20+
{
21+
"name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent",
22+
"allDeclaredFields": true,
23+
"allDeclaredMethods": true,
24+
"allDeclaredConstructors": true
25+
},
26+
{
27+
"name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent",
28+
"allDeclaredConstructors": true,
29+
"allPublicConstructors": true,
30+
"allDeclaredMethods": true,
31+
"allPublicMethods": true,
32+
"allDeclaredClasses": true,
33+
"allPublicClasses": true
34+
}
35+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
"name":"com.amazonaws.services.lambda.runtime.api.client.runtimeapi.LambdaRuntimeClientException",
4+
"methods":[{"name":"<init>","parameterTypes":["java.lang.String","int"] }]
5+
},
6+
{
7+
"name":"com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.InvocationRequest",
8+
"fields":[{"name":"id"}, {"name":"invokedFunctionArn"}, {"name":"deadlineTimeInMs"}, {"name":"xrayTraceId"}, {"name":"clientContext"}, {"name":"cognitoIdentity"}, {"name": "tenantId"}, {"name":"content"}],
9+
"allPublicMethods":true
10+
}
11+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Args = --initialize-at-build-time=jdk.xml.internal.SecuritySupport
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[
2+
{
3+
"name": "com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.deser.Deserializers[]"
4+
},
5+
{
6+
"name": "com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.ext.Java7SupportImpl",
7+
"methods": [{ "name": "<init>", "parameterTypes": [] }]
8+
},
9+
{
10+
"name": "com.amazonaws.services.lambda.runtime.LambdaRuntime",
11+
"fields": [{ "name": "logger" }]
12+
},
13+
{
14+
"name": "com.amazonaws.services.lambda.runtime.logging.LogLevel",
15+
"allDeclaredConstructors": true,
16+
"allPublicConstructors": true,
17+
"allDeclaredMethods": true,
18+
"allPublicMethods": true,
19+
"allDeclaredFields": true,
20+
"allPublicFields": true
21+
},
22+
{
23+
"name": "com.amazonaws.services.lambda.runtime.logging.LogFormat",
24+
"allDeclaredConstructors": true,
25+
"allPublicConstructors": true,
26+
"allDeclaredMethods": true,
27+
"allPublicMethods": true,
28+
"allDeclaredFields": true,
29+
"allPublicFields": true
30+
},
31+
{
32+
"name": "java.lang.Void",
33+
"methods": [{ "name": "<init>", "parameterTypes": [] }]
34+
},
35+
{
36+
"name": "java.util.Collections$UnmodifiableMap",
37+
"fields": [{ "name": "m" }]
38+
},
39+
{
40+
"name": "jdk.internal.module.IllegalAccessLogger",
41+
"fields": [{ "name": "logger" }]
42+
},
43+
{
44+
"name": "sun.misc.Unsafe",
45+
"fields": [{ "name": "theUnsafe" }]
46+
},
47+
{
48+
"name": "com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.InvocationRequest",
49+
"fields": [
50+
{ "name": "id" },
51+
{ "name": "invokedFunctionArn" },
52+
{ "name": "deadlineTimeInMs" },
53+
{ "name": "xrayTraceId" },
54+
{ "name": "clientContext" },
55+
{ "name": "cognitoIdentity" },
56+
{ "name": "tenantId" },
57+
{ "name": "content" }
58+
],
59+
"allPublicMethods": true
60+
}
61+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"resources": {
3+
"includes": [
4+
{
5+
"pattern": "\\Qjni/libaws-lambda-jni.linux-aarch_64.so\\E"
6+
},
7+
{
8+
"pattern": "\\Qjni/libaws-lambda-jni.linux-x86_64.so\\E"
9+
},
10+
{
11+
"pattern": "\\Qjni/libaws-lambda-jni.linux_musl-aarch_64.so\\E"
12+
},
13+
{
14+
"pattern": "\\Qjni/libaws-lambda-jni.linux_musl-x86_64.so\\E"
15+
}
16+
]
17+
},
18+
"bundles": []
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[
2+
{
3+
"name": "com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.deser.Deserializers[]"
4+
},
5+
{
6+
"name": "com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.ext.Java7HandlersImpl",
7+
"methods": [{ "name": "<init>", "parameterTypes": [] }]
8+
},
9+
{
10+
"name": "com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.ext.Java7SupportImpl",
11+
"methods": [{ "name": "<init>", "parameterTypes": [] }]
12+
},
13+
{
14+
"name": "com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.ser.Serializers[]"
15+
},
16+
{
17+
"name": "org.joda.time.DateTime",
18+
"allDeclaredConstructors": true,
19+
"allPublicConstructors": true,
20+
"allDeclaredMethods": true,
21+
"allPublicMethods": true,
22+
"allDeclaredClasses": true,
23+
"allPublicClasses": true
24+
}
25+
]

0 commit comments

Comments
 (0)