Skip to content

Commit 6f781d2

Browse files
Don't create a new Vert.x on dev mode restart
1 parent d42e123 commit 6f781d2

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

core/deployment/src/main/java/io/quarkus/deployment/dev/DevModeMain.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,14 @@ public void start() throws Exception {
102102

103103
QuarkusBootstrap.Builder bootstrapBuilder = QuarkusBootstrap.builder()
104104
.setApplicationRoot(appRoots.build())
105-
.setTargetDirectory(context.getDevModeRunnerJarFile().getParentFile().toPath())
106105
.setIsolateDeployment(true)
107106
.setLocalProjectDiscovery(context.isLocalProjectDiscovery())
108107
.addAdditionalDeploymentArchive(path)
109108
.setBaseName(context.getBaseName())
110109
.setMode(context.getMode());
110+
if (context.getDevModeRunnerJarFile() != null) {
111+
bootstrapBuilder.setTargetDirectory(context.getDevModeRunnerJarFile().getParentFile().toPath());
112+
}
111113
if (context.getProjectDir() != null) {
112114
bootstrapBuilder.setProjectRoot(context.getProjectDir().toPath());
113115
} else {

extensions/vertx-core/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public class VertxCoreRecorder {
5353

5454
public Supplier<Vertx> configureVertx(VertxConfiguration config,
5555
LaunchMode launchMode, ShutdownContext shutdown, List<Consumer<VertxOptions>> customizers) {
56-
vertx = new VertxSupplier(config, customizers);
5756
if (launchMode != LaunchMode.DEVELOPMENT) {
57+
vertx = new VertxSupplier(config, customizers);
5858
// we need this to be part of the last shutdown tasks because closing it early (basically before Arc)
5959
// could cause problem to beans that rely on Vert.x and contain shutdown tasks
6060
shutdown.addLastShutdownTask(new Runnable() {
@@ -63,6 +63,31 @@ public void run() {
6363
destroy();
6464
}
6565
});
66+
} else {
67+
if (vertx == null) {
68+
vertx = new VertxSupplier(config, customizers);
69+
} else if (vertx.v != null) {
70+
tryCleanTccl(vertx.v);
71+
}
72+
shutdown.addLastShutdownTask(new Runnable() {
73+
@Override
74+
public void run() {
75+
CountDownLatch latch = new CountDownLatch(1);
76+
if (vertx.v != null) {
77+
vertx.v.eventBus().close(new Handler<AsyncResult<Void>>() {
78+
@Override
79+
public void handle(AsyncResult<Void> event) {
80+
vertx.v.eventBus().start(new Handler<AsyncResult<Void>>() {
81+
@Override
82+
public void handle(AsyncResult<Void> event) {
83+
latch.countDown();
84+
}
85+
});
86+
}
87+
});
88+
}
89+
}
90+
});
6691
}
6792
return vertx;
6893
}
@@ -303,7 +328,8 @@ public Supplier<EventLoopGroup> bossSupplier() {
303328
return new Supplier<EventLoopGroup>() {
304329
@Override
305330
public EventLoopGroup get() {
306-
return ((VertxImpl) vertx.get()).getAcceptorEventLoopGroup();
331+
vertx.get();
332+
return ((VertxImpl) vertx.v).getAcceptorEventLoopGroup();
307333
}
308334
};
309335
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.quarkus.vertx.web;
2+
3+
import static io.vertx.core.http.HttpMethod.GET;
4+
import static io.vertx.core.http.HttpMethod.OPTIONS;
5+
import static io.vertx.core.http.HttpMethod.POST;
6+
7+
import io.quarkus.vertx.core.runtime.VertxCoreRecorder;
8+
import io.vertx.ext.web.RoutingContext;
9+
10+
public class DevModeRoute {
11+
12+
@Route(path = "/test", methods = { GET, OPTIONS, POST })
13+
void getRoutes(RoutingContext context) {
14+
context.response().setStatusCode(200).end("test route");
15+
}
16+
17+
@Route(path = "/assert", methods = GET)
18+
void assertVertx(RoutingContext context) {
19+
if (VertxCoreRecorder.getVertx().get() == context.vertx()) {
20+
context.response().end("OK");
21+
} else {
22+
context.fail(new RuntimeException("Incorrect vertx in use"));
23+
}
24+
}
25+
}

extensions/vertx-web/deployment/src/test/java/io/quarkus/vertx/web/VertxWebDevModeTestCase.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class VertxWebDevModeTestCase {
1616
@RegisterExtension
1717
static QuarkusDevModeTest runner = new QuarkusDevModeTest()
1818
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
19-
.addClasses(TestRoute.class));
19+
.addClasses(DevModeRoute.class));
2020

2121
@Test
2222
public void testRunningInDevMode() {
@@ -26,7 +26,7 @@ public void testRunningInDevMode() {
2626
.then().statusCode(200)
2727
.body(Matchers.equalTo("test route"));
2828

29-
runner.modifySourceFile(TestRoute.class, new Function<String, String>() {
29+
runner.modifySourceFile(DevModeRoute.class, new Function<String, String>() {
3030
@Override
3131
public String apply(String s) {
3232
return s.replace("test route", "new code");
@@ -39,6 +39,10 @@ public String apply(String s) {
3939
.then().statusCode(200)
4040
.body(Matchers.equalTo("new code"));
4141
}
42+
RestAssured.given()
43+
.get("/assert")
44+
.then().statusCode(200)
45+
.body(Matchers.equalTo("OK"));
4246
}
4347

4448
}

0 commit comments

Comments
 (0)