diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/AbstractVertxRxHttpServerTest.java b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/AbstractVertxRxHttpServerTest.java new file mode 100644 index 000000000000..818c858a6f1a --- /dev/null +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/AbstractVertxRxHttpServerTest.java @@ -0,0 +1,107 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.vertx.reactive.server; + +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; + +import io.opentelemetry.instrumentation.api.internal.HttpConstants; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; +import io.vertx.core.DeploymentOptions; +import io.vertx.core.Promise; +import io.vertx.core.Vertx; +import io.vertx.core.VertxOptions; +import io.vertx.core.json.JsonObject; +import io.vertx.reactivex.core.AbstractVerticle; +import io.vertx.reactivex.ext.web.Router; +import io.vertx.reactivex.ext.web.RoutingContext; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; + +abstract class AbstractVertxRxHttpServerTest extends AbstractHttpServerTest { + static final String CONFIG_HTTP_SERVER_PORT = "http.server.port"; + + @Override + protected Vertx setupServer() throws Exception { + Vertx server = + Vertx.vertx( + new VertxOptions() + // Useful for debugging: + // .setBlockedThreadCheckInterval(Integer.MAX_VALUE) + ); + CompletableFuture future = new CompletableFuture<>(); + server.deployVerticle( + verticle().getName(), + new DeploymentOptions() + .setConfig(new JsonObject().put(CONFIG_HTTP_SERVER_PORT, port)) + .setInstances(3), + result -> { + if (!result.succeeded()) { + throw new IllegalStateException("Cannot deploy server Verticle", result.cause()); + } + future.complete(null); + }); + + future.get(30, TimeUnit.SECONDS); + return server; + } + + @Override + protected void stopServer(Vertx vertx) { + vertx.close(); + } + + @Override + protected void configure(HttpServerTestOptions options) { + super.configure(options); + + options.setTestPathParam(true); + // server spans are ended inside the controller spans + options.setVerifyServerSpanEndTime(false); + options.setExpectedHttpRoute( + (endpoint, method) -> { + if (HttpConstants._OTHER.equals(method)) { + return getContextPath() + endpoint.getPath(); + } + return expectedHttpRoute(endpoint, method); + }); + } + + protected Class verticle() { + return VertxReactiveWebServer.class; + } + + public static class VertxReactiveWebServer extends AbstractVertxRxVerticle { + @Override + void handle(RoutingContext ctx, ServerEndpoint endpoint, Runnable action) { + controller(endpoint, action::run); + } + + @Override + public void start(Promise startFuture) { + int port = config().getInteger(CONFIG_HTTP_SERVER_PORT); + Router router = Router.router(vertx); + + configure(router); + router + .route(EXCEPTION.getPath()) + .handler( + ctx -> + handle( + ctx, + EXCEPTION, + () -> { + throw new IllegalStateException(EXCEPTION.getBody()); + })); + + vertx + .createHttpServer() + .requestHandler(router) + .listen(port, httpServerAsyncResult -> startFuture.complete()); + } + } +} diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxCircuitBreakerHttpServerTest.java b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxCircuitBreakerHttpServerTest.java index ef2e0de1dee7..d447a6d1733e 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxCircuitBreakerHttpServerTest.java +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxCircuitBreakerHttpServerTest.java @@ -7,6 +7,8 @@ import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; import io.vertx.circuitbreaker.CircuitBreakerOptions; @@ -15,8 +17,12 @@ import io.vertx.reactivex.core.AbstractVerticle; import io.vertx.reactivex.ext.web.Router; import io.vertx.reactivex.ext.web.RoutingContext; +import org.junit.jupiter.api.extension.RegisterExtension; -class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { +class VertxRxCircuitBreakerHttpServerTest extends AbstractVertxRxHttpServerTest { + + @RegisterExtension + static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent(); @Override protected void configure(HttpServerTestOptions options) { diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxHttpServerTest.java b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxHttpServerTest.java index 4c4393f7b299..771fd09e85ef 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxHttpServerTest.java +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxHttpServerTest.java @@ -7,76 +7,21 @@ import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; -import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; -import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; -import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; -import io.vertx.core.DeploymentOptions; import io.vertx.core.Promise; -import io.vertx.core.Vertx; -import io.vertx.core.VertxOptions; -import io.vertx.core.json.JsonObject; import io.vertx.reactivex.core.AbstractVerticle; import io.vertx.reactivex.ext.web.Router; import io.vertx.reactivex.ext.web.RoutingContext; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.extension.RegisterExtension; -class VertxRxHttpServerTest extends AbstractHttpServerTest { - static final String CONFIG_HTTP_SERVER_PORT = "http.server.port"; +class VertxRxHttpServerTest extends AbstractVertxRxHttpServerTest { @RegisterExtension static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent(); @Override - protected Vertx setupServer() throws Exception { - Vertx server = - Vertx.vertx( - new VertxOptions() - // Useful for debugging: - // .setBlockedThreadCheckInterval(Integer.MAX_VALUE) - ); - CompletableFuture future = new CompletableFuture<>(); - server.deployVerticle( - verticle().getName(), - new DeploymentOptions() - .setConfig(new JsonObject().put(CONFIG_HTTP_SERVER_PORT, port)) - .setInstances(3), - result -> { - if (!result.succeeded()) { - throw new IllegalStateException("Cannot deploy server Verticle", result.cause()); - } - future.complete(null); - }); - - future.get(30, TimeUnit.SECONDS); - return server; - } - - @Override - protected void stopServer(Vertx vertx) { - vertx.close(); - } - - @Override - protected void configure(HttpServerTestOptions options) { - super.configure(options); - - options.setTestPathParam(true); - // server spans are ended inside the controller spans - options.setVerifyServerSpanEndTime(false); - options.setExpectedHttpRoute( - (endpoint, method) -> { - if (HttpConstants._OTHER.equals(method)) { - return getContextPath() + endpoint.getPath(); - } - return expectedHttpRoute(endpoint, method); - }); - } - protected Class verticle() { return VertxReactiveWebServer.class; } diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/AbstractVertxRxHttpServerTest.java b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/AbstractVertxRxHttpServerTest.java new file mode 100644 index 000000000000..9ab1b8a91363 --- /dev/null +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/AbstractVertxRxHttpServerTest.java @@ -0,0 +1,69 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.vertx.reactive.server; + +import io.opentelemetry.instrumentation.api.internal.HttpConstants; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; +import io.vertx.core.DeploymentOptions; +import io.vertx.core.Vertx; +import io.vertx.core.VertxOptions; +import io.vertx.core.json.JsonObject; +import io.vertx.reactivex.core.AbstractVerticle; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; + +abstract class AbstractVertxRxHttpServerTest extends AbstractHttpServerTest { + static final String CONFIG_HTTP_SERVER_PORT = "http.server.port"; + + @Override + protected Vertx setupServer() throws Exception { + Vertx server = + Vertx.vertx( + new VertxOptions() + // Useful for debugging: + // .setBlockedThreadCheckInterval(Integer.MAX_VALUE) + .setClusterPort(port)); + CompletableFuture future = new CompletableFuture<>(); + server.deployVerticle( + verticle().getName(), + new DeploymentOptions() + .setConfig(new JsonObject().put(CONFIG_HTTP_SERVER_PORT, port)) + .setInstances(3), + result -> { + if (!result.succeeded()) { + throw new IllegalStateException("Cannot deploy server Verticle", result.cause()); + } + future.complete(null); + }); + + future.get(30, TimeUnit.SECONDS); + return server; + } + + @Override + protected void stopServer(Vertx vertx) { + vertx.close(); + } + + @Override + protected void configure(HttpServerTestOptions options) { + super.configure(options); + + options.setTestPathParam(true); + // server spans are ended inside the controller spans + options.setVerifyServerSpanEndTime(false); + options.setExpectedHttpRoute( + (endpoint, method) -> { + if (HttpConstants._OTHER.equals(method)) { + return getContextPath() + endpoint.getPath(); + } + return expectedHttpRoute(endpoint, method); + }); + } + + protected abstract Class verticle(); +} diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxCircuitBreakerHttpServerTest.java b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxCircuitBreakerHttpServerTest.java index ee2b7ed1fc3a..cdcd40956d16 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxCircuitBreakerHttpServerTest.java +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxCircuitBreakerHttpServerTest.java @@ -7,6 +7,8 @@ import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; import io.vertx.circuitbreaker.CircuitBreakerOptions; @@ -15,8 +17,12 @@ import io.vertx.reactivex.core.AbstractVerticle; import io.vertx.reactivex.ext.web.Router; import io.vertx.reactivex.ext.web.RoutingContext; +import org.junit.jupiter.api.extension.RegisterExtension; -class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { +class VertxRxCircuitBreakerHttpServerTest extends AbstractVertxRxHttpServerTest { + + @RegisterExtension + static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent(); @Override protected void configure(HttpServerTestOptions options) { diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxHttpServerTest.java b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxHttpServerTest.java index 287065c300dc..31842c0e707c 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxHttpServerTest.java +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxHttpServerTest.java @@ -7,76 +7,21 @@ import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; -import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; -import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; -import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; -import io.vertx.core.DeploymentOptions; import io.vertx.core.Future; -import io.vertx.core.Vertx; -import io.vertx.core.VertxOptions; -import io.vertx.core.json.JsonObject; import io.vertx.reactivex.core.AbstractVerticle; import io.vertx.reactivex.ext.web.Router; import io.vertx.reactivex.ext.web.RoutingContext; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.extension.RegisterExtension; -class VertxRxHttpServerTest extends AbstractHttpServerTest { - static final String CONFIG_HTTP_SERVER_PORT = "http.server.port"; +class VertxRxHttpServerTest extends AbstractVertxRxHttpServerTest { @RegisterExtension static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent(); @Override - protected Vertx setupServer() throws Exception { - Vertx server = - Vertx.vertx( - new VertxOptions() - // Useful for debugging: - // .setBlockedThreadCheckInterval(Integer.MAX_VALUE) - .setClusterPort(port)); - CompletableFuture future = new CompletableFuture<>(); - server.deployVerticle( - verticle().getName(), - new DeploymentOptions() - .setConfig(new JsonObject().put(CONFIG_HTTP_SERVER_PORT, port)) - .setInstances(3), - result -> { - if (!result.succeeded()) { - throw new IllegalStateException("Cannot deploy server Verticle", result.cause()); - } - future.complete(null); - }); - - future.get(30, TimeUnit.SECONDS); - return server; - } - - @Override - protected void stopServer(Vertx vertx) { - vertx.close(); - } - - @Override - protected void configure(HttpServerTestOptions options) { - super.configure(options); - - options.setTestPathParam(true); - // server spans are ended inside the controller spans - options.setVerifyServerSpanEndTime(false); - options.setExpectedHttpRoute( - (endpoint, method) -> { - if (HttpConstants._OTHER.equals(method)) { - return getContextPath() + endpoint.getPath(); - } - return expectedHttpRoute(endpoint, method); - }); - } - protected Class verticle() { return VertxReactiveWebServer.class; }