Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Aleksandrov <dmitry.aleksandrov@oracle.com>
  • Loading branch information
dalexandrov committed Dec 1, 2023
1 parent dfbf9ca commit 066b14e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@ApplicationScoped
public class InMemorySpanExporter implements SpanExporter {
private boolean isStopped = false;
private final List<SpanData> finishedSpanItems = new CopyOnWriteArrayList<>();
private static final List<SpanData> finishedSpanItems = new CopyOnWriteArrayList<>();

/**
* In-memory span exporter inspired by TCKs.
Expand All @@ -48,7 +48,7 @@ public List<SpanData> getFinishedSpanItems(int spanCount) {
}

public void assertSpanCount(int spanCount) {
Awaitility.await().pollDelay(3, SECONDS).atMost(120, SECONDS)
Awaitility.await().pollDelay(3, SECONDS).atMost(10, SECONDS)
.untilAsserted(() -> assertThat(finishedSpanItems.size(), Matchers.is(spanCount)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import io.opentelemetry.sdk.trace.data.SpanData;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.GET;
Expand All @@ -48,6 +49,7 @@
* Test Span Hierarchy with Tracer Mock
*/
@HelidonTest
@AddBean(RestSpanHierarchyTest.SpanResource.class)
@AddBean(InMemorySpanExporter.class)
@AddBean(InMemorySpanExporterProvider.class)
@AddConfig(key = "otel.service.name", value = "helidon-mp-telemetry")
Expand All @@ -64,23 +66,15 @@ public class RestSpanHierarchyTest {

@BeforeEach
void setup() {
if (spanExporter != null) {
spanExporter.reset();
}
}

@AfterEach
void reset(){
spanExporter.reset();
}

@Test
void spanHierarchy() {

assertThat(webTarget.request("mixed").get(), is(Status.OK_200));
assertThat(webTarget.path("mixed").request().get().getStatus(), is(Response.Status.OK.getStatusCode()));

List<SpanData> spanItems = spanExporter.getFinishedSpanItems(3);
assertThat(spanItems.size(), is(3));
List<SpanData> spanItems = spanExporter.getFinishedSpanItems(4);
assertThat(spanItems.get(0).getKind(), is(SERVER));
assertThat(spanItems.get(0).getName(), is("mixed_inner"));
assertThat(spanItems.get(0).getAttributes().get(AttributeKey.stringKey("attribute")), is("value"));
Expand All @@ -99,10 +93,10 @@ void spanHierarchy() {
@Test
void spanHierarchyInjected() {

assertThat(webTarget.request("mixed_injected").get(), is(Status.OK_200));
assertThat(webTarget.path("mixed_injected").request().get().getStatus(), is(Response.Status.OK.getStatusCode()));

List<SpanData> spanItems = spanExporter.getFinishedSpanItems(3);
assertThat(spanItems.size(), is(3));
List<SpanData> spanItems = spanExporter.getFinishedSpanItems(4);
assertThat(spanItems.size(), is(4));
assertThat(spanItems.get(0).getKind(), is(SERVER));
assertThat(spanItems.get(0).getName(), is("mixed_inner_injected"));
assertThat(spanItems.get(0).getAttributes().get(AttributeKey.stringKey("attribute")), is("value"));
Expand All @@ -120,6 +114,7 @@ void spanHierarchyInjected() {


@Path("/")
@ApplicationScoped
public static class SpanResource {

@Inject
Expand Down Expand Up @@ -155,9 +150,4 @@ public Response mixedSpanInjected() {
return Response.ok().build();
}
}

@ApplicationPath("/")
public static class RestApplication extends Application {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.helidon.microprofile.testing.junit5.HelidonTest;

import io.opentelemetry.sdk.trace.data.SpanData;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.GET;
Expand All @@ -43,12 +44,13 @@
* Test Span Hierarchy with Tracer Mock
*/
@HelidonTest
@AddBean(TestFullUrlName.SpanResource.class)
@AddBean(InMemorySpanExporter.class)
@AddBean(InMemorySpanExporterProvider.class)
@AddExtension(TelemetryCdiExtension.class)
@AddConfig(key = "otel.service.name", value = "helidon-mp-telemetry")
@AddConfig(key = "otel.sdk.disabled", value = "false")
@AddConfig(key = "telemetry.span.full.url", value = "false")
@AddConfig(key = "telemetry.span.full.url", value = "true")
@AddConfig(key = "otel.traces.exporter", value = "in-memory")
public class TestFullUrlName {

Expand All @@ -71,15 +73,16 @@ void setup() {
@Test
void spanNaming() {

assertThat(webTarget.request("/named").get(), is(Status.OK_200));
assertThat(webTarget.path("named").request().get().getStatus(), is(Response.Status.OK.getStatusCode()));

List<SpanData> spanItems = spanExporter.getFinishedSpanItems(1);
assertThat(spanItems.size(), is(1));
List<SpanData> spanItems = spanExporter.getFinishedSpanItems(2);
assertThat(spanItems.size(), is(2));
assertThat(spanItems.get(0).getName(), is("http://localhost:" + webTarget.getUri().getPort() + "/named"));
}


@Path("/")
@ApplicationScoped
public static class SpanResource {

@GET
Expand All @@ -89,9 +92,4 @@ public Response mixedSpan() {
}

}

@ApplicationPath("/")
public static class RestApplication extends Application {

}
}

0 comments on commit 066b14e

Please sign in to comment.