Skip to content

Commit b8e3d65

Browse files
committed
integration tests infrastructure
1 parent 7cacd91 commit b8e3d65

File tree

11 files changed

+891
-1
lines changed

11 files changed

+891
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
<groupId>powertools-e2e-test</groupId>
5+
<artifactId>E2EIdempotencyFunction</artifactId>
6+
<version>1.0</version>
7+
<packaging>jar</packaging>
8+
<name>A sample Hello World using powertools idempotency</name>
9+
<properties>
10+
<log4j.version>2.17.2</log4j.version>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<lambda.powertools.version>1.12.3</lambda.powertools.version>
13+
</properties>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>software.amazon.lambda</groupId>
18+
<artifactId>powertools-logging</artifactId>
19+
<version>${lambda.powertools.version}</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>software.amazon.lambda</groupId>
23+
<artifactId>powertools-idempotency</artifactId>
24+
<version>${lambda.powertools.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>com.amazonaws</groupId>
28+
<artifactId>aws-lambda-java-core</artifactId>
29+
<version>1.2.1</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.amazonaws</groupId>
33+
<artifactId>aws-lambda-java-events</artifactId>
34+
<version>3.11.0</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.apache.logging.log4j</groupId>
38+
<artifactId>log4j-core</artifactId>
39+
<version>${log4j.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.logging.log4j</groupId>
43+
<artifactId>log4j-api</artifactId>
44+
<version>${log4j.version}</version>
45+
</dependency>
46+
</dependencies>
47+
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.codehaus.mojo</groupId>
52+
<artifactId>aspectj-maven-plugin</artifactId>
53+
<version>1.14.0</version>
54+
<configuration>
55+
<source>${maven.compiler.source}</source>
56+
<target>${maven.compiler.target}</target>
57+
<complianceLevel>${maven.compiler.target}</complianceLevel>
58+
<aspectLibraries>
59+
<aspectLibrary>
60+
<groupId>software.amazon.lambda</groupId>
61+
<artifactId>powertools-idempotency</artifactId>
62+
</aspectLibrary>
63+
</aspectLibraries>
64+
</configuration>
65+
<executions>
66+
<execution>
67+
<goals>
68+
<goal>compile</goal>
69+
</goals>
70+
</execution>
71+
</executions>
72+
</plugin>
73+
<plugin>
74+
<groupId>org.apache.maven.plugins</groupId>
75+
<artifactId>maven-shade-plugin</artifactId>
76+
<version>3.2.4</version>
77+
<configuration>
78+
<createDependencyReducedPom>false</createDependencyReducedPom>
79+
<finalName>function</finalName>
80+
</configuration>
81+
<executions>
82+
<execution>
83+
<phase>package</phase>
84+
<goals>
85+
<goal>shade</goal>
86+
</goals>
87+
<configuration>
88+
<transformers>
89+
<transformer
90+
implementation="io.github.edwgiz.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer">
91+
</transformer>
92+
</transformers>
93+
</configuration>
94+
</execution>
95+
</executions>
96+
<dependencies>
97+
<dependency>
98+
<groupId>io.github.edwgiz</groupId>
99+
<artifactId>log4j-maven-shade-plugin-extensions</artifactId>
100+
<version>2.17.2</version>
101+
</dependency>
102+
</dependencies>
103+
</plugin>
104+
</plugins>
105+
</build>
106+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2022 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+
package software.amazon.lambda.powertools.e2e;
15+
16+
import java.util.ArrayList;
17+
import java.util.Arrays;
18+
import java.util.List;
19+
import java.util.Objects;
20+
21+
public class Basket {
22+
private List<Product> products = new ArrayList<>();
23+
24+
public List<Product> getProducts() {
25+
return products;
26+
}
27+
28+
public void setProducts(List<Product> products) {
29+
this.products = products;
30+
}
31+
32+
public Basket() {
33+
}
34+
35+
public Basket( Product ...p){
36+
products.addAll(Arrays.asList(p));
37+
}
38+
39+
public void add(Product product) {
40+
products.add(product);
41+
}
42+
43+
@Override
44+
public boolean equals(Object o) {
45+
if (this == o) return true;
46+
if (o == null || getClass() != o.getClass()) return false;
47+
Basket basket = (Basket) o;
48+
return products.equals(basket.products);
49+
}
50+
51+
@Override
52+
public int hashCode() {
53+
return Objects.hash(products);
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.awssdk.http.urlconnection.UrlConnectionHttpClient;
8+
import software.amazon.awssdk.regions.Region;
9+
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
10+
import software.amazon.lambda.powertools.idempotency.Idempotency;
11+
import software.amazon.lambda.powertools.idempotency.IdempotencyConfig;
12+
import software.amazon.lambda.powertools.idempotency.Idempotent;
13+
import software.amazon.lambda.powertools.idempotency.persistence.DynamoDBPersistenceStore;
14+
15+
16+
public class Function implements RequestHandler<Product, Basket> {
17+
private final static Logger LOG = LogManager.getLogger(Function.class);
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 Basket handleRequest(Product input, Context context) {
41+
LOG.info("Handling product with id {}", input.getId());
42+
Basket b = new Basket();
43+
b.add(input);
44+
return b;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2022 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+
package software.amazon.lambda.powertools.e2e;
15+
16+
import java.util.Objects;
17+
18+
public class Product {
19+
private long id;
20+
21+
private String name;
22+
23+
private double price;
24+
25+
public Product() {
26+
}
27+
28+
public Product(long id, String name, double price) {
29+
this.id = id;
30+
this.name = name;
31+
this.price = price;
32+
}
33+
34+
public long getId() {
35+
return id;
36+
}
37+
38+
public void setId(long id) {
39+
this.id = id;
40+
}
41+
42+
public String getName() {
43+
return name;
44+
}
45+
46+
public void setName(String name) {
47+
this.name = name;
48+
}
49+
50+
public double getPrice() {
51+
return price;
52+
}
53+
54+
public void setPrice(double price) {
55+
this.price = price;
56+
}
57+
58+
@Override
59+
public boolean equals(Object o) {
60+
if (this == o) return true;
61+
if (o == null || getClass() != o.getClass()) return false;
62+
Product product = (Product) o;
63+
return id == product.id && Double.compare(product.price, price) == 0 && Objects.equals(name, product.name);
64+
}
65+
66+
@Override
67+
public int hashCode() {
68+
return Objects.hash(id, name, price);
69+
}
70+
}
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="DEBUG">
10+
<AppenderRef ref="JsonAppender"/>
11+
</Root>
12+
<Logger name="JsonLogger" level="INFO" additivity="false">
13+
<AppenderRef ref="JsonAppender"/>
14+
</Logger>
15+
</Loggers>
16+
</Configuration>

0 commit comments

Comments
 (0)