Skip to content

Commit 74fa661

Browse files
committed
fix tests
1 parent 46e76f9 commit 74fa661

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/MetricsUtils.java

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package software.amazon.lambda.powertools.metrics;
1616

17-
import static java.util.Objects.requireNonNull;
1817
import static java.util.Optional.ofNullable;
1918
import static software.amazon.lambda.powertools.common.internal.LambdaHandlerProcessor.getXrayTraceId;
2019
import static software.amazon.lambda.powertools.metrics.internal.LambdaMetricsAspect.REQUEST_ID_PROPERTY;

powertools-tracing/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@
7878
<artifactId>junit-jupiter-engine</artifactId>
7979
<scope>test</scope>
8080
</dependency>
81+
<dependency>
82+
<groupId>org.junit-pioneer</groupId>
83+
<artifactId>junit-pioneer</artifactId>
84+
<scope>test</scope>
85+
</dependency>
8186
<dependency>
8287
<groupId>org.apache.commons</groupId>
8388
<artifactId>commons-lang3</artifactId>

powertools-tracing/src/test/java/software/amazon/lambda/powertools/tracing/internal/LambdaTracingAspectTest.java

+43
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.junit.jupiter.api.BeforeAll;
3434
import org.junit.jupiter.api.BeforeEach;
3535
import org.junit.jupiter.api.Test;
36+
import org.junitpioneer.jupiter.SetEnvironmentVariable;
3637
import org.mockito.Mock;
3738
import org.mockito.MockedStatic;
3839
import software.amazon.lambda.powertools.common.internal.LambdaHandlerProcessor;
@@ -113,6 +114,28 @@ void shouldCaptureNonHandlerMethodWithCustomSegmentName() {
113114
void shouldCaptureTraces() {
114115
requestHandler.handleRequest(new Object(), context);
115116

117+
assertThat(AWSXRay.getTraceEntity())
118+
.isNotNull();
119+
120+
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
121+
.hasSize(1)
122+
.allSatisfy(subsegment ->
123+
{
124+
assertThat(subsegment.getAnnotations())
125+
.hasSize(2)
126+
.containsEntry("ColdStart", true)
127+
.containsEntry("Service", "lambdaHandler");
128+
129+
assertThat(subsegment.getMetadata())
130+
.hasSize(0);
131+
});
132+
}
133+
134+
@Test
135+
@SetEnvironmentVariable(key = "POWERTOOLS_TRACER_CAPTURE_RESPONSE", value = "true")
136+
void shouldCaptureTracesWithResponseMetadata() {
137+
requestHandler.handleRequest(new Object(), context);
138+
116139
assertThat(AWSXRay.getTraceEntity())
117140
.isNotNull();
118141

@@ -132,6 +155,7 @@ void shouldCaptureTraces() {
132155
}
133156

134157
@Test
158+
@SetEnvironmentVariable(key = "POWERTOOLS_TRACER_CAPTURE_ERROR", value = "true")
135159
void shouldCaptureTracesWithExceptionMetaData() {
136160
requestHandler = new PowerTracerToolEnabledWithException();
137161

@@ -163,6 +187,25 @@ void shouldCaptureTracesWithExceptionMetaData() {
163187
void shouldCaptureTracesForStream() throws IOException {
164188
streamHandler.handleRequest(new ByteArrayInputStream("test".getBytes()), new ByteArrayOutputStream(), context);
165189

190+
assertThat(AWSXRay.getTraceEntity())
191+
.isNotNull();
192+
193+
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
194+
.hasSize(1)
195+
.allSatisfy(subsegment ->
196+
{
197+
assertThat(subsegment.getAnnotations())
198+
.hasSize(2)
199+
.containsEntry("ColdStart", true)
200+
.containsEntry("Service", "streamHandler");
201+
});
202+
}
203+
204+
@Test
205+
@SetEnvironmentVariable(key = "POWERTOOLS_TRACER_CAPTURE_RESPONSE", value = "true")
206+
void shouldCaptureTracesForStreamWithResponseMetadata() throws IOException {
207+
streamHandler.handleRequest(new ByteArrayInputStream("test".getBytes()), new ByteArrayOutputStream(), context);
208+
166209
assertThat(AWSXRay.getTraceEntity())
167210
.isNotNull();
168211

0 commit comments

Comments
 (0)