Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8240711: TestJstatdPort.java failed due to "ExportException: Port alr…
…eady in use:"

Reviewed-by: amenkov
  • Loading branch information
Daniil Titov committed Mar 18, 2020
1 parent c6cec8a commit b70ef0d2e256085b48f8d5b0f131bca89b699609
Showing with 10 additions and 13 deletions.
  1. +10 −13 test/jdk/sun/tools/jstatd/JstatdTest.java
@@ -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;
}
@@ -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;
}
@@ -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 {
@@ -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 ");
}

0 comments on commit b70ef0d

Please sign in to comment.