99import static io .opentelemetry .instrumentation .jmx .rules .assertions .DataPointAttributes .attributeGroup ;
1010
1111import io .opentelemetry .instrumentation .jmx .rules .assertions .AttributeMatcher ;
12+ import java .io .IOException ;
13+ import java .net .URISyntaxException ;
14+ import java .nio .file .Files ;
15+ import java .nio .file .Path ;
16+ import java .nio .file .Paths ;
1217import java .time .Duration ;
1318import java .util .Collections ;
1419import java .util .List ;
20+ import java .util .stream .Collectors ;
21+ import java .util .stream .Stream ;
1522import org .junit .jupiter .api .Test ;
1623import org .testcontainers .containers .GenericContainer ;
1724import org .testcontainers .containers .wait .strategy .Wait ;
18- import org .testcontainers .utility . MountableFile ;
25+ import org .testcontainers .images . builder . Transferable ;
1926
2027class HadoopTest extends TargetSystemTest {
28+
29+ public static final String ENDPOINT_PLACEHOLDER = "<<ENDPOINT_PLACEHOLDER>>" ;
30+
2131 @ Test
22- void testMetrics_Hadoop2x () {
32+ void testMetrics_Hadoop2x () throws URISyntaxException , IOException {
2333 List <String > yamlFiles = Collections .singletonList ("hadoop.yaml" );
2434
2535 yamlFiles .forEach (this ::validateYamlSyntax );
@@ -28,9 +38,7 @@ void testMetrics_Hadoop2x() {
2838 // so all the env vars needs to be embedded inside the hadoop-env.sh file
2939 GenericContainer <?> target =
3040 new GenericContainer <>("bmedora/hadoop:2.9-base" )
31- .withCopyFileToContainer (
32- MountableFile .forClasspathResource ("hadoop2-env.sh" , 0400 ),
33- "/hadoop/etc/hadoop/hadoop-env.sh" )
41+ .withCopyToContainer (Transferable .of (readAndPreprocessEnvFile ("hadoop2-env.sh" )), "/hadoop/etc/hadoop/hadoop-env.sh" )
3442 .withCreateContainerCmdModifier (cmd -> cmd .withHostName ("test-host" ))
3543 .withStartupTimeout (Duration .ofMinutes (3 ))
3644 .withExposedPorts (50070 )
@@ -44,8 +52,21 @@ void testMetrics_Hadoop2x() {
4452 verifyMetrics (createMetricsVerifier ());
4553 }
4654
55+ private String readAndPreprocessEnvFile (String fileName ) throws URISyntaxException , IOException {
56+ Path path = Paths .get (getClass ().getClassLoader ().getResource (fileName ).toURI ());
57+
58+ String data ;
59+ try (Stream <String > lines = Files .lines (path )) {
60+ data = lines
61+ .map (line -> line .replace (ENDPOINT_PLACEHOLDER , otlpEndpoint ))
62+ .collect (Collectors .joining ("\n " ));
63+ }
64+
65+ return data ;
66+ }
67+
4768 @ Test
48- void testMetrics_Hadoop3x () {
69+ void testMetrics_Hadoop3x () throws URISyntaxException , IOException {
4970 List <String > yamlFiles = Collections .singletonList ("hadoop.yaml" );
5071
5172 yamlFiles .forEach (this ::validateYamlSyntax );
@@ -55,9 +76,7 @@ void testMetrics_Hadoop3x() {
5576 GenericContainer <?> target =
5677 new GenericContainer <>("loum/hadoop-pseudo:3.3.6" )
5778 .withExposedPorts (9870 , 9000 )
58- .withCopyFileToContainer (
59- MountableFile .forClasspathResource ("hadoop3-env.sh" , 0644 ),
60- "/opt/hadoop/etc/hadoop/hadoop-env.sh" )
79+ .withCopyToContainer (Transferable .of (readAndPreprocessEnvFile ("hadoop3-env.sh" )), "/opt/hadoop/etc/hadoop/hadoop-env.sh" )
6180 .withCreateContainerCmdModifier (cmd -> cmd .withHostName ("test-host" ))
6281 .waitingFor (
6382 Wait .forListeningPorts (9870 , 9000 ).withStartupTimeout (Duration .ofMinutes (3 )));
0 commit comments