Skip to content

Commit f680d06

Browse files
committed
refactoring
1 parent 4a4a533 commit f680d06

File tree

13 files changed

+298
-168
lines changed

13 files changed

+298
-168
lines changed

powertools-e2e-tests/pom.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,9 @@
1717
<maven.compiler.target>11</maven.compiler.target>
1818
<constructs.version>10.1.138</constructs.version>
1919
<cdk.version>2.47.0</cdk.version>
20-
<lombok.version>1.18.24</lombok.version>
2120
</properties>
2221

2322
<dependencies>
24-
<dependency>
25-
<groupId>org.projectlombok</groupId>
26-
<artifactId>lombok</artifactId>
27-
<version>${lombok.version}</version>
28-
<scope>provided</scope>
29-
</dependency>
30-
3123
<dependency>
3224
<groupId>ch.qos.logback</groupId>
3325
<artifactId>logback-classic</artifactId>
@@ -144,13 +136,6 @@
144136
<configuration>
145137
<source>${maven.compiler.source}</source>
146138
<target>${maven.compiler.target}</target>
147-
<annotationProcessorPaths>
148-
<path>
149-
<groupId>org.projectlombok</groupId>
150-
<artifactId>lombok</artifactId>
151-
<version>${lombok.version}</version>
152-
</path>
153-
</annotationProcessorPaths>
154139
<encoding>UTF-8</encoding>
155140
</configuration>
156141
</plugin>

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/IdempotencyE2ETest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
import org.junit.jupiter.api.Test;
77
import org.junit.jupiter.api.Timeout;
88
import software.amazon.lambda.powertools.testutils.Infrastructure;
9-
import software.amazon.lambda.powertools.testutils.InvocationResult;
9+
import software.amazon.lambda.powertools.testutils.lambda.InvocationResult;
1010

1111
import java.time.Year;
1212
import java.util.HashMap;
1313
import java.util.concurrent.TimeUnit;
1414

15+
import static software.amazon.lambda.powertools.testutils.lambda.LambdaInvoker.invokeFunction;
16+
1517
public class IdempotencyE2ETest {
1618
private static Infrastructure infrastructure;
19+
private static String functionName;
1720

1821
@BeforeAll
1922
@Timeout(value = 5, unit = TimeUnit.MINUTES)
@@ -27,7 +30,7 @@ public static void setup() {
2730
}}
2831
)
2932
.build();
30-
infrastructure.deploy();
33+
functionName = infrastructure.deploy();
3134
}
3235

3336
@AfterAll
@@ -43,15 +46,15 @@ public void test_ttlNotExpired_sameResult_ttlExpired_differentResult() throws In
4346

4447
// WHEN
4548
// First invocation
46-
InvocationResult result1 = infrastructure.invokeFunction(event);
49+
InvocationResult result1 = invokeFunction(functionName, event);
4750

4851
// Second invocation (should get same result)
49-
InvocationResult result2 = infrastructure.invokeFunction(event);
52+
InvocationResult result2 = invokeFunction(functionName, event);
5053

5154
Thread.sleep(12000);
5255

5356
// Third invocation (should get different result)
54-
InvocationResult result3 = infrastructure.invokeFunction(event);
57+
InvocationResult result3 = invokeFunction(functionName, event);
5558

5659
// THEN
5760
Assertions.assertThat(result1.getResult()).contains(Year.now().toString());

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/LoggingE2ETest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@
88
import org.junit.jupiter.api.Test;
99
import org.junit.jupiter.api.Timeout;
1010
import software.amazon.lambda.powertools.testutils.Infrastructure;
11-
import software.amazon.lambda.powertools.testutils.InvocationResult;
11+
import software.amazon.lambda.powertools.testutils.lambda.InvocationResult;
1212

1313
import java.util.HashMap;
1414
import java.util.UUID;
1515
import java.util.concurrent.TimeUnit;
1616

1717
import static org.assertj.core.api.Assertions.assertThat;
18-
import static software.amazon.lambda.powertools.testutils.InvocationLogs.Level.INFO;
18+
import static software.amazon.lambda.powertools.testutils.lambda.LambdaInvoker.invokeFunction;
19+
import static software.amazon.lambda.powertools.testutils.logging.InvocationLogs.Level.INFO;
1920

2021
public class LoggingE2ETest {
2122

2223
private static final ObjectMapper objectMapper = new ObjectMapper();
24+
2325
private static Infrastructure infrastructure;
26+
private static String functionName;
2427

2528
@BeforeAll
2629
@Timeout(value = 5, unit = TimeUnit.MINUTES)
@@ -34,7 +37,7 @@ public static void setup() {
3437
}}
3538
)
3639
.build();
37-
infrastructure.deploy();
40+
functionName = infrastructure.deploy();
3841
}
3942

4043
@AfterAll
@@ -50,8 +53,8 @@ public void test_logInfoWithAdditionalKeys() throws JsonProcessingException {
5053
String event = "{\"message\":\"New Order\", \"keys\":{\"orderId\":\"" + orderId +"\"}}";
5154

5255
// WHEN
53-
InvocationResult invocationResult1 = infrastructure.invokeFunction(event);
54-
InvocationResult invocationResult2 = infrastructure.invokeFunction(event);
56+
InvocationResult invocationResult1 = invokeFunction(functionName, event);
57+
InvocationResult invocationResult2 = invokeFunction(functionName, event);
5558

5659
// THEN
5760
String[] functionLogs = invocationResult1.getLogs().getFunctionLogs(INFO);

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/MetricsE2ETest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import org.junit.jupiter.api.Test;
66
import org.junit.jupiter.api.Timeout;
77
import software.amazon.lambda.powertools.testutils.Infrastructure;
8-
import software.amazon.lambda.powertools.testutils.InvocationResult;
8+
import software.amazon.lambda.powertools.testutils.lambda.InvocationResult;
9+
import software.amazon.lambda.powertools.testutils.metrics.MetricsFetcher;
910

1011
import java.util.Collections;
1112
import java.util.HashMap;
@@ -14,12 +15,13 @@
1415
import java.util.concurrent.TimeUnit;
1516

1617
import static org.assertj.core.api.Assertions.assertThat;
18+
import static software.amazon.lambda.powertools.testutils.lambda.LambdaInvoker.invokeFunction;
1719

1820
public class MetricsE2ETest {
19-
private static Infrastructure infrastructure;
20-
2121
private static final String namespace = "MetricsE2ENamespace_"+UUID.randomUUID();
2222
private static final String service = "MetricsE2EService_"+UUID.randomUUID();
23+
private static Infrastructure infrastructure;
24+
private static String functionName;
2325

2426
@BeforeAll
2527
@Timeout(value = 5, unit = TimeUnit.MINUTES)
@@ -33,7 +35,7 @@ public static void setup() {
3335
}}
3436
)
3537
.build();
36-
infrastructure.deploy();
38+
functionName = infrastructure.deploy();
3739
}
3840

3941
@AfterAll
@@ -48,18 +50,19 @@ public void test_recordMetrics() {
4850
String event1 = "{ \"metrics\": {\"orders\": 1, \"products\": 4}, \"dimensions\": { \"Environment\": \"test\"} }";
4951

5052
// WHEN
51-
InvocationResult invocationResult = infrastructure.invokeFunction(event1);
53+
InvocationResult invocationResult = invokeFunction(functionName, event1);
5254

5355
// THEN
54-
List<Double> coldStart = infrastructure.getMetrics(invocationResult.getStart(), invocationResult.getEnd(), 60, namespace, "ColdStart", new HashMap<>() {{ put("FunctionName", infrastructure.getFunctionName()); put("Service", service); }});
56+
MetricsFetcher metricsFetcher = new MetricsFetcher();
57+
List<Double> coldStart = metricsFetcher.fetchMetrics(invocationResult.getStart(), invocationResult.getEnd(), 60, namespace, "ColdStart", new HashMap<>() {{ put("FunctionName", functionName); put("Service", service); }});
5558
assertThat(coldStart.get(0)).isEqualTo(1);
56-
List<Double> orderMetrics = infrastructure.getMetrics(invocationResult.getStart(), invocationResult.getEnd(), 60, namespace, "orders", Collections.singletonMap("Environment", "test"));
59+
List<Double> orderMetrics = metricsFetcher.fetchMetrics(invocationResult.getStart(), invocationResult.getEnd(), 60, namespace, "orders", Collections.singletonMap("Environment", "test"));
5760
assertThat(orderMetrics.get(0)).isEqualTo(1);
58-
List<Double> productMetrics = infrastructure.getMetrics(invocationResult.getStart(), invocationResult.getEnd(), 60, namespace, "products", Collections.singletonMap("Environment", "test"));
61+
List<Double> productMetrics = metricsFetcher.fetchMetrics(invocationResult.getStart(), invocationResult.getEnd(), 60, namespace, "products", Collections.singletonMap("Environment", "test"));
5962
assertThat(productMetrics.get(0)).isEqualTo(4);
60-
orderMetrics = infrastructure.getMetrics(invocationResult.getStart(), invocationResult.getEnd(), 60, namespace, "orders", Collections.singletonMap("Service", service));
63+
orderMetrics = metricsFetcher.fetchMetrics(invocationResult.getStart(), invocationResult.getEnd(), 60, namespace, "orders", Collections.singletonMap("Service", service));
6164
assertThat(orderMetrics.get(0)).isEqualTo(1);
62-
productMetrics = infrastructure.getMetrics(invocationResult.getStart(), invocationResult.getEnd(), 60, namespace, "products", Collections.singletonMap("Service", service));
65+
productMetrics = metricsFetcher.fetchMetrics(invocationResult.getStart(), invocationResult.getEnd(), 60, namespace, "products", Collections.singletonMap("Service", service));
6366
assertThat(productMetrics.get(0)).isEqualTo(4);
6467
}
6568
}

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/TracingE2ETest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.junit.jupiter.api.Test;
66
import org.junit.jupiter.api.Timeout;
77
import software.amazon.lambda.powertools.testutils.Infrastructure;
8-
import software.amazon.lambda.powertools.testutils.InvocationResult;
8+
import software.amazon.lambda.powertools.testutils.lambda.InvocationResult;
99
import software.amazon.lambda.powertools.testutils.tracing.SegmentDocument.SubSegment;
1010
import software.amazon.lambda.powertools.testutils.tracing.Trace;
1111
import software.amazon.lambda.powertools.testutils.tracing.TraceFetcher;
@@ -16,11 +16,14 @@
1616
import java.util.concurrent.TimeUnit;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
19+
import static software.amazon.lambda.powertools.testutils.lambda.LambdaInvoker.invokeFunction;
1920

2021
public class TracingE2ETest {
21-
private static Infrastructure infrastructure;
2222
private static final String service = "TracingE2EService_"+UUID.randomUUID(); // "TracingE2EService_e479fb27-422b-4107-9f8c-086c62e1cd12";
2323

24+
private static Infrastructure infrastructure;
25+
private static String functionName;
26+
2427
@BeforeAll
2528
@Timeout(value = 5, unit = TimeUnit.MINUTES)
2629
public static void setup() {
@@ -33,7 +36,7 @@ public static void setup() {
3336
}}
3437
)
3538
.build();
36-
infrastructure.deploy();
39+
functionName = infrastructure.deploy();
3740
}
3841

3942
@AfterAll
@@ -47,19 +50,16 @@ public void test_tracing() {
4750
// GIVEN
4851
String message = "Hello World";
4952
String event = String.format("{\"message\":\"%s\"}", message);
50-
String result = String.format("%s (%s)", message, infrastructure.getFunctionName());
53+
String result = String.format("%s (%s)", message, functionName);
5154

5255
// WHEN
53-
InvocationResult invocationResult = infrastructure.invokeFunction(event);
56+
InvocationResult invocationResult = invokeFunction(functionName, event);
5457

5558
// THEN
5659
Trace trace = TraceFetcher.builder()
5760
.start(invocationResult.getStart())
5861
.end(invocationResult.getEnd())
59-
// .start(Instant.ofEpochSecond(1667468280))
60-
// .end(Instant.ofEpochSecond(1667468340))
61-
.functionName(infrastructure.getFunctionName())
62-
// .functionName("TracingE2ETest-744e0e5ba909-function")
62+
.functionName(functionName)
6363
.build()
6464
.fetchTrace();
6565

0 commit comments

Comments
 (0)