From e386b145048815767762c4dffc1f10ed708e7ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 26 Feb 2024 16:37:52 +0100 Subject: [PATCH] Correctly forward websocket errors in DevUIJsonRPCTest Instead of logging them (sometimes) and waiting for the timeout. --- .../quarkus/devui/tests/DevUIJsonRPCTest.java | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/extensions/vertx-http/dev-ui-tests/src/main/java/io/quarkus/devui/tests/DevUIJsonRPCTest.java b/extensions/vertx-http/dev-ui-tests/src/main/java/io/quarkus/devui/tests/DevUIJsonRPCTest.java index 45791f5e27b86..2c6e51397d64d 100644 --- a/extensions/vertx-http/dev-ui-tests/src/main/java/io/quarkus/devui/tests/DevUIJsonRPCTest.java +++ b/extensions/vertx-http/dev-ui-tests/src/main/java/io/quarkus/devui/tests/DevUIJsonRPCTest.java @@ -149,10 +149,10 @@ private JsonNode objectResultFromJsonRPC(int id) throws InterruptedException, Js } private JsonNode objectResultFromJsonRPC(int id, int loopCount) throws InterruptedException, JsonProcessingException { - if (MESSAGES.containsKey(id)) { - String response = MESSAGES.remove(id); + if (RESPONSES.containsKey(id)) { + WebSocketResponse response = RESPONSES.remove(id); if (response != null) { - ObjectNode json = (ObjectNode) new ObjectMapper().readTree(response); + ObjectNode json = (ObjectNode) new ObjectMapper().readTree(response.message()); JsonNode result = json.get("result"); if (result != null) { return result.get("object"); @@ -212,25 +212,48 @@ private int sendRequest(String methodName, Map params) throws IO socket.frameHandler((e) -> { Buffer b = accumulatedBuffer.appendBuffer(e.binaryData()); if (e.isFinal()) { - MESSAGES.put(id, b.toString()); + RESPONSES.put(id, new WebSocketResponse(b.toString())); } }); socket.writeTextMessage(request); socket.exceptionHandler((e) -> { - e.printStackTrace(); + RESPONSES.put(id, new WebSocketResponse(e)); vertx.close(); }); socket.closeHandler(v -> { vertx.close(); }); } else { + RESPONSES.put(id, new WebSocketResponse(ar.cause())); vertx.close(); } }); return id; } - private static final ConcurrentHashMap MESSAGES = new ConcurrentHashMap<>(); + private static final ConcurrentHashMap RESPONSES = new ConcurrentHashMap<>(); + + private static class WebSocketResponse { + private final String message; + private final Throwable throwable; + + public WebSocketResponse(String message) { + this.message = message; + this.throwable = null; + } + + public WebSocketResponse(Throwable throwable) { + this.message = null; + this.throwable = throwable; + } + + String message() { + if (throwable != null) { + throw new IllegalStateException("Request failed: " + throwable.getMessage(), throwable); + } + return message; + } + } }