This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 850923efe414 CAMEL-24015: Fix flaky VertxPlatformHttpOAuthProfileTest
(#24618)
850923efe414 is described below
commit 850923efe414e565a5cb8b1e70181b4a27c99c81
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sun Jul 12 09:44:57 2026 +0200
CAMEL-24015: Fix flaky VertxPlatformHttpOAuthProfileTest (#24618)
CAMEL-24015: Fix flaky VertxPlatformHttpOAuthProfileTest
Replace flaky Vert.x HTTP client with RestAssured-based test to avoid
connection race when server responds 401 before request body is sent.
Co-authored-by: Claude Opus 4.6 <[email protected]>
---
.../vertx/VertxPlatformHttpOAuthProfileTest.java | 51 ++++------------------
1 file changed, 9 insertions(+), 42 deletions(-)
diff --git
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpOAuthProfileTest.java
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpOAuthProfileTest.java
index bc413147bbe2..685d8b5bdade 100644
---
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpOAuthProfileTest.java
+++
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpOAuthProfileTest.java
@@ -16,12 +16,8 @@
*/
package org.apache.camel.component.platform.http.vertx;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import io.vertx.core.http.HttpClient;
-import io.vertx.core.http.HttpMethod;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.platform.http.PlatformHttpConstants;
@@ -47,51 +43,22 @@ class VertxPlatformHttpOAuthProfileTest {
@Test
void rejectsMissingBearerTokenBeforeBodyHandler() throws Exception {
CamelContext context =
VertxPlatformHttpEngineTest.createCamelContext();
- HttpClient client = null;
try {
addRoute(context);
VertxPlatformHttpEngineTest.startCamelContext(context);
- VertxPlatformHttpServer server =
context.hasService(VertxPlatformHttpServer.class);
- client = server.getVertx().createHttpClient();
-
- // Collect status code and response body atomically inside the
response
- // handler to avoid a race where the body arrives and is discarded
before
- // the test registers a body() handler.
- CompletableFuture<int[]> statusFuture = new CompletableFuture<>();
- CompletableFuture<String> bodyFuture = new CompletableFuture<>();
- client.request(HttpMethod.POST, server.getPort(), "localhost",
"/secure")
- .onSuccess(request -> {
- request.putHeader("Content-Length", "1024");
- request.response()
- .onSuccess(response -> {
- statusFuture.complete(new int[] {
response.statusCode() });
- response.body()
- .onSuccess(buffer ->
bodyFuture.complete(buffer.toString()))
-
.onFailure(bodyFuture::completeExceptionally);
- })
- .onFailure(t -> {
- statusFuture.completeExceptionally(t);
- bodyFuture.completeExceptionally(t);
- });
- request.sendHead().onFailure(t -> {
- statusFuture.completeExceptionally(t);
- bodyFuture.completeExceptionally(t);
- });
- })
- .onFailure(t -> {
- statusFuture.completeExceptionally(t);
- bodyFuture.completeExceptionally(t);
- });
-
- assertEquals(401, statusFuture.get(5, TimeUnit.SECONDS)[0]);
- assertEquals("Unauthorized", bodyFuture.get(5, TimeUnit.SECONDS));
+ // Send a POST with a body but no Authorization header.
+ // The server must reject the request before reaching the route.
+ given()
+ .body("hello")
+ .when()
+ .post("/secure")
+ .then()
+ .statusCode(401)
+ .body(equalTo("Unauthorized"));
assertEquals(0, routeInvocations.get());
} finally {
- if (client != null) {
-
client.close().toCompletionStage().toCompletableFuture().get(5,
TimeUnit.SECONDS);
- }
context.stop();
}
}