Skip to content

Commit

Permalink
convert vertx-web-3.0 test case from groovy to java (#12826)
Browse files Browse the repository at this point in the history
  • Loading branch information
shalk authored Dec 5, 2024
1 parent 7b69e56 commit 5ebb81b
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 107 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.vertx;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;

class VertxLatestHttpServerTest extends AbstractVertxHttpServerTest {

@Override
protected Class<? extends AbstractVerticle> verticle() {
return VertxLatestWebServer.class;
}

@Override
protected void stopServer(Vertx server) throws Exception {
server.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package server;
package io.opentelemetry.javaagent.instrumentation.vertx;

import io.vertx.core.Promise;
import io.vertx.core.http.HttpServerResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

package server
package io.opentelemetry.javaagent.instrumentation.vertx;

import io.vertx.core.AbstractVerticle
import io.vertx.core.AbstractVerticle;

class VertxHttpServerTest extends AbstractVertxHttpServerTest {

@Override
protected Class<? extends AbstractVerticle> verticle() {
return VertxWebServer
return VertxWebServer.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package server;
package io.opentelemetry.javaagent.instrumentation.vertx;

import io.vertx.core.Future;
import io.vertx.core.http.HttpServerResponse;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.vertx;

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.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.json.JsonObject;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.junit.jupiter.api.extension.RegisterExtension;

abstract class AbstractVertxHttpServerTest extends AbstractHttpServerTest<Vertx> {

@RegisterExtension
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();

@Override
protected void configure(HttpServerTestOptions options) {
super.configure(options);
options.setTestPathParam(true);
// server spans are ended inside of the controller spans
options.setVerifyServerSpanEndTime(false);
options.setContextPath("/vertx-app");
options.setExpectedHttpRoute(
(endpoint, method) -> {
if (Objects.equals(method, HttpConstants._OTHER)) {
return getContextPath() + endpoint.getPath();
}
if (Objects.equals(endpoint, ServerEndpoint.NOT_FOUND)) {
return getContextPath();
}
return super.expectedHttpRoute(endpoint, method);
});
}

@Override
protected Vertx setupServer()
throws ExecutionException, InterruptedException, TimeoutException, NoSuchMethodException {
Vertx server =
Vertx.vertx(
new VertxOptions()
// Useful for debugging:
// .setBlockedThreadCheckInterval(Integer.MAX_VALUE)
);
CompletableFuture<Void> future = new CompletableFuture<>();

server.deployVerticle(
verticle().getName(),
new DeploymentOptions()
.setConfig(
new JsonObject().put(AbstractVertxWebServer.CONFIG_HTTP_SERVER_PORT, (Object) port))
.setInstances(3),
res -> {
if (!res.succeeded()) {
throw new IllegalStateException("Cannot deploy server Verticle", res.cause());
}
future.complete(null);
});

future.get(30, TimeUnit.SECONDS);
return server;
}

@Override
protected void stopServer(Vertx server) throws Exception {
server.close();
}

protected abstract Class<? extends AbstractVerticle> verticle();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package server;
package io.opentelemetry.javaagent.instrumentation.vertx;

import static io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.controller;
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS;
Expand Down

0 comments on commit 5ebb81b

Please sign in to comment.