Skip to content

Commit c63a933

Browse files
committed
convert vertx-web-3.0 test case from groovy to java
1 parent 965e886 commit c63a933

File tree

4 files changed

+100
-91
lines changed

4 files changed

+100
-91
lines changed

instrumentation/vertx/vertx-web-3.0/javaagent/src/latestDepTest/groovy/server/VertxLatestHttpServerTest.groovy instrumentation/vertx/vertx-web-3.0/javaagent/src/latestDepTest/java/server/VertxLatestHttpServerTest.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package server
6+
package server;
77

8-
9-
import io.vertx.core.AbstractVerticle
8+
import io.vertx.core.AbstractVerticle;
9+
import io.vertx.core.Vertx;
1010

1111
class VertxLatestHttpServerTest extends AbstractVertxHttpServerTest {
1212

1313
@Override
1414
protected Class<? extends AbstractVerticle> verticle() {
15-
return VertxLatestWebServer
15+
return VertxLatestWebServer.class;
16+
}
17+
18+
@Override
19+
protected void stopServer(Vertx server) throws Exception {
20+
server.close();
1621
}
1722
}

instrumentation/vertx/vertx-web-3.0/javaagent/src/version3Test/groovy/server/VertxHttpServerTest.groovy instrumentation/vertx/vertx-web-3.0/javaagent/src/version3Test/java/server/VertxHttpServerTest.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package server
6+
package server;
77

8-
import io.vertx.core.AbstractVerticle
8+
import io.vertx.core.AbstractVerticle;
99

1010
class VertxHttpServerTest extends AbstractVertxHttpServerTest {
11-
1211
@Override
1312
protected Class<? extends AbstractVerticle> verticle() {
14-
return VertxWebServer
13+
return VertxWebServer.class;
1514
}
1615
}

instrumentation/vertx/vertx-web-3.0/testing/src/main/groovy/server/AbstractVertxHttpServerTest.groovy

-83
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package server;
7+
8+
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
9+
10+
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
11+
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
12+
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest;
13+
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
14+
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
15+
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
16+
import io.vertx.core.AbstractVerticle;
17+
import io.vertx.core.DeploymentOptions;
18+
import io.vertx.core.Vertx;
19+
import io.vertx.core.VertxOptions;
20+
import io.vertx.core.json.JsonObject;
21+
import java.util.Objects;
22+
import java.util.concurrent.CompletableFuture;
23+
import java.util.concurrent.ExecutionException;
24+
import java.util.concurrent.TimeUnit;
25+
import java.util.concurrent.TimeoutException;
26+
import org.junit.jupiter.api.extension.RegisterExtension;
27+
28+
abstract class AbstractVertxHttpServerTest extends AbstractHttpServerTest<Vertx> {
29+
30+
@RegisterExtension
31+
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();
32+
33+
@Override
34+
protected void configure(HttpServerTestOptions options) {
35+
options.setTestPathParam(true);
36+
// server spans are ended inside of the controller spans
37+
options.setVerifyServerSpanEndTime(false);
38+
options.setContextPath("/vertx-app");
39+
options.setExpectedException(new IllegalStateException(EXCEPTION.getBody()));
40+
super.configure(options);
41+
}
42+
43+
@Override
44+
public String expectedHttpRoute(ServerEndpoint endpoint, String method) {
45+
if (Objects.equals(method, HttpConstants._OTHER)) {
46+
return getContextPath() + endpoint.getPath();
47+
}
48+
if (Objects.equals(endpoint, ServerEndpoint.NOT_FOUND)) {
49+
return getContextPath();
50+
}
51+
return super.expectedHttpRoute(endpoint, method);
52+
}
53+
54+
@Override
55+
protected Vertx setupServer()
56+
throws ExecutionException, InterruptedException, TimeoutException, NoSuchMethodException {
57+
Vertx server =
58+
Vertx.vertx(
59+
new VertxOptions()
60+
// Useful for debugging:
61+
// .setBlockedThreadCheckInterval(Integer.MAX_VALUE)
62+
);
63+
CompletableFuture<Void> future = new CompletableFuture<>();
64+
65+
server.deployVerticle(
66+
verticle().getName(),
67+
new DeploymentOptions()
68+
.setConfig(
69+
new JsonObject().put(AbstractVertxWebServer.CONFIG_HTTP_SERVER_PORT, (Object) port))
70+
.setInstances(3),
71+
res -> {
72+
if (!res.succeeded()) {
73+
throw new IllegalStateException("Cannot deploy server Verticle", res.cause());
74+
}
75+
future.complete(null);
76+
});
77+
78+
future.get(30, TimeUnit.SECONDS);
79+
return server;
80+
}
81+
82+
@Override
83+
protected void stopServer(Vertx server) throws Exception {
84+
server.close();
85+
}
86+
87+
protected abstract Class<? extends AbstractVerticle> verticle();
88+
}

0 commit comments

Comments
 (0)