diff --git a/src/test/java/itest/CustomTargetsIT.java b/src/test/java/itest/CustomTargetsIT.java index b6ec3d390..92d3d0484 100644 --- a/src/test/java/itest/CustomTargetsIT.java +++ b/src/test/java/itest/CustomTargetsIT.java @@ -21,7 +21,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; -import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -51,7 +51,7 @@ @TestMethodOrder(OrderAnnotation.class) public class CustomTargetsIT extends StandardSelfTest { - private final ExecutorService worker = ForkJoinPool.commonPool(); + private final ExecutorService worker = Executors.newCachedThreadPool(); static final Map NULL_RESULT = new HashMap<>(); private String itestJvmId; private static StoredCredential storedCredential; diff --git a/src/test/java/itest/bases/StandardSelfTest.java b/src/test/java/itest/bases/StandardSelfTest.java index 431ad7b98..443affa69 100644 --- a/src/test/java/itest/bases/StandardSelfTest.java +++ b/src/test/java/itest/bases/StandardSelfTest.java @@ -21,7 +21,8 @@ import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -53,6 +54,7 @@ public abstract class StandardSelfTest { private static final String SELFTEST_ALIAS = "selftest"; + private static final ExecutorService WORKER = Executors.newCachedThreadPool(); public static final Logger logger = Logger.getLogger(StandardSelfTest.class); public static final ObjectMapper mapper = new ObjectMapper(); public static final int REQUEST_TIMEOUT_SECONDS = 30; @@ -65,24 +67,23 @@ public static void waitForDiscovery() { while (!found && System.nanoTime() < deadline) { logger.infov("Waiting for discovery to see at least one target..."); CompletableFuture queryFound = new CompletableFuture<>(); - ForkJoinPool.commonPool() - .submit( - () -> { - webClient - .get("/api/v3/targets") - .basicAuthentication("user", "pass") - .as(BodyCodec.jsonArray()) - .timeout(500) - .send( - ar -> { - if (ar.failed()) { - logger.error(ar.cause()); - return; - } - JsonArray arr = ar.result().body(); - queryFound.complete(arr.size() >= 1); - }); - }); + WORKER.submit( + () -> { + webClient + .get("/api/v3/targets") + .basicAuthentication("user", "pass") + .as(BodyCodec.jsonArray()) + .timeout(500) + .send( + ar -> { + if (ar.failed()) { + logger.error(ar.cause()); + return; + } + JsonArray arr = ar.result().body(); + queryFound.complete(arr.size() >= 1); + }); + }); try { found |= queryFound.get(500, TimeUnit.MILLISECONDS); if (!found) { @@ -108,29 +109,28 @@ private static void tryDefineSelfCustomTarget() { "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi", "alias", SELFTEST_ALIAS)); - ForkJoinPool.commonPool() - .submit( - () -> { - webClient - .post("/api/v2/targets") - .basicAuthentication("user", "pass") - .timeout(500) - .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()); - }); - }); + WORKER.submit( + () -> { + webClient + .post("/api/v2/targets") + .basicAuthentication("user", "pass") + .timeout(500) + .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); } @@ -138,37 +138,34 @@ private static void tryDefineSelfCustomTarget() { public static String getSelfReferenceConnectUrl() { CompletableFuture future = new CompletableFuture<>(); - ForkJoinPool.commonPool() - .submit( - () -> { - webClient - .get("/api/v3/targets") - .basicAuthentication("user", "pass") - .as(BodyCodec.jsonArray()) - .timeout(5000) - .send( - ar -> { - if (ar.failed()) { - logger.error(ar.cause()); - return; - } - JsonArray arr = ar.result().body(); - boolean found = false; - for (int i = 0; i < arr.size(); i++) { - JsonObject obj = arr.getJsonObject(i); - if (SELFTEST_ALIAS.equals( - obj.getString("alias"))) { - future.complete(obj); - found = true; - break; - } - } - if (!found) { - future.completeExceptionally( - new NotFoundException()); - } - }); - }); + WORKER.submit( + () -> { + webClient + .get("/api/v3/targets") + .basicAuthentication("user", "pass") + .as(BodyCodec.jsonArray()) + .timeout(5000) + .send( + ar -> { + if (ar.failed()) { + logger.error(ar.cause()); + return; + } + JsonArray arr = ar.result().body(); + boolean found = false; + for (int i = 0; i < arr.size(); i++) { + JsonObject obj = arr.getJsonObject(i); + if (SELFTEST_ALIAS.equals(obj.getString("alias"))) { + future.complete(obj); + found = true; + break; + } + } + if (!found) { + future.completeExceptionally(new NotFoundException()); + } + }); + }); try { JsonObject obj = future.get(5000, TimeUnit.MILLISECONDS); return obj.getString("connectUrl");