Skip to content

Commit 5b33d85

Browse files
committed
removed logback testing solution and test the annotation not logging
1 parent 391c9cf commit 5b33d85

File tree

2 files changed

+10
-52
lines changed

2 files changed

+10
-52
lines changed

powertools-tracing/pom.xml

-11
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@
4848
</developer>
4949
</developers>
5050

51-
<properties>
52-
<logback.version>1.2.11</logback.version>
53-
</properties>
54-
5551
<distributionManagement>
5652
<snapshotRepository>
5753
<id>ossrh</id>
@@ -119,13 +115,6 @@
119115
<artifactId>assertj-core</artifactId>
120116
<scope>test</scope>
121117
</dependency>
122-
<dependency>
123-
<groupId>ch.qos.logback</groupId>
124-
<artifactId>logback-classic</artifactId>
125-
<version>${logback.version}</version>
126-
<scope>test</scope>
127-
</dependency>
128-
129118
</dependencies>
130119

131120
<build>

powertools-tracing/src/test/java/software/amazon/lambda/powertools/tracing/TracingUtilsTest.java

+10-41
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,14 @@
2020
import static org.mockito.Mockito.verify;
2121
import static software.amazon.lambda.powertools.tracing.TracingUtils.withEntitySubsegment;
2222

23-
import ch.qos.logback.classic.Level;
24-
import ch.qos.logback.classic.Logger;
25-
import ch.qos.logback.classic.spi.ILoggingEvent;
26-
import ch.qos.logback.core.read.ListAppender;
2723
import com.amazonaws.services.lambda.runtime.Context;
2824
import com.amazonaws.xray.AWSXRay;
2925
import com.amazonaws.xray.entities.Entity;
30-
import java.util.List;
3126
import org.junit.jupiter.api.AfterEach;
3227
import org.junit.jupiter.api.BeforeEach;
3328
import org.junit.jupiter.api.Test;
34-
import org.slf4j.LoggerFactory;
3529

3630
class TracingUtilsTest {
37-
3831
@BeforeEach
3932
void setUp() {
4033
AWSXRay.beginSegment("test");
@@ -130,45 +123,21 @@ void shouldInvokeCodeBlockWrappedWithinSubsegment() {
130123
}
131124

132125
@Test
133-
void shouldEmitNoLogWarnIfValidCharacterInKey() {
126+
void shouldNotAddAnnotationIfInvalidCharacterInKey() {
134127
AWSXRay.beginSubsegment("subSegment");
135-
Logger logger = (Logger) LoggerFactory.getLogger(TracingUtils.class);
136-
137-
// create and start a ListAppender
138-
ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
139-
listAppender.start();
140-
141-
// add the appender to the logger
142-
logger.addAppender(listAppender);
143-
144-
TracingUtils.putAnnotation("stringKey", "val");
145-
146-
List<ILoggingEvent> logsList = listAppender.list;
147-
assertThat(AWSXRay.getTraceEntity().getAnnotations())
148-
.hasSize(1)
149-
.contains(
150-
entry("stringKey", "val")
151-
);
152-
assertThat(logsList.size()).isZero();
128+
String inputKey = "stringKey with spaces";
129+
TracingUtils.putAnnotation(inputKey, "val");
130+
AWSXRay.getCurrentSubsegmentOptional()
131+
.ifPresent(segment -> assertThat(segment.getAnnotations()).size().isEqualTo(0));
153132
}
154133

155134
@Test
156-
void shouldEmitLogWarnIfInvalidCharacterInKey() {
135+
void shouldAddAnnotationIfValidCharactersInKey() {
157136
AWSXRay.beginSubsegment("subSegment");
158-
Logger logger = (Logger) LoggerFactory.getLogger(TracingUtils.class);
159-
160-
// create and start a ListAppender
161-
ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
162-
listAppender.start();
163-
164-
// add the appender to the logger
165-
logger.addAppender(listAppender);
166-
String inputKey = "stringKey with spaces";
137+
String inputKey = "validKey";
167138
TracingUtils.putAnnotation(inputKey, "val");
168-
169-
List<ILoggingEvent> logsList = listAppender.list;
170-
assertThat(logsList.get(0).getLevel()).isEqualTo(Level.WARN);
171-
assertThat(logsList.get(0).getMessage()).isEqualTo("Ignoring annotation with unsupported characters in key: {}",inputKey);
139+
AWSXRay.getCurrentSubsegmentOptional()
140+
.ifPresent(segment -> assertThat(segment.getAnnotations()).size().isEqualTo(1));
172141
}
173142

174143
@Test
@@ -269,4 +238,4 @@ void shouldInvokeCodeBlockWrappedWithinNamespacedEntitySubsegment() throws Inter
269238
.containsEntry("key", "val");
270239
});
271240
}
272-
}
241+
}

0 commit comments

Comments
 (0)