Skip to content

Commit fb42dd0

Browse files
authored
Cleanup tests (#96)
Signed-off-by: Pavol Loffay <[email protected]>
1 parent 6395bc9 commit fb42dd0

File tree

10 files changed

+50
-44
lines changed

10 files changed

+50
-44
lines changed

instrumentation/grpc-1.5/src/test/java/io/opentelemetry/instrumentation/hypertrace/grpc/v1_5/GrpcBodyTest.java renamed to instrumentation/grpc-1.5/src/test/java/io/opentelemetry/instrumentation/hypertrace/grpc/v1_5/GrpcInstrumentationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import org.junit.jupiter.api.Test;
5151
import org.junitpioneer.jupiter.ClearSystemProperty;
5252

53-
public class GrpcBodyTest extends AbstractInstrumenterTest {
53+
public class GrpcInstrumentationTest extends AbstractInstrumenterTest {
5454

5555
private static final Helloworld.Request REQUEST =
5656
Request.newBuilder().setName("request name").build();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
import org.junit.jupiter.api.Assertions;
3030
import org.junit.jupiter.api.Test;
3131

32-
public class Servlet23Test extends AbstractInstrumenterTest {
32+
public class Servlet23InstrumentationTest extends AbstractInstrumenterTest {
3333

3434
@Test
35-
public void simpleServlet() throws Exception {
35+
public void postJson() throws Exception {
3636
Server server = new Server(0);
3737
ServletContextHandler handler = new ServletContextHandler();
3838
handler.addServlet(TestServlet.class, "/test");
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
import org.junit.jupiter.api.Assertions;
3030
import org.junit.jupiter.api.Test;
3131

32-
public class Servlet30Test extends AbstractInstrumenterTest {
32+
public class Servlet30InstrumentationTest extends AbstractInstrumenterTest {
3333

3434
@Test
35-
public void simpleServlet() throws Exception {
35+
public void postJson() throws Exception {
3636
Server server = new Server(0);
3737
ServletContextHandler handler = new ServletContextHandler();
3838
handler.addServlet(TestServlet.class, "/test");
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
import org.junit.jupiter.api.Assertions;
3131
import org.junit.jupiter.api.Test;
3232

33-
public class Servlet31Test extends AbstractInstrumenterTest {
33+
public class Servlet31InstrumentationTest extends AbstractInstrumenterTest {
3434

3535
@Test
36-
public void simpleServlet() throws Exception {
36+
public void postJson() throws Exception {
3737
Server server = new Server(0);
3838
ServletContextHandler handler = new ServletContextHandler();
3939
handler.addServlet(TestServlet.class, "/test");
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.junit.jupiter.api.Test;
3434
import spark.Spark;
3535

36-
public class SparkJavaBodyCaptureTest extends AbstractInstrumenterTest {
36+
public class SparkJavaInstrumentationTest extends AbstractInstrumenterTest {
3737
private static final int PORT = 8099;
3838

3939
private static final String RESPONSE_BODY = "{\"key\": \"val\"}";
@@ -44,7 +44,7 @@ public class SparkJavaBodyCaptureTest extends AbstractInstrumenterTest {
4444
private static final String REQUEST_HEADER_VALUE = "responseHeader";
4545

4646
@BeforeAll
47-
public static void beforeAll() {
47+
public static void postJson() {
4848
AbstractInstrumenterTest.beforeAll();
4949
Spark.port(PORT);
5050
Spark.post(

javaagent-core/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ idea {
2222
}
2323

2424
dependencies {
25-
implementation("io.opentelemetry:opentelemetry-api:0.9.1")
25+
api("io.opentelemetry:opentelemetry-api:0.9.1")
2626

2727
api("com.google.protobuf:protobuf-java:3.11.4")
2828
api("com.google.protobuf:protobuf-java-util:3.11.4")

smoke-tests/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
}
44

55
dependencies{
6+
testImplementation(project(":javaagent-core"))
67
testImplementation("org.testcontainers:testcontainers:1.15.0-rc2")
78
testImplementation("com.squareup.okhttp3:okhttp:4.9.0")
89
testImplementation("org.awaitility:awaitility:4.0.3")

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ protected static int countSpansByName(
141141
return (int) getSpanStream(traces).filter(it -> it.getName().equals(spanName)).count();
142142
}
143143

144-
protected static Stream<Span> getSpanStream(Collection<ExportTraceServiceRequest> traces) {
145-
return traces.stream()
146-
.flatMap(it -> it.getResourceSpansList().stream())
147-
.flatMap(it -> it.getInstrumentationLibrarySpansList().stream())
148-
.flatMap(it -> it.getSpansList().stream());
144+
protected static Stream<Span> getSpanStream(Collection<ExportTraceServiceRequest> traceRequest) {
145+
return traceRequest.stream()
146+
.flatMap(request -> request.getResourceSpansList().stream())
147+
.flatMap(resourceSpans -> resourceSpans.getInstrumentationLibrarySpansList().stream())
148+
.flatMap(librarySpans -> librarySpans.getSpansList().stream());
149149
}
150150

151151
protected Collection<ExportTraceServiceRequest> waitForTraces() throws IOException {

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.junit.jupiter.api.Test;
3232
import org.testcontainers.containers.GenericContainer;
3333

34-
public class SpringBootDisabledBodyCaptureTest extends AbstractSmokeTest {
34+
public class SpringBootDisabledBodyCaptureSmokeTest extends AbstractSmokeTest {
3535

3636
@Override
3737
protected String getTargetImage(int jdk) {
@@ -55,7 +55,7 @@ void afterEach() {
5555
}
5656

5757
@Test
58-
public void springBootSmokeTest() throws IOException {
58+
public void get() throws IOException {
5959
// TODO test with multiple JDK (11, 14)
6060
String url = String.format("http://localhost:%d/greeting", app.getMappedPort(8080));
6161
Request request = new Request.Builder().url(url).get().build();
@@ -75,23 +75,23 @@ public void springBootSmokeTest() throws IOException {
7575
Assertions.assertEquals(
7676
2,
7777
getSpanStream(traces)
78-
.flatMap(s -> s.getAttributesList().stream())
79-
.filter(a -> a.getKey().equals(OTEL_LIBRARY_VERSION_ATTRIBUTE))
80-
.map(a -> a.getValue().getStringValue())
81-
.filter(s -> s.equals(currentAgentVersion))
78+
.flatMap(span -> span.getAttributesList().stream())
79+
.filter(attribute -> attribute.getKey().equals(OTEL_LIBRARY_VERSION_ATTRIBUTE))
80+
.map(attribute -> attribute.getValue().getStringValue())
81+
.filter(value -> value.equals(currentAgentVersion))
8282
.count());
8383
Assertions.assertEquals(
8484
0,
8585
getSpanStream(traces)
86-
.flatMap(s -> s.getAttributesList().stream())
87-
.filter(a -> a.getKey().contains("request.header."))
88-
.map(a -> a.getValue().getStringValue())
86+
.flatMap(span -> span.getAttributesList().stream())
87+
.filter(attribute -> attribute.getKey().contains("request.header."))
88+
.map(attribute -> attribute.getValue().getStringValue())
8989
.count());
9090
List<String> responseBodyAttributes =
9191
getSpanStream(traces)
92-
.flatMap(s -> s.getAttributesList().stream())
93-
.filter(a -> a.getKey().contains("response.body"))
94-
.map(a -> a.getValue().getStringValue())
92+
.flatMap(span -> span.getAttributesList().stream())
93+
.filter(attribute -> attribute.getKey().contains("response.body"))
94+
.map(attribute -> attribute.getValue().getStringValue())
9595
.collect(Collectors.toList());
9696
Assertions.assertEquals(0, responseBodyAttributes.size());
9797
}

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
import java.util.stream.Collectors;
2727
import okhttp3.Request;
2828
import okhttp3.Response;
29+
import org.hypertrace.agent.core.HypertraceSemanticAttributes;
2930
import org.junit.jupiter.api.AfterAll;
3031
import org.junit.jupiter.api.Assertions;
3132
import org.junit.jupiter.api.BeforeEach;
3233
import org.junit.jupiter.api.Test;
3334
import org.testcontainers.containers.GenericContainer;
3435

35-
public class SpringBootTest extends AbstractSmokeTest {
36+
public class SpringBootSmokeTest extends AbstractSmokeTest {
3637

3738
@Override
3839
protected String getTargetImage(int jdk) {
@@ -58,7 +59,7 @@ static void afterEach() {
5859
}
5960

6061
@Test
61-
public void smoke() throws IOException {
62+
public void get() throws IOException {
6263
String url = String.format("http://localhost:%d/greeting", app.getMappedPort(8080));
6364
Request request = new Request.Builder().url(url).get().build();
6465

@@ -91,30 +92,34 @@ public void smoke() throws IOException {
9192
Assertions.assertEquals(
9293
2,
9394
getSpanStream(traces)
94-
.flatMap(s -> s.getAttributesList().stream())
95-
.filter(a -> a.getKey().equals(OTEL_LIBRARY_VERSION_ATTRIBUTE))
96-
.map(a -> a.getValue().getStringValue())
97-
.filter(s -> s.equals(currentAgentVersion))
95+
.flatMap(span -> span.getAttributesList().stream())
96+
.filter(attribute -> attribute.getKey().equals(OTEL_LIBRARY_VERSION_ATTRIBUTE))
97+
.map(attribute -> attribute.getValue().getStringValue())
98+
.filter(value -> value.equals(currentAgentVersion))
9899
.count());
99100
Assertions.assertTrue(
100101
getSpanStream(traces)
101-
.flatMap(s -> s.getAttributesList().stream())
102-
.filter(a -> a.getKey().contains("request.header."))
103-
.map(a -> a.getValue().getStringValue())
102+
.flatMap(span -> span.getAttributesList().stream())
103+
.filter(attribute -> attribute.getKey().contains("request.header."))
104+
.map(attribute -> attribute.getValue().getStringValue())
104105
.count()
105106
> 0);
106107
Assertions.assertTrue(
107108
getSpanStream(traces)
108-
.flatMap(s -> s.getAttributesList().stream())
109-
.filter(a -> a.getKey().contains("response.header."))
110-
.map(a -> a.getValue().getStringValue())
109+
.flatMap(span -> span.getAttributesList().stream())
110+
.filter(attribute -> attribute.getKey().contains("response.header."))
111+
.map(attribute -> attribute.getValue().getStringValue())
111112
.count()
112113
> 0);
113114
List<String> responseBodyAttributes =
114115
getSpanStream(traces)
115-
.flatMap(s -> s.getAttributesList().stream())
116-
.filter(a -> a.getKey().contains("response.body"))
117-
.map(a -> a.getValue().getStringValue())
116+
.flatMap(span -> span.getAttributesList().stream())
117+
.filter(
118+
attribute ->
119+
attribute
120+
.getKey()
121+
.contains(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY.getKey()))
122+
.map(attribute -> attribute.getValue().getStringValue())
118123
.collect(Collectors.toList());
119124
Assertions.assertEquals(1, responseBodyAttributes.size());
120125
Assertions.assertEquals("Hi!", responseBodyAttributes.get(0));
@@ -131,8 +136,8 @@ public void blocking() throws IOException {
131136
Assertions.assertEquals(
132137
1,
133138
getSpanStream(traces)
134-
.flatMap(s -> s.getAttributesList().stream())
135-
.filter(a -> a.getKey().equals("hypertrace.mock.filter.result"))
139+
.flatMap(span -> span.getAttributesList().stream())
140+
.filter(attribute -> attribute.getKey().equals("hypertrace.mock.filter.result"))
136141
.count());
137142
}
138143
}

0 commit comments

Comments
 (0)