Skip to content

Commit 2d555ad

Browse files
authored
Add tests for vertx-web 5.0.0 (#13900)
1 parent 6af7676 commit 2d555ad

File tree

9 files changed

+151
-20
lines changed

9 files changed

+151
-20
lines changed

instrumentation/vertx/vertx-web-3.0/javaagent/build.gradle.kts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,59 @@ dependencies {
2020
testInstrumentation(project(":instrumentation:jdbc:javaagent"))
2121
}
2222

23+
val testLatestDeps = findProperty("testLatestDeps") as Boolean
24+
2325
testing {
2426
suites {
2527
val version3Test by registering(JvmTestSuite::class) {
2628
dependencies {
2729
implementation(project(":instrumentation:vertx:vertx-web-3.0:testing"))
2830

29-
implementation("io.vertx:vertx-web:3.0.0")
30-
implementation("io.vertx:vertx-jdbc-client:3.0.0")
31-
implementation("io.vertx:vertx-codegen:3.0.0")
32-
implementation("io.vertx:vertx-docgen:3.0.0")
31+
val version = if (testLatestDeps) "3.+" else "3.0.0"
32+
implementation("io.vertx:vertx-web:$version")
33+
implementation("io.vertx:vertx-jdbc-client:$version")
34+
implementation("io.vertx:vertx-codegen:$version")
35+
implementation("io.vertx:vertx-docgen:$version")
3336
}
3437
}
3538

36-
val latestDepTest by registering(JvmTestSuite::class) {
39+
val version41Test by registering(JvmTestSuite::class) {
3740
dependencies {
3841
implementation(project(":instrumentation:vertx:vertx-web-3.0:testing"))
3942

40-
implementation("io.vertx:vertx-web:4.+")
41-
implementation("io.vertx:vertx-jdbc-client:4.+")
42-
implementation("io.vertx:vertx-codegen:4.+")
43+
val version = if (testLatestDeps) "4.+" else "4.1.0"
44+
implementation("io.vertx:vertx-web:$version")
45+
implementation("io.vertx:vertx-jdbc-client:$version")
46+
implementation("io.vertx:vertx-codegen:$version")
47+
}
48+
}
49+
50+
val version5Test by registering(JvmTestSuite::class) {
51+
dependencies {
52+
implementation(project(":instrumentation:vertx:vertx-web-3.0:testing"))
53+
54+
val version = if (testLatestDeps) "latest.release" else "5.0.0"
55+
implementation("io.vertx:vertx-web:$version")
56+
implementation("io.vertx:vertx-jdbc-client:$version")
57+
implementation("io.vertx:vertx-codegen:$version")
4358
}
4459
}
4560
}
4661
}
4762

48-
val testLatestDeps = findProperty("testLatestDeps") as Boolean
49-
5063
tasks {
51-
if (testLatestDeps) {
52-
// disable regular test running and compiling tasks when latest dep test task is run
53-
named("test") {
64+
named("compileVersion5TestJava", JavaCompile::class).configure {
65+
options.release.set(11)
66+
}
67+
val testJavaVersion =
68+
gradle.startParameter.projectProperties.get("testJavaVersion")?.let(JavaVersion::toVersion)
69+
?: JavaVersion.current()
70+
if (!testJavaVersion.isCompatibleWith(JavaVersion.VERSION_11)) {
71+
named("version5Test", Test::class).configure {
5472
enabled = false
5573
}
5674
}
5775

58-
named("latestDepTest") {
59-
enabled = testLatestDeps
60-
}
61-
6276
check {
6377
dependsOn(testing.suites)
6478
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import io.vertx.core.AbstractVerticle;
99
import io.vertx.core.Vertx;
1010

11-
class VertxLatestHttpServerTest extends AbstractVertxHttpServerTest {
11+
class Vertx41HttpServerTest extends AbstractVertxHttpServerTest {
1212

1313
@Override
1414
protected Class<? extends AbstractVerticle> verticle() {
15-
return VertxLatestWebServer.class;
15+
return Vertx41WebServer.class;
1616
}
1717

1818
@Override
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import io.vertx.core.http.HttpServerResponse;
1010
import io.vertx.ext.web.Router;
1111

12-
public class VertxLatestWebServer extends AbstractVertxWebServer {
12+
public class Vertx41WebServer extends AbstractVertxWebServer {
1313

1414
@Override
1515
public void end(HttpServerResponse response) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.netty.handler.codec.haproxy;
7+
8+
// instrumentation fails without this class
9+
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
10+
public class HAProxyMessage {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.netty.handler.codec.haproxy;
7+
8+
// instrumentation fails without this class
9+
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
10+
public class HAProxyProxiedProtocol {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.vertx;
7+
8+
import io.vertx.core.AbstractVerticle;
9+
import io.vertx.core.DeploymentOptions;
10+
import io.vertx.core.Vertx;
11+
import io.vertx.core.VertxOptions;
12+
import io.vertx.core.json.JsonObject;
13+
import java.util.concurrent.CompletableFuture;
14+
import java.util.concurrent.ExecutionException;
15+
import java.util.concurrent.TimeUnit;
16+
import java.util.concurrent.TimeoutException;
17+
18+
class Vertx5HttpServerTest extends AbstractVertxHttpServerTest {
19+
20+
@Override
21+
protected Class<? extends AbstractVerticle> verticle() {
22+
return Vertx5WebServer.class;
23+
}
24+
25+
@Override
26+
protected Vertx setupServer()
27+
throws ExecutionException, InterruptedException, TimeoutException, NoSuchMethodException {
28+
Vertx server =
29+
Vertx.vertx(
30+
new VertxOptions()
31+
// Useful for debugging:
32+
// .setBlockedThreadCheckInterval(Integer.MAX_VALUE)
33+
);
34+
CompletableFuture<Void> future = new CompletableFuture<>();
35+
36+
server
37+
.deployVerticle(
38+
verticle().getName(),
39+
new DeploymentOptions()
40+
.setConfig(
41+
new JsonObject()
42+
.put(AbstractVertxWebServer.CONFIG_HTTP_SERVER_PORT, (Object) port))
43+
.setInstances(3))
44+
.onComplete(
45+
res -> {
46+
if (!res.succeeded()) {
47+
throw new IllegalStateException("Cannot deploy server Verticle", res.cause());
48+
}
49+
future.complete(null);
50+
});
51+
52+
future.get(30, TimeUnit.SECONDS);
53+
return server;
54+
}
55+
56+
@Override
57+
protected void stopServer(Vertx server) throws Exception {
58+
server.close();
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.vertx;
7+
8+
import io.vertx.core.Promise;
9+
import io.vertx.core.http.HttpServerResponse;
10+
import io.vertx.ext.web.Router;
11+
12+
public class Vertx5WebServer extends AbstractVertxWebServer {
13+
14+
@Override
15+
public void end(HttpServerResponse response) {
16+
response.end();
17+
}
18+
19+
@Override
20+
public void end(HttpServerResponse response, String message) {
21+
response.end(message);
22+
}
23+
24+
@Override
25+
public void start(Promise<Void> startPromise) {
26+
int port = config().getInteger(CONFIG_HTTP_SERVER_PORT);
27+
Router router = buildRouter();
28+
Router mainRouter = Router.router(vertx);
29+
mainRouter.route("/vertx-app/*").subRouter(router);
30+
31+
vertx
32+
.createHttpServer()
33+
.requestHandler(mainRouter)
34+
.listen(port)
35+
.onComplete(it -> startPromise.complete());
36+
}
37+
}

0 commit comments

Comments
 (0)