From e4f83915c02a8b89b1670ddae393958d33d7fb29 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Thu, 23 Nov 2023 13:38:24 +0100 Subject: [PATCH 1/3] Use quarkus-jaeger 1.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 773c3ae..05bc791 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ UTF-8 3.6.0 3.0.3 - 999-SNAPSHOT + 1.0.0 3.24.2 From 298b7a21f688f8c994451d113b373274fbd4a12e Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Thu, 23 Nov 2023 13:40:51 +0100 Subject: [PATCH 2/3] Fix groupId in quickstart module --- quickstart/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstart/pom.xml b/quickstart/pom.xml index 191176b..f3f3880 100644 --- a/quickstart/pom.xml +++ b/quickstart/pom.xml @@ -29,7 +29,7 @@ test - io.quarkus + io.quarkiverse.opentracing quarkus-smallrye-opentracing From 04654ab9c0788e22de3cd2a266d0cabc3e71bea3 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Thu, 23 Nov 2023 13:52:40 +0100 Subject: [PATCH 3/3] Avoid registering the tracer multiple times --- .../deployment/SmallryeOpentracingTest.java | 23 ----------- .../opentracing/deployment/TracerHolder.java | 13 ++++++ .../opentracing/deployment/TracingTest.java | 40 ++++++++----------- .../MongoTracingCommandListenerTest.java | 18 +++------ 4 files changed, 36 insertions(+), 58 deletions(-) delete mode 100644 deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/SmallryeOpentracingTest.java create mode 100644 deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/TracerHolder.java diff --git a/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/SmallryeOpentracingTest.java b/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/SmallryeOpentracingTest.java deleted file mode 100644 index 0e5b9fd..0000000 --- a/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/SmallryeOpentracingTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.quarkus.smallrye.opentracing.deployment; - -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.quarkus.test.QuarkusUnitTest; - -public class SmallryeOpentracingTest { - - // Start unit test with your extension loaded - @RegisterExtension - static final QuarkusUnitTest unitTest = new QuarkusUnitTest() - .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); - - @Test - public void writeYourOwnUnitTest() { - // Write your unit tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-extensions for more information - Assertions.assertTrue(true, "Add some assertions to " + getClass().getName()); - } -} diff --git a/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/TracerHolder.java b/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/TracerHolder.java new file mode 100644 index 0000000..5713a49 --- /dev/null +++ b/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/TracerHolder.java @@ -0,0 +1,13 @@ +package io.quarkus.smallrye.opentracing.deployment; + +import io.opentracing.mock.MockTracer; +import io.opentracing.util.GlobalTracer; + +public class TracerHolder { + + public static MockTracer mockTracer = new MockTracer(); + + static { + GlobalTracer.registerIfAbsent(mockTracer); + } +} diff --git a/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/TracingTest.java b/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/TracingTest.java index bc06afb..d6c8ffc 100644 --- a/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/TracingTest.java +++ b/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/TracingTest.java @@ -15,8 +15,6 @@ import org.junit.jupiter.api.extension.RegisterExtension; import io.opentracing.mock.MockSpan; -import io.opentracing.mock.MockTracer; -import io.opentracing.util.GlobalTracer; import io.opentracing.util.GlobalTracerTestUtil; import io.quarkus.test.QuarkusUnitTest; import io.restassured.RestAssured; @@ -31,18 +29,14 @@ public class TracingTest { .addClass(Service.class) .addClass(RestService.class) .addClass(Fruit.class) + .addClass(TracerHolder.class) .addAsResource("application.properties") .addAsResource("import.sql") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); - static MockTracer mockTracer = new MockTracer(); - static { - GlobalTracer.registerIfAbsent(mockTracer); - } - @BeforeEach public void before() { - mockTracer.reset(); + TracerHolder.mockTracer.reset(); } @AfterAll @@ -57,9 +51,9 @@ public void testSingleServerRequest() { RestAssured.when().get("/hello") .then() .statusCode(200); - Assertions.assertEquals(1, mockTracer.finishedSpans().size()); + Assertions.assertEquals(1, TracerHolder.mockTracer.finishedSpans().size()); Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.hello", - mockTracer.finishedSpans().get(0).operationName()); + TracerHolder.mockTracer.finishedSpans().get(0).operationName()); } finally { RestAssured.reset(); } @@ -72,11 +66,11 @@ public void testCDI() { RestAssured.when().get("/cdi") .then() .statusCode(200); - Assertions.assertEquals(2, mockTracer.finishedSpans().size()); + Assertions.assertEquals(2, TracerHolder.mockTracer.finishedSpans().size()); Assertions.assertEquals("io.quarkus.smallrye.opentracing.deployment.Service.foo", - mockTracer.finishedSpans().get(0).operationName()); + TracerHolder.mockTracer.finishedSpans().get(0).operationName()); Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.cdi", - mockTracer.finishedSpans().get(1).operationName()); + TracerHolder.mockTracer.finishedSpans().get(1).operationName()); } finally { RestAssured.reset(); } @@ -89,12 +83,12 @@ public void testMPRestClient() { RestAssured.when().get("/restClient") .then() .statusCode(200); - Assertions.assertEquals(3, mockTracer.finishedSpans().size()); + Assertions.assertEquals(3, TracerHolder.mockTracer.finishedSpans().size()); Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.hello", - mockTracer.finishedSpans().get(0).operationName()); - Assertions.assertEquals("GET", mockTracer.finishedSpans().get(1).operationName()); + TracerHolder.mockTracer.finishedSpans().get(0).operationName()); + Assertions.assertEquals("GET", TracerHolder.mockTracer.finishedSpans().get(1).operationName()); Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.restClient", - mockTracer.finishedSpans().get(2).operationName()); + TracerHolder.mockTracer.finishedSpans().get(2).operationName()); } finally { RestAssured.reset(); } @@ -109,8 +103,8 @@ public void testContextPropagationInFaultTolerance() { .statusCode(200) .body(equalTo("fallback")); Awaitility.await().atMost(5, TimeUnit.SECONDS) - .until(() -> mockTracer.finishedSpans().size() == 5); - List spans = mockTracer.finishedSpans(); + .until(() -> TracerHolder.mockTracer.finishedSpans().size() == 5); + List spans = TracerHolder.mockTracer.finishedSpans(); Assertions.assertEquals(5, spans.size()); for (MockSpan mockSpan : spans) { @@ -143,20 +137,20 @@ public void testJPA() { .body("name[0]", equalTo("Apple")) .body("name[1]", equalTo("Banana")) .body("name[2]", equalTo("Cherry")); - List spans = mockTracer.finishedSpans(); + List spans = TracerHolder.mockTracer.finishedSpans(); Assertions.assertEquals(3, spans.size()); for (MockSpan mockSpan : spans) { Assertions.assertEquals(spans.get(0).context().traceId(), mockSpan.context().traceId()); } - MockSpan firstSpan = mockTracer.finishedSpans().get(0); + MockSpan firstSpan = TracerHolder.mockTracer.finishedSpans().get(0); Assertions.assertEquals("Query", firstSpan.operationName()); Assertions.assertTrue(firstSpan.tags().containsKey("db.statement")); Assertions.assertTrue(firstSpan.tags().get("db.statement").toString().contains("known_fruits")); Assertions.assertEquals("io.quarkus.smallrye.opentracing.deployment.Service.getFruits", - mockTracer.finishedSpans().get(1).operationName()); + TracerHolder.mockTracer.finishedSpans().get(1).operationName()); Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.jpa", - mockTracer.finishedSpans().get(2).operationName()); + TracerHolder.mockTracer.finishedSpans().get(2).operationName()); } finally { RestAssured.reset(); } diff --git a/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/integration/MongoTracingCommandListenerTest.java b/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/integration/MongoTracingCommandListenerTest.java index 532e217..45579ba 100644 --- a/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/integration/MongoTracingCommandListenerTest.java +++ b/deployment/src/test/java/io/quarkus/smallrye/opentracing/deployment/integration/MongoTracingCommandListenerTest.java @@ -15,9 +15,8 @@ import com.mongodb.client.MongoClient; import io.opentracing.mock.MockSpan; -import io.opentracing.mock.MockTracer; -import io.opentracing.util.GlobalTracer; import io.opentracing.util.GlobalTracerTestUtil; +import io.quarkus.smallrye.opentracing.deployment.TracerHolder; import io.quarkus.smallrye.opentracing.runtime.integration.MongoTracingCommandListener; import io.quarkus.test.QuarkusUnitTest; @@ -34,17 +33,12 @@ public class MongoTracingCommandListenerTest extends MongoTestBase { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() .setArchiveProducer( - () -> ShrinkWrap.create(JavaArchive.class).addClasses(MongoTestBase.class)) + () -> ShrinkWrap.create(JavaArchive.class).addClasses(MongoTestBase.class, TracerHolder.class)) .withConfigurationResource("application-tracing-mongo.properties"); - static MockTracer mockTracer = new MockTracer(); - static { - GlobalTracer.register(mockTracer); - } - @BeforeEach public void before() { - mockTracer.reset(); + TracerHolder.mockTracer.reset(); } @AfterAll @@ -61,12 +55,12 @@ void cleanup() { @Test void testClientInitialization() { - assertThat(mockTracer.finishedSpans()).isEmpty(); + assertThat(TracerHolder.mockTracer.finishedSpans()).isEmpty(); assertThat(client.listDatabaseNames().first()).isNotEmpty(); - assertThat(mockTracer.finishedSpans()).hasSize(1); - MockSpan span = mockTracer.finishedSpans().get(0); + assertThat(TracerHolder.mockTracer.finishedSpans()).hasSize(1); + MockSpan span = TracerHolder.mockTracer.finishedSpans().get(0); assertThat(span.operationName()).isEqualTo("listDatabases"); }