Skip to content

Commit

Permalink
Backport 1d0250709a6ee97f5647edff589761bd9d0b7f4c
Browse files Browse the repository at this point in the history
  • Loading branch information
duke committed Jun 7, 2024
1 parent af699ff commit 18ff0d1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions test/jdk/sun/tools/jstatd/JstatdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public final class JstatdTest {
private static final int JSTAT_GCUTIL_INTERVAL_MS = 250;
private static final String JPS_OUTPUT_REGEX = "^\\d+\\s*.*";

private static final int MAX_JSTATD_TRIES = 10;

private boolean useDefaultPort = true;
private boolean useDefaultRmiPort = true;
private String port;
Expand Down Expand Up @@ -288,7 +290,7 @@ private void addToolArg(JDKToolLauncher launcher, String name, String value) {
private ProcessThread tryToSetupJstatdProcess() throws Throwable {
portInUse = false;
ProcessThread jstatdThread = new ProcessThread("Jstatd-Thread",
JstatdTest::isJstadReady, getJstatdCmd());
JstatdTest::isJstatdReady, getJstatdCmd());
try {
jstatdThread.start();
// Make sure jstatd is up and running
Expand All @@ -308,8 +310,8 @@ private ProcessThread tryToSetupJstatdProcess() throws Throwable {
return jstatdThread;
}

private static boolean isJstadReady(String line) {
if (line.contains("Port already in use")) {
private static boolean isJstatdReady(String line) {
if (line.contains("Port already in use") || line.contains("Could not bind")) {
portInUse = true;
return true;
}
Expand All @@ -328,8 +330,9 @@ private void runTest(boolean useShortSyntax) throws Throwable {
}

ProcessThread jstatdThread = null;
int tries = 0;
try {
while (jstatdThread == null) {
while (jstatdThread == null && ++tries <= MAX_JSTATD_TRIES) {
if (!useDefaultPort) {
port = String.valueOf(Utils.getFreePort());
}
Expand All @@ -345,10 +348,11 @@ private void runTest(boolean useShortSyntax) throws Throwable {
continue;
}
}

jstatdThread = tryToSetupJstatdProcess();
}

if (jstatdThread == null) {
throw new RuntimeException("Cannot start jstatd.");
}
runToolsAndVerify();
} finally {
cleanUpThread(jstatdThread);
Expand Down

0 comments on commit 18ff0d1

Please sign in to comment.