Skip to content

Commit 011201c

Browse files
zeitlingerlaurit
andauthored
convert groovy smoke tests to java, part 1 (#14648)
Co-authored-by: Lauri Tulmin <[email protected]>
1 parent 17a0bde commit 011201c

File tree

15 files changed

+1219
-922
lines changed

15 files changed

+1219
-922
lines changed

smoke-tests/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ dependencies {
3737
testImplementation("com.github.docker-java:docker-java-core:$dockerJavaVersion")
3838
testImplementation("com.github.docker-java:docker-java-transport-httpclient5:$dockerJavaVersion")
3939

40-
// make IntelliJ see shaded Armeria
40+
// make IntelliJ see shaded Armeria and protobuf
4141
testCompileOnly(project(":testing:armeria-shaded-for-testing", configuration = "shadow"))
42+
testCompileOnly(project(":testing:proto-shaded-for-testing", configuration = "shadow"))
4243
}
4344

4445
tasks {

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

Lines changed: 0 additions & 33 deletions
This file was deleted.

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

Lines changed: 0 additions & 54 deletions
This file was deleted.

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

Lines changed: 0 additions & 61 deletions
This file was deleted.

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

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.smoketest;
7+
8+
import java.time.Duration;
9+
import org.junit.jupiter.api.DisplayName;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.condition.DisabledIf;
12+
13+
@DisabledIf("io.opentelemetry.smoketest.TestContainerManager#useWindowsContainers")
14+
class AgentDebugLoggingTest extends JavaSmokeTest {
15+
@Override
16+
protected String getTargetImage(String jdk) {
17+
return "ghcr.io/open-telemetry/opentelemetry-java-instrumentation/smoke-test-spring-boot:jdk"
18+
+ jdk
19+
+ "-20250915.17728045097";
20+
}
21+
22+
@Override
23+
protected TargetWaitStrategy getWaitStrategy() {
24+
return new TargetWaitStrategy.Log(
25+
Duration.ofMinutes(1), ".*DEBUG io.opentelemetry.javaagent.tooling.VersionLogger.*");
26+
}
27+
28+
@DisplayName("verifies that debug logging is working by checking for a debug log on startup")
29+
@Test
30+
void verifyLogging() throws Exception {
31+
withTarget(8, () -> {});
32+
}
33+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.smoketest;
7+
8+
import static java.util.Collections.emptyList;
9+
import static java.util.Collections.emptyMap;
10+
11+
import io.opentelemetry.sdk.logs.data.LogRecordData;
12+
import io.opentelemetry.sdk.metrics.data.MetricData;
13+
import io.opentelemetry.sdk.trace.data.SpanData;
14+
import io.opentelemetry.smoketest.windows.WindowsTestContainerManager;
15+
import io.opentelemetry.testing.internal.armeria.client.WebClient;
16+
import java.util.Collection;
17+
import java.util.List;
18+
import java.util.Map;
19+
import java.util.function.Consumer;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.testcontainers.containers.output.OutputFrame;
22+
23+
public abstract class JavaSmokeTest {
24+
protected static final TestContainerManager containerManager = createContainerManager();
25+
private JavaTelemetryRetriever telemetryRetriever;
26+
27+
protected String agentPath =
28+
System.getProperty("io.opentelemetry.smoketest.agent.shadowJar.path");
29+
30+
protected WebClient client() {
31+
return WebClient.of("h1c://localhost:" + containerManager.getTargetMappedPort(8080));
32+
}
33+
34+
/** Subclasses can override this method to pass jvm arguments in another environment variable */
35+
protected String getJvmArgsEnvVarName() {
36+
return "JAVA_TOOL_OPTIONS";
37+
}
38+
39+
/** Subclasses can override this method to customise target application's environment */
40+
protected Map<String, String> getExtraEnv() {
41+
return emptyMap();
42+
}
43+
44+
/** Subclasses can override this method to disable setting default service name */
45+
protected boolean getSetServiceName() {
46+
return true;
47+
}
48+
49+
/** Subclasses can override this method to provide additional files to copy to target container */
50+
protected List<ResourceMapping> getExtraResources() {
51+
return emptyList();
52+
}
53+
54+
/**
55+
* Subclasses can override this method to provide additional ports that should be exposed from the
56+
* target container
57+
*/
58+
protected List<Integer> getExtraPorts() {
59+
return emptyList();
60+
}
61+
62+
@BeforeEach
63+
void setUp() {
64+
containerManager.startEnvironmentOnce();
65+
telemetryRetriever = new JavaTelemetryRetriever(containerManager.getBackendMappedPort());
66+
}
67+
68+
public void withTarget(int jdk, TargetRunner runner) throws Exception {
69+
startTarget(jdk);
70+
try {
71+
runner.runInTarget();
72+
} finally {
73+
stopTarget();
74+
}
75+
}
76+
77+
public Consumer<OutputFrame> startTarget(int jdk) {
78+
return startTarget(String.valueOf(jdk), null, false);
79+
}
80+
81+
public Consumer<OutputFrame> startTarget(String jdk, String serverVersion, boolean windows) {
82+
String targetImage = getTargetImage(jdk, serverVersion, windows);
83+
return containerManager.startTarget(
84+
targetImage,
85+
agentPath,
86+
getJvmArgsEnvVarName(),
87+
getExtraEnv(),
88+
getSetServiceName(),
89+
getExtraResources(),
90+
getExtraPorts(),
91+
getWaitStrategy(),
92+
getCommand());
93+
}
94+
95+
protected abstract String getTargetImage(String jdk);
96+
97+
protected String getTargetImage(String jdk, String serverVersion, boolean windows) {
98+
return getTargetImage(jdk);
99+
}
100+
101+
protected TargetWaitStrategy getWaitStrategy() {
102+
return null;
103+
}
104+
105+
protected String[] getCommand() {
106+
return null;
107+
}
108+
109+
public void cleanup() {
110+
telemetryRetriever.clearTelemetry();
111+
}
112+
113+
public void stopTarget() {
114+
containerManager.stopTarget();
115+
cleanup();
116+
}
117+
118+
protected List<SpanData> waitForTraces() {
119+
return telemetryRetriever.waitForTraces();
120+
}
121+
122+
protected Collection<MetricData> waitForMetrics() {
123+
return telemetryRetriever.waitForMetrics();
124+
}
125+
126+
protected Collection<LogRecordData> waitForLogs() {
127+
return telemetryRetriever.waitForLogs();
128+
}
129+
130+
private static TestContainerManager createContainerManager() {
131+
return TestContainerManager.useWindowsContainers()
132+
? new WindowsTestContainerManager()
133+
: new LinuxTestContainerManager();
134+
}
135+
}

0 commit comments

Comments
 (0)