Skip to content

Commit

Permalink
extract utility
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Nov 6, 2023
1 parent 8f6953c commit 299a254
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/test/java/itest/bases/StandardSelfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> queryFound = new CompletableFuture<>();
WORKER.submit(
() -> {
Expand All @@ -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 {
Expand Down Expand Up @@ -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<Buffer> 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<Buffer> resp = ar.result();
logger.infov(
"HTTP {0} {1}: {2} [{3}]",
resp.statusCode(),
resp.statusMessage(),
resp.bodyAsString(),
resp.headers());
});
} catch (Exception e) {
logger.warn(e);
}
Expand Down

0 comments on commit 299a254

Please sign in to comment.