Skip to content

Commit c1fd00d

Browse files
committed
add e2e tests for logging
1 parent c556e38 commit c1fd00d

File tree

12 files changed

+1032
-0
lines changed

12 files changed

+1032
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package software.amazon.lambda.powertools.e2e;
2+
3+
import com.amazonaws.services.lambda.runtime.Context;
4+
import com.amazonaws.services.lambda.runtime.RequestHandler;
5+
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
6+
import software.amazon.awssdk.regions.Region;
7+
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
8+
import software.amazon.lambda.powertools.idempotency.Idempotency;
9+
import software.amazon.lambda.powertools.idempotency.IdempotencyConfig;
10+
import software.amazon.lambda.powertools.idempotency.Idempotent;
11+
import software.amazon.lambda.powertools.idempotency.persistence.DynamoDBPersistenceStore;
12+
13+
import java.time.Instant;
14+
import java.time.format.DateTimeFormatter;
15+
16+
17+
public class Function implements RequestHandler<String, String> {
18+
19+
public Function() {
20+
this(DynamoDbClient
21+
.builder()
22+
.httpClient(UrlConnectionHttpClient.builder().build())
23+
.region(Region.of(System.getenv("AWS_REGION")))
24+
.build());
25+
}
26+
27+
public Function(DynamoDbClient client) {
28+
Idempotency.config().withConfig(
29+
IdempotencyConfig.builder()
30+
.build())
31+
.withPersistenceStore(
32+
DynamoDBPersistenceStore.builder()
33+
.withDynamoDbClient(client)
34+
.withTableName(System.getenv("IDEMPOTENCY_TABLE"))
35+
.build()
36+
).configure();
37+
}
38+
39+
@Idempotent
40+
public String handleRequest(String input, Context context) {
41+
DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE;
42+
return dtf.format(Instant.now());
43+
}
44+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
<groupId>software.amazon.lambda</groupId>
6+
<artifactId>E2ELoggingFunction</artifactId>
7+
<version>1.12.3</version>
8+
<packaging>jar</packaging>
9+
<name>A sample Hello World using powertools logging</name>
10+
11+
<properties>
12+
<log4j.version>2.19.0</log4j.version>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<lambda.powertools.version>1.12.3</lambda.powertools.version>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>software.amazon.lambda</groupId>
20+
<artifactId>powertools-logging</artifactId>
21+
<version>${lambda.powertools.version}</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>com.amazonaws</groupId>
25+
<artifactId>aws-lambda-java-core</artifactId>
26+
<version>1.2.1</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.amazonaws</groupId>
30+
<artifactId>aws-lambda-java-events</artifactId>
31+
<version>3.11.0</version>
32+
</dependency>
33+
34+
</dependencies>
35+
36+
<build>
37+
<plugins>
38+
<plugin>
39+
<groupId>org.codehaus.mojo</groupId>
40+
<artifactId>aspectj-maven-plugin</artifactId>
41+
<version>1.14.0</version>
42+
<configuration>
43+
<source>${maven.compiler.source}</source>
44+
<target>${maven.compiler.target}</target>
45+
<complianceLevel>${maven.compiler.target}</complianceLevel>
46+
<aspectLibraries>
47+
<aspectLibrary>
48+
<groupId>software.amazon.lambda</groupId>
49+
<artifactId>powertools-logging</artifactId>
50+
</aspectLibrary>
51+
</aspectLibraries>
52+
</configuration>
53+
<executions>
54+
<execution>
55+
<goals>
56+
<goal>compile</goal>
57+
</goals>
58+
</execution>
59+
</executions>
60+
</plugin>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-shade-plugin</artifactId>
64+
<version>3.2.4</version>
65+
<configuration>
66+
<createDependencyReducedPom>false</createDependencyReducedPom>
67+
<finalName>function</finalName>
68+
</configuration>
69+
<executions>
70+
<execution>
71+
<phase>package</phase>
72+
<goals>
73+
<goal>shade</goal>
74+
</goals>
75+
<configuration>
76+
<transformers>
77+
<transformer
78+
implementation="io.github.edwgiz.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer">
79+
</transformer>
80+
</transformers>
81+
</configuration>
82+
</execution>
83+
</executions>
84+
<dependencies>
85+
<dependency>
86+
<groupId>io.github.edwgiz</groupId>
87+
<artifactId>log4j-maven-shade-plugin-extensions</artifactId>
88+
<version>2.17.2</version>
89+
</dependency>
90+
</dependencies>
91+
</plugin>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-compiler-plugin</artifactId>
95+
<version>3.10.1</version>
96+
<configuration>
97+
<source>${maven.compiler.source}</source>
98+
<target>${maven.compiler.target}</target>
99+
</configuration>
100+
</plugin>
101+
</plugins>
102+
</build>
103+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package software.amazon.lambda.powertools.e2e;
2+
3+
import com.amazonaws.services.lambda.runtime.Context;
4+
import com.amazonaws.services.lambda.runtime.RequestHandler;
5+
import org.apache.logging.log4j.LogManager;
6+
import org.apache.logging.log4j.Logger;
7+
import software.amazon.lambda.powertools.logging.Logging;
8+
import software.amazon.lambda.powertools.logging.LoggingUtils;
9+
10+
public class Function implements RequestHandler<Input, String> {
11+
12+
private static final Logger LOG = LogManager.getLogger(Function.class);
13+
14+
@Logging
15+
public String handleRequest(Input input, Context context) {
16+
17+
LoggingUtils.appendKeys(input.getKeys());
18+
LOG.info(input.getMessage());
19+
20+
return "OK";
21+
}
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package software.amazon.lambda.powertools.e2e;
2+
3+
import java.util.Map;
4+
5+
public class Input {
6+
private String message;
7+
private Map<String, String> keys;
8+
9+
public Input() {
10+
}
11+
12+
public String getMessage() {
13+
return message;
14+
}
15+
16+
public void setMessage(String message) {
17+
this.message = message;
18+
}
19+
20+
public Map<String, String> getKeys() {
21+
return keys;
22+
}
23+
24+
public void setKeys(Map<String, String> keys) {
25+
this.keys = keys;
26+
}
27+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration>
3+
<Appenders>
4+
<Console name="JsonAppender" target="SYSTEM_OUT">
5+
<JsonTemplateLayout eventTemplateUri="classpath:LambdaJsonLayout.json" />
6+
</Console>
7+
</Appenders>
8+
<Loggers>
9+
<Root level="INFO">
10+
<AppenderRef ref="JsonAppender"/>
11+
</Root>
12+
<Logger name="JsonLogger" level="INFO" additivity="false">
13+
<AppenderRef ref="JsonAppender"/>
14+
</Logger>
15+
</Loggers>
16+
</Configuration>

powertools-e2e-tests/pom.xml

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<artifactId>powertools-parent</artifactId>
8+
<groupId>software.amazon.lambda</groupId>
9+
<version>1.12.3</version>
10+
</parent>
11+
12+
<artifactId>powertools-e2e-tests</artifactId>
13+
<description>AWS Lambda Powertools for Java End-To-End Tests</description>
14+
15+
<properties>
16+
<maven.compiler.source>11</maven.compiler.source>
17+
<maven.compiler.target>11</maven.compiler.target>
18+
<constructs.version>10.1.138</constructs.version>
19+
<cdk.version>2.47.0</cdk.version>
20+
</properties>
21+
22+
<dependencies>
23+
24+
<dependency>
25+
<groupId>ch.qos.logback</groupId>
26+
<artifactId>logback-classic</artifactId>
27+
<version>1.4.4</version>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>software.amazon.awssdk</groupId>
32+
<artifactId>lambda</artifactId>
33+
<version>${aws.sdk.version}</version>
34+
<scope>test</scope>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>software.amazon.awssdk</groupId>
39+
<artifactId>cloudwatch</artifactId>
40+
<version>${aws.sdk.version}</version>
41+
<scope>test</scope>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>software.amazon.awssdk</groupId>
46+
<artifactId>xray</artifactId>
47+
<version>${aws.sdk.version}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>software.amazon.awssdk</groupId>
53+
<artifactId>url-connection-client</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>org.junit.jupiter</groupId>
59+
<artifactId>junit-jupiter-api</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>org.junit.jupiter</groupId>
65+
<artifactId>junit-jupiter-engine</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>org.assertj</groupId>
71+
<artifactId>assertj-core</artifactId>
72+
<scope>test</scope>
73+
</dependency>
74+
75+
<dependency>
76+
<groupId>com.evanlennick</groupId>
77+
<artifactId>retry4j</artifactId>
78+
<version>0.15.0</version>
79+
<scope>test</scope>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>software.amazon.awscdk</groupId>
84+
<artifactId>aws-cdk-lib</artifactId>
85+
<version>${cdk.version}</version>
86+
<scope>test</scope>
87+
</dependency>
88+
89+
<dependency>
90+
<groupId>software.constructs</groupId>
91+
<artifactId>constructs</artifactId>
92+
<version>${constructs.version}</version>
93+
<scope>test</scope>
94+
</dependency>
95+
<dependency>
96+
<groupId>software.amazon.awssdk</groupId>
97+
<artifactId>s3</artifactId>
98+
<version>${aws.sdk.version}</version>
99+
<scope>test</scope>
100+
</dependency>
101+
<dependency>
102+
<groupId>software.amazon.awssdk</groupId>
103+
<artifactId>cloudformation</artifactId>
104+
<version>${aws.sdk.version}</version>
105+
<scope>test</scope>
106+
</dependency>
107+
<dependency>
108+
<groupId>software.amazon.awssdk</groupId>
109+
<artifactId>sts</artifactId>
110+
<version>${aws.sdk.version}</version>
111+
<scope>test</scope>
112+
</dependency>
113+
<dependency>
114+
<groupId>org.yaml</groupId>
115+
<artifactId>snakeyaml</artifactId>
116+
<version>1.33</version>
117+
<scope>test</scope>
118+
</dependency>
119+
<dependency>
120+
<groupId>org.aspectj</groupId>
121+
<artifactId>aspectjrt</artifactId>
122+
<scope>compile</scope>
123+
</dependency>
124+
<dependency>
125+
<groupId>software.amazon.lambda</groupId>
126+
<artifactId>powertools-serialization</artifactId>
127+
<scope>test</scope>
128+
</dependency>
129+
</dependencies>
130+
131+
<profiles>
132+
<profile>
133+
<id>it</id>
134+
<build>
135+
<plugins>
136+
<plugin>
137+
<groupId>org.codehaus.mojo</groupId>
138+
<artifactId>build-helper-maven-plugin</artifactId>
139+
<version>3.3.0</version>
140+
<executions>
141+
<execution>
142+
<id>add-test-source</id>
143+
<phase>process-resources</phase>
144+
<goals>
145+
<goal>add-test-source</goal>
146+
</goals>
147+
<configuration>
148+
<sources>
149+
<source>src/it/java</source>
150+
</sources>
151+
</configuration>
152+
</execution>
153+
</executions>
154+
</plugin>
155+
<plugin>
156+
<groupId>org.apache.maven.plugins</groupId>
157+
<artifactId>maven-failsafe-plugin</artifactId>
158+
<version>2.22.2</version>
159+
<executions>
160+
<execution>
161+
<goals>
162+
<goal>integration-test</goal>
163+
<goal>verify</goal>
164+
</goals>
165+
</execution>
166+
</executions>
167+
</plugin>
168+
</plugins>
169+
</build>
170+
</profile>
171+
</profiles>
172+
173+
</project>

0 commit comments

Comments
 (0)