Skip to content

Commit 3435a1c

Browse files
committed
url connection
1 parent d65df47 commit 3435a1c

File tree

2 files changed

+109
-93
lines changed

2 files changed

+109
-93
lines changed

smoke-tests/src/test/groovy/io/opentelemetry/smoketest/IbmHttpsUrlConnectionTest.groovy

Lines changed: 0 additions & 93 deletions
This file was deleted.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.smoketest;
7+
8+
import static io.opentelemetry.sdk.testing.assertj.TracesAssert.assertThat;
9+
10+
import io.opentelemetry.api.trace.SpanKind;
11+
import java.time.Duration;
12+
import org.assertj.core.api.Assertions;
13+
import org.junit.jupiter.api.AfterEach;
14+
import org.junit.jupiter.api.BeforeEach;
15+
import org.junit.jupiter.api.Test;
16+
import org.junit.jupiter.api.condition.DisabledIf;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
import org.testcontainers.containers.Container;
20+
import org.testcontainers.containers.GenericContainer;
21+
import org.testcontainers.containers.Network;
22+
import org.testcontainers.containers.output.Slf4jLogConsumer;
23+
import org.testcontainers.containers.wait.strategy.Wait;
24+
import org.testcontainers.utility.DockerImageName;
25+
import org.testcontainers.utility.MountableFile;
26+
27+
@DisabledIf("io.opentelemetry.smoketest.TestContainerManager#useWindowsContainers")
28+
class IbmHttpsUrlConnectionTest {
29+
private static final Logger logger = LoggerFactory.getLogger(IbmHttpsUrlConnectionTest.class);
30+
31+
private static final String TARGET_AGENT_FILENAME = "opentelemetry-javaagent.jar";
32+
private static final String agentPath =
33+
System.getProperty("io.opentelemetry.smoketest.agent.shadowJar.path");
34+
private static final int BACKEND_PORT = 8080;
35+
private static final String BACKEND_ALIAS = "backend";
36+
37+
private Network network;
38+
private GenericContainer<?> backend;
39+
private GenericContainer<?> target;
40+
private Container.ExecResult result;
41+
private TelemetryRetriever telemetryRetriever;
42+
43+
@BeforeEach
44+
void setUp() {
45+
network = Network.newNetwork();
46+
backend =
47+
new GenericContainer<>(
48+
DockerImageName.parse(
49+
"ghcr.io/open-telemetry/opentelemetry-java-instrumentation/smoke-test-fake-backend:20250811.16876216352"))
50+
.withExposedPorts(BACKEND_PORT)
51+
.withEnv("JAVA_TOOL_OPTIONS", "-Xmx128m")
52+
.waitingFor(Wait.forHttp("/health").forPort(BACKEND_PORT))
53+
.withNetwork(network)
54+
.withNetworkAliases(BACKEND_ALIAS)
55+
.withLogConsumer(new Slf4jLogConsumer(logger));
56+
backend.start();
57+
telemetryRetriever =
58+
new TelemetryRetriever(backend.getMappedPort(BACKEND_PORT), Duration.ofSeconds(30));
59+
60+
target =
61+
new GenericContainer<>(DockerImageName.parse("ibmjava:8-sdk"))
62+
.withStartupTimeout(Duration.ofMinutes(5))
63+
.withNetwork(network)
64+
.withLogConsumer(new Slf4jLogConsumer(logger))
65+
.withCopyFileToContainer(
66+
MountableFile.forHostPath(agentPath), "/" + TARGET_AGENT_FILENAME)
67+
.withCopyFileToContainer(
68+
MountableFile.forClasspathResource(
69+
"ibmhttpsurlconnection/IbmHttpsUrlConnectionTest.java"),
70+
"/IbmHttpsUrlConnectionTest.java")
71+
.withCopyFileToContainer(
72+
MountableFile.forClasspathResource("ibmhttpsurlconnection/start.sh", 777),
73+
"/start.sh")
74+
.withCopyFileToContainer(
75+
MountableFile.forClasspathResource("ibmhttpsurlconnection/test.sh", 777),
76+
"/test.sh")
77+
.waitingFor(Wait.forLogMessage(".*started.*\\n", 1))
78+
.withCommand("/bin/sh", "-c", "/start.sh");
79+
target.start();
80+
}
81+
82+
@Test
83+
void testHttpsUrlConnection() throws Exception {
84+
result = target.execInContainer("/bin/sh", "-c", "/test.sh");
85+
Assertions.assertThat(result.getExitCode()).isZero();
86+
87+
assertThat(telemetryRetriever.waitForTraces())
88+
.hasTracesSatisfyingExactly(
89+
trace ->
90+
trace.hasSpansSatisfyingExactly(
91+
span -> span.hasName("GET").hasKind(SpanKind.CLIENT).hasNoParent()));
92+
}
93+
94+
@AfterEach
95+
void tearDown() {
96+
if (result != null) {
97+
System.err.println(result);
98+
}
99+
if (target != null) {
100+
target.stop();
101+
}
102+
if (backend != null) {
103+
backend.stop();
104+
}
105+
if (network != null) {
106+
network.close();
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)