Skip to content

Commit 6e2aef7

Browse files
authored
Speedup SB smoke test (#62)
* Speedup SB smoke test Signed-off-by: Pavol Loffay <[email protected]> * fixes Signed-off-by: Pavol Loffay <[email protected]>
1 parent b618970 commit 6e2aef7

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

smoke-tests/src/test/java/org/hypertrace/agent/smoketest/AbstractSmokeTest.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.testcontainers.containers.output.Slf4jLogConsumer;
4343
import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException;
4444
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
45+
import org.testcontainers.utility.DockerImageName;
4546
import org.testcontainers.utility.MountableFile;
4647

4748
public abstract class AbstractSmokeTest {
@@ -61,7 +62,6 @@ public abstract class AbstractSmokeTest {
6162
private static final Network network = Network.newNetwork();
6263
private static OpenTelemetryCollector collector;
6364
private static OpenTelemetryStorage openTelemetryStorage;
64-
protected GenericContainer target;
6565

6666
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
6767
protected OkHttpClient client =
@@ -123,18 +123,16 @@ GenericContainer createAppUnderTest(int jdk) {
123123
"agentPath is not set, configure it via env var SMOKETEST_JAVAAGENT_PATH");
124124
}
125125
log.info("Agent path {}", agentPath);
126-
target =
127-
new GenericContainer<>(getTargetImage(jdk))
128-
.withExposedPorts(8080)
129-
.withNetwork(network)
130-
.withLogConsumer(new Slf4jLogConsumer(log))
131-
.withCopyFileToContainer(MountableFile.forHostPath(agentPath), "/javaagent.jar")
132-
.withEnv("JAVA_TOOL_OPTIONS", "-javaagent:/javaagent.jar")
133-
.withEnv("OTEL_BSP_MAX_EXPORT_BATCH", "1")
134-
.withEnv("OTEL_BSP_SCHEDULE_DELAY", "10")
135-
.withEnv("OTEL_EXPORTER_ZIPKIN_ENDPOINT", OTEL_EXPORTER_ENDPOINT)
136-
.withEnv("OTEL_EXPORTER", OTEL_EXPORTER);
137-
return target;
126+
return new GenericContainer<>(DockerImageName.parse(getTargetImage(jdk)))
127+
.withExposedPorts(8080)
128+
.withNetwork(network)
129+
.withLogConsumer(new Slf4jLogConsumer(log))
130+
.withCopyFileToContainer(MountableFile.forHostPath(agentPath), "/javaagent.jar")
131+
.withEnv("JAVA_TOOL_OPTIONS", "-javaagent:/javaagent.jar")
132+
.withEnv("OTEL_BSP_MAX_EXPORT_BATCH", "1")
133+
.withEnv("OTEL_BSP_SCHEDULE_DELAY", "10")
134+
.withEnv("OTEL_EXPORTER_ZIPKIN_ENDPOINT", OTEL_EXPORTER_ENDPOINT)
135+
.withEnv("OTEL_EXPORTER", OTEL_EXPORTER);
138136
}
139137

140138
protected static int countSpansByName(

smoke-tests/src/test/java/org/hypertrace/agent/smoketest/OpenTelemetryCollector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Set;
2121
import org.testcontainers.containers.GenericContainer;
2222
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
23+
import org.testcontainers.utility.DockerImageName;
2324

2425
public class OpenTelemetryCollector extends GenericContainer<OpenTelemetryCollector> {
2526

@@ -29,7 +30,7 @@ public class OpenTelemetryCollector extends GenericContainer<OpenTelemetryCollec
2930
public static final int HEALTH_CHECK_PORT = 13133;
3031

3132
public OpenTelemetryCollector(String dockerImage) {
32-
super(dockerImage);
33+
super(DockerImageName.parse(dockerImage));
3334
init();
3435
}
3536

smoke-tests/src/test/java/org/hypertrace/agent/smoketest/OpenTelemetryStorage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818

1919
import org.testcontainers.containers.GenericContainer;
2020
import org.testcontainers.containers.wait.strategy.Wait;
21+
import org.testcontainers.utility.DockerImageName;
2122

2223
/** @author Pavol Loffay */
2324
public class OpenTelemetryStorage extends GenericContainer<OpenTelemetryStorage> {
2425
public static final int PORT = 8080;
2526

2627
public OpenTelemetryStorage(String dockerImage) {
27-
super(dockerImage);
28+
super(DockerImageName.parse(dockerImage));
2829
init();
2930
}
3031

smoke-tests/src/test/java/org/hypertrace/agent/smoketest/SpringBootDisabledBodyCaptureTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void afterEach() {
5757
@Test
5858
public void springBootSmokeTest() throws IOException {
5959
// TODO test with multiple JDK (11, 14)
60-
String url = String.format("http://localhost:%d/greeting", target.getMappedPort(8080));
60+
String url = String.format("http://localhost:%d/greeting", app.getMappedPort(8080));
6161
Request request = new Request.Builder().url(url).get().build();
6262

6363
Response response = client.newCall(request).execute();

smoke-tests/src/test/java/org/hypertrace/agent/smoketest/SpringBootTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.util.stream.Collectors;
2626
import okhttp3.Request;
2727
import okhttp3.Response;
28-
import org.junit.jupiter.api.AfterEach;
28+
import org.junit.jupiter.api.AfterAll;
2929
import org.junit.jupiter.api.Assertions;
3030
import org.junit.jupiter.api.BeforeEach;
3131
import org.junit.jupiter.api.Test;
@@ -38,25 +38,27 @@ protected String getTargetImage(int jdk) {
3838
return "open-telemetry-docker-dev.bintray.io/java/smoke-springboot-jdk" + jdk + ":latest";
3939
}
4040

41-
private GenericContainer app;
41+
private static GenericContainer app;
4242

4343
@BeforeEach
4444
void beforeEach() {
45-
app = createAppUnderTest(8);
46-
app.start();
45+
if (app == null) {
46+
// TODO test with JDK (11, 14)
47+
app = createAppUnderTest(8);
48+
app.start();
49+
}
4750
}
4851

49-
@AfterEach
50-
void afterEach() {
52+
@AfterAll
53+
static void afterEach() {
5154
if (app != null) {
5255
app.stop();
5356
}
5457
}
5558

5659
@Test
5760
public void springBootSmokeTest() throws IOException {
58-
// TODO test with multiple JDK (11, 14)
59-
String url = String.format("http://localhost:%d/greeting", target.getMappedPort(8080));
61+
String url = String.format("http://localhost:%d/greeting", app.getMappedPort(8080));
6062
Request request = new Request.Builder().url(url).get().build();
6163

6264
Response response = client.newCall(request).execute();
@@ -106,7 +108,7 @@ public void springBootSmokeTest() throws IOException {
106108

107109
@Test
108110
public void springBootMockBlockingTest() throws IOException {
109-
String url = String.format("http://localhost:%d/greeting", target.getMappedPort(8080));
111+
String url = String.format("http://localhost:%d/greeting", app.getMappedPort(8080));
110112
Request request = new Request.Builder().url(url).addHeader("block", "true").get().build();
111113
Response response = client.newCall(request).execute();
112114
Collection<ExportTraceServiceRequest> traces = waitForTraces();

0 commit comments

Comments
 (0)