Skip to content

Commit

Permalink
8240711: TestJstatdPort.java failed due to "ExportException: Port alr…
Browse files Browse the repository at this point in the history
…eady in use:"

Reviewed-by: amenkov
  • Loading branch information
Daniil Titov committed Mar 18, 2020
1 parent c6cec8a commit b70ef0d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions test/jdk/sun/tools/jstatd/JstatdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public final class JstatdTest {
private boolean withExternalRegistry = false;
private boolean useShortCommandSyntax = false;

private volatile static boolean portInUse;

public void setServerName(String serverName) {
this.serverName = serverName;
}
Expand All @@ -91,20 +93,10 @@ public void setWithExternalRegistry(boolean withExternalRegistry) {

private Long waitOnTool(ProcessThread thread) throws Throwable {
long pid = thread.getPid();

Throwable t = thread.getUncaught();
if (t != null) {
if (t.getMessage().contains(
"java.rmi.server.ExportException: Port already in use")) {
System.out.println("Port already in use. Trying to restart with a new one...");
Thread.sleep(100);
return null;
} else {
// Something unexpected has happened
throw new Throwable(t);
}
if (portInUse) {
System.out.println("Port already in use. Trying to restart with a new one...");
return null;
}

System.out.println(thread.getName() + " pid: " + pid);
return pid;
}
Expand Down Expand Up @@ -291,6 +283,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());
try {
Expand All @@ -313,6 +306,10 @@ private ProcessThread tryToSetupJstatdProcess() throws Throwable {
}

private static boolean isJstadReady(String line) {
if (line.contains("Port already in use")) {
portInUse = true;
return true;
}
return line.startsWith("jstatd started (bound to ");
}

Expand Down

0 comments on commit b70ef0d

Please sign in to comment.