Skip to content

Commit 3aea275

Browse files
committed
Add unit tests
1 parent 95b82cc commit 3aea275

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

  • dd-java-agent/instrumentation/spark/spark-common/src

dd-java-agent/instrumentation/spark/spark-common/src/main/java/datadog/trace/instrumentation/spark/EmrUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
1010

11-
/** Extracts the AWS EMR Step ID from the working directory name (e.g. {@code s-0039...}). */
11+
/** Extracts the AWS EMR Step ID from the working directory name (e.g. s-07767992IY7VC5NVV854). */
1212
class EmrUtils {
1313

1414
private static final Logger log = LoggerFactory.getLogger(EmrUtils.class);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package datadog.trace.instrumentation.spark;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNull;
5+
6+
import org.junit.jupiter.api.AfterEach;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
9+
10+
class EmrUtilsTest {
11+
12+
private String originalUserDir;
13+
14+
@BeforeEach
15+
void saveUserDir() {
16+
originalUserDir = System.getProperty("user.dir");
17+
}
18+
19+
@AfterEach
20+
void restoreUserDir() {
21+
System.setProperty("user.dir", originalUserDir);
22+
}
23+
24+
@Test
25+
void returnsStepIdWhenWorkdirMatchesEmrPattern() {
26+
System.setProperty("user.dir", "/mnt/var/lib/hadoop/steps/s-07767992IY7VC5NVV854");
27+
assertEquals("s-07767992IY7VC5NVV854", EmrUtils.getEmrStepId());
28+
}
29+
30+
@Test
31+
void returnsNullWhenWorkdirDoesNotMatchEmrPattern() {
32+
System.setProperty("user.dir", "/home/hadoop");
33+
assertNull(EmrUtils.getEmrStepId());
34+
}
35+
36+
@Test
37+
void returnsNullForApplicationIdWorkdir() {
38+
System.setProperty("user.dir", "/home/hadoop/application_1234567890_0001");
39+
assertNull(EmrUtils.getEmrStepId());
40+
}
41+
}

0 commit comments

Comments
 (0)