Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 7d0aaf1

Browse files
Olga MikhaltsovaYuri Nesterenko
Olga Mikhaltsova
authored and
Yuri Nesterenko
committed
8240711: TestJstatdPort.java failed due to "ExportException: Port already in use:"
Backport-of: b70ef0d
1 parent 71ed1cd commit 7d0aaf1

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

test/jdk/sun/tools/jstatd/JstatdTest.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public final class JstatdTest {
7070
private Long jstatdPid;
7171
private boolean withExternalRegistry = false;
7272

73+
private volatile static boolean portInUse;
74+
7375
public void setServerName(String serverName) {
7476
this.serverName = serverName;
7577
}
@@ -84,20 +86,10 @@ public void setWithExternalRegistry(boolean withExternalRegistry) {
8486

8587
private Long waitOnTool(ProcessThread thread) throws Throwable {
8688
long pid = thread.getPid();
87-
88-
Throwable t = thread.getUncaught();
89-
if (t != null) {
90-
if (t.getMessage().contains(
91-
"java.rmi.server.ExportException: Port already in use")) {
92-
System.out.println("Port already in use. Trying to restart with a new one...");
93-
Thread.sleep(100);
94-
return null;
95-
} else {
96-
// Something unexpected has happened
97-
throw new Throwable(t);
98-
}
89+
if (portInUse) {
90+
System.out.println("Port already in use. Trying to restart with a new one...");
91+
return null;
9992
}
100-
10193
System.out.println(thread.getName() + " pid: " + pid);
10294
return pid;
10395
}
@@ -274,6 +266,7 @@ private String[] getJstatdCmd() throws Exception {
274266
}
275267

276268
private ProcessThread tryToSetupJstatdProcess() throws Throwable {
269+
portInUse = false;
277270
ProcessThread jstatdThread = new ProcessThread("Jstatd-Thread",
278271
JstatdTest::isJstadReady, getJstatdCmd());
279272
try {
@@ -296,6 +289,10 @@ private ProcessThread tryToSetupJstatdProcess() throws Throwable {
296289
}
297290

298291
private static boolean isJstadReady(String line) {
292+
if (line.contains("Port already in use")) {
293+
portInUse = true;
294+
return true;
295+
}
299296
return line.startsWith("jstatd started (bound to ");
300297
}
301298

0 commit comments

Comments
 (0)