Skip to content

Commit

Permalink
minor test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasamoroso committed Jun 19, 2024
1 parent 32ae2af commit 2ea9fc6
Showing 1 changed file with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

package io.opentelemetry.javaagent.instrumentation.javalin.v5_0;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static io.opentelemetry.semconv.HttpAttributes.HTTP_ROUTE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import io.javalin.Javalin;
import io.opentelemetry.api.trace.SpanKind;
Expand Down Expand Up @@ -42,9 +41,7 @@ class JavalinTest {
@BeforeAll
static void setup() {
port = PortUtils.findOpenPort();

app = TestJavalinJavaApplication.initJavalin(port);

client = WebClient.of("http://localhost:" + port);
}

Expand All @@ -59,8 +56,8 @@ void testSpanNameAndHttpRouteSpanWithPathParamResponseSuccessful() {
AggregatedHttpResponse response = client.get("/param/" + id).aggregate().join();
String content = response.contentUtf8();

assertNotEquals(port, 0);
assertEquals(content, id);
assertThat(content).isEqualTo(id);
assertThat(response.status().code()).isEqualTo(200);
testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
Expand Down Expand Up @@ -91,7 +88,6 @@ void testSpanNameAndHttpRouteSpanWithPathParamResponseSuccessful() {
void testSpanNameAndHttpRouteSpanResponseError() {
client.get("/error").aggregate().join();

assertNotEquals(port, 0);
testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
Expand Down Expand Up @@ -121,9 +117,9 @@ void testSpanNameAndHttpRouteSpanResponseError() {

@Test
public void testSpanNameAndHttpRouteSpanAsyncRouteResponseSuccessful() {
client.get("/async").aggregate().join();
AggregatedHttpResponse response = client.get("/async").aggregate().join();

assertNotEquals(port, 0);
assertThat(response.status().code()).isEqualTo(200);
testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
Expand Down Expand Up @@ -157,22 +153,18 @@ void testHttpRouteMetricWithPathParamResponseSuccessful() {
String content = response.contentUtf8();
String instrumentation = "io.opentelemetry.jetty-11.0";

assertNotEquals(port, 0);
assertEquals(content, id);

assertThat(content).isEqualTo(id);
assertThat(response.status().code()).isEqualTo(200);
testing.waitAndAssertMetrics(
instrumentation,
"http.server.request.duration",
metrics ->
metrics.anySatisfy(
metric -> {
String metricHttpRoute =
metric.getData().getPoints().stream()
.findFirst()
.get()
.getAttributes()
.get(HTTP_ROUTE);
assertEquals("/param/{id}", metricHttpRoute);
}));
metric ->
assertThat(metric)
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point -> point.hasAttribute(HTTP_ROUTE, "/param/{id}")))));
}
}

0 comments on commit 2ea9fc6

Please sign in to comment.