Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
* SPDX-License-Identifier: Apache-2.0
*/

package server
package server;


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

class VertxLatestHttpServerTest extends AbstractVertxHttpServerTest {

@Override
protected Class<? extends AbstractVerticle> verticle() {
return VertxLatestWebServer
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,14 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

package server
package server;

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;
}
}

This file was deleted.

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

package server;

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.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) {
options.setTestPathParam(true);
// server spans are ended inside of the controller spans
options.setVerifyServerSpanEndTime(false);
options.setContextPath("/vertx-app");
options.setExpectedException(new IllegalStateException(EXCEPTION.getBody()));
super.configure(options);
}

@Override
public String expectedHttpRoute(ServerEndpoint endpoint, String 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();
}
Loading