From 299a254c02af30bb1ee15f3a4609705f7921b5f9 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Mon, 6 Nov 2023 17:08:29 -0500 Subject: [PATCH] extract utility --- .../java/itest/bases/StandardSelfTest.java | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/test/java/itest/bases/StandardSelfTest.java b/src/test/java/itest/bases/StandardSelfTest.java index 352be9151..a36f6d432 100644 --- a/src/test/java/itest/bases/StandardSelfTest.java +++ b/src/test/java/itest/bases/StandardSelfTest.java @@ -62,10 +62,15 @@ public abstract class StandardSelfTest { @BeforeAll public static void waitForDiscovery() { + waitForDiscovery(0); + } + + public static void waitForDiscovery(int otherTargetsCount) { + final int totalTargets = otherTargetsCount + 1; boolean found = false; long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(REQUEST_TIMEOUT_SECONDS); while (!found && System.nanoTime() < deadline) { - logger.infov("Waiting for discovery to see at least one target..."); + logger.infov("Waiting for discovery to see at least {0} target(s)...", totalTargets); CompletableFuture queryFound = new CompletableFuture<>(); WORKER.submit( () -> { @@ -81,7 +86,7 @@ public static void waitForDiscovery() { return; } JsonArray arr = ar.result().body(); - queryFound.complete(arr.size() >= 1); + queryFound.complete(arr.size() == totalTargets); }); }); try { @@ -109,28 +114,25 @@ private static void tryDefineSelfCustomTarget() { "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi", "alias", SELFTEST_ALIAS)); - WORKER.submit( - () -> { - webClient - .post("/api/v2/targets") - .basicAuthentication("user", "pass") - .timeout(5000) - .sendJson( - self, - ar -> { - if (ar.failed()) { - logger.error(ar.cause()); - return; - } - HttpResponse resp = ar.result(); - logger.infov( - "HTTP {0} {1}: {2} [{3}]", - resp.statusCode(), - resp.statusMessage(), - resp.bodyAsString(), - resp.headers()); - }); - }); + webClient + .post("/api/v2/targets") + .basicAuthentication("user", "pass") + .timeout(5000) + .sendJson( + self, + ar -> { + if (ar.failed()) { + logger.error(ar.cause()); + return; + } + HttpResponse resp = ar.result(); + logger.infov( + "HTTP {0} {1}: {2} [{3}]", + resp.statusCode(), + resp.statusMessage(), + resp.bodyAsString(), + resp.headers()); + }); } catch (Exception e) { logger.warn(e); }