This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch camel-4.10.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.10.x by this push: new 4a9fa025751 CAMEL-22133: Fix VertxPlatformHttpServer Vertx shutdown logic 4a9fa025751 is described below commit 4a9fa025751a1fc72ab58a809d0912efb69cbd01 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Wed Jun 4 07:35:23 2025 +0100 CAMEL-22133: Fix VertxPlatformHttpServer Vertx shutdown logic --- .../http/vertx/VertxPlatformHttpServer.java | 2 +- .../http/vertx/VertxPlatformHttpEngineTest.java | 7 +++ .../vertx/VertxPlatformHttpSharedVertxTest.java | 65 ++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java index d7e225d099f..58a691b1037 100644 --- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java +++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java @@ -288,7 +288,7 @@ public class VertxPlatformHttpServer extends ServiceSupport implements CamelCont } protected void stopVertx() { - if (this.vertx == null || this.localVertx) { + if (this.vertx == null || !this.localVertx) { return; } diff --git a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java index b2dc03e7108..fb0f2c30720 100644 --- a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java +++ b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java @@ -80,6 +80,7 @@ import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; public class VertxPlatformHttpEngineTest { public static SSLContextParameters serverSSLParameters; @@ -140,6 +141,7 @@ public class VertxPlatformHttpEngineTest { @Test public void testEngine() throws Exception { final CamelContext context = createCamelContext(); + VertxPlatformHttpServer platformHttpServer; try { context.addRoutes(new RouteBuilder() { @@ -183,9 +185,14 @@ public class VertxPlatformHttpEngineTest { assertNotNull(server); assertEquals("http", server.getScheme()); assertEquals(RestAssured.port, server.getServerPort()); + + platformHttpServer = context.hasService(VertxPlatformHttpServer.class); + assertNotNull(platformHttpServer.getVertx()); } finally { context.stop(); } + + assertNull(platformHttpServer.getVertx()); } @Test diff --git a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSharedVertxTest.java b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSharedVertxTest.java new file mode 100644 index 00000000000..4fc124b33ed --- /dev/null +++ b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSharedVertxTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.platform.http.vertx; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import io.vertx.core.Vertx; +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.test.AvailablePortFinder; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +class VertxPlatformHttpSharedVertxTest { + private static final Vertx vertx = Vertx.vertx(); + + @AfterAll + static void afterAll() { + if (vertx != null) { + vertx.close(); + } + } + + @Test + void sharedVertxInstanceNotClosed() throws Exception { + try (CamelContext context = new DefaultCamelContext()) { + VertxPlatformHttpServerConfiguration configuration = new VertxPlatformHttpServerConfiguration(); + configuration.setBindPort(AvailablePortFinder.getNextAvailable()); + + context.getRegistry().bind("vertx", vertx); + context.addService(new VertxPlatformHttpServer(configuration)); + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("platform-http:/test") + .setBody().constant("Hello World"); + } + }); + context.start(); + } + + // Verify shutdown of VertxPlatformHttpServer did not close the shared Vertx instance + CountDownLatch latch = new CountDownLatch(1); + vertx.setTimer(1, event -> latch.countDown()); + assertTrue(latch.await(1, TimeUnit.SECONDS)); + } +}