提交 6e960911 编写于 作者: J jbachorik

8034177: sun/management/jmxremote/startstop/JMXStartStopTest.java should report port in use

Reviewed-by: dfuchs, sjiang
上级 34929b0e
...@@ -25,6 +25,7 @@ import java.io.File; ...@@ -25,6 +25,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.ServerSocket;
import java.rmi.NoSuchObjectException; import java.rmi.NoSuchObjectException;
import java.rmi.registry.LocateRegistry; import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry; import java.rmi.registry.Registry;
...@@ -255,26 +256,23 @@ public class JMXStartStopTest { ...@@ -255,26 +256,23 @@ public class JMXStartStopTest {
private static List<Failure> failures = new ArrayList<>(); private static List<Failure> failures = new ArrayList<>();
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
for (int i=0;i<3;i++) { for (Method m : JMXStartStopTest.class.getDeclaredMethods()) {
System.out.println("=== PASS " + i + " ==="); if (m.getName().startsWith("test_")) {
for (Method m : JMXStartStopTest.class.getDeclaredMethods()) { try {
if (m.getName().startsWith("test_")) { m.invoke(null);
try { System.out.println("=== PASSED\n");
m.invoke(null); } catch (Throwable e) {
System.out.println("=== PASSED\n"); failures.add(new Failure(e, m.getName() + " failed"));
} catch (Throwable e) {
failures.add(new Failure(e, m.getName() + " failed"));
}
} }
} }
}
if (!failures.isEmpty()) { if (!failures.isEmpty()) {
for(Failure f : failures) { for(Failure f : failures) {
System.err.println(f.getMsg()); System.err.println(f.getMsg());
f.getCause().printStackTrace(System.err); f.getCause().printStackTrace(System.err);
}
throw new Error();
} }
throw new Error();
} }
} }
...@@ -371,6 +369,7 @@ public class JMXStartStopTest { ...@@ -371,6 +369,7 @@ public class JMXStartStopTest {
)); ));
pbArgs.addAll(Arrays.asList(args)); pbArgs.addAll(Arrays.asList(args));
pbArgs.add("JMXStartStopDoSomething"); pbArgs.add("JMXStartStopDoSomething");
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
pbArgs.toArray(new String[pbArgs.size()]) pbArgs.toArray(new String[pbArgs.size()])
); );
...@@ -596,14 +595,16 @@ public class JMXStartStopTest { ...@@ -596,14 +595,16 @@ public class JMXStartStopTest {
jcmd(CMD_STOP); jcmd(CMD_STOP);
jcmd(CMD_STOP); jcmd(CMD_STOP);
ServerSocket ss = new ServerSocket(0);
jcmd( jcmd(
line -> { line -> {
if (line.contains("Port already in use: 22")) { if (line.contains("Port already in use: " + ss.getLocalPort())) {
checks[2] = true; checks[2] = true;
} }
}, },
CMD_START, CMD_START,
"jmxremote.port=22", "jmxremote.port=" + ss.getLocalPort(),
"jmxremote.rmi.port=" + port2, "jmxremote.rmi.port=" + port2,
"jmxremote.authenticate=false", "jmxremote.authenticate=false",
"jmxremote.ssl=false"); "jmxremote.ssl=false");
...@@ -616,7 +617,7 @@ public class JMXStartStopTest { ...@@ -616,7 +617,7 @@ public class JMXStartStopTest {
"report an invalid agent state"); "report an invalid agent state");
} }
if (!checks[2]) { if (!checks[2]) {
throw new Exception("Starting agent on port 22 should " + throw new Exception("Starting agent on port " + ss.getLocalPort() + " should " +
"report port in use"); "report port in use");
} }
} finally { } finally {
...@@ -627,7 +628,7 @@ public class JMXStartStopTest { ...@@ -627,7 +628,7 @@ public class JMXStartStopTest {
private static void test_07() throws Exception { private static void test_07() throws Exception {
// Run an app without JMX enabled, but with some properties set // Run an app without JMX enabled, but with some properties set
// in command line. // in command line.
// make sure these properties overriden corectly // make sure these properties overridden corectly
System.out.println("**** Test seven ****"); System.out.println("**** Test seven ****");
...@@ -654,7 +655,7 @@ public class JMXStartStopTest { ...@@ -654,7 +655,7 @@ public class JMXStartStopTest {
// Run an app with JMX enabled and with some properties set // Run an app with JMX enabled and with some properties set
// in command line. // in command line.
// stop JMX agent and then start it again with different property values // stop JMX agent and then start it again with different property values
// make sure these properties overriden corectly // make sure these properties overridden corectly
System.out.println("**** Test eight ****"); System.out.println("**** Test eight ****");
...@@ -690,7 +691,7 @@ public class JMXStartStopTest { ...@@ -690,7 +691,7 @@ public class JMXStartStopTest {
// stop JMX agent and then start it again with different property values // stop JMX agent and then start it again with different property values
// specifing some property in management config file and some of them // specifing some property in management config file and some of them
// in command line // in command line
// make sure these properties overriden corectly // make sure these properties overridden corectly
System.out.println("**** Test nine ****"); System.out.println("**** Test nine ****");
...@@ -725,7 +726,7 @@ public class JMXStartStopTest { ...@@ -725,7 +726,7 @@ public class JMXStartStopTest {
// in command line. // in command line.
// stop JMX agent and then start it again with different property values // stop JMX agent and then start it again with different property values
// stop JMX agent again and then start it without property value // stop JMX agent again and then start it without property value
// make sure these properties overriden corectly // make sure these properties overridden corectly
System.out.println("**** Test ten ****"); System.out.println("**** Test ten ****");
...@@ -800,7 +801,7 @@ public class JMXStartStopTest { ...@@ -800,7 +801,7 @@ public class JMXStartStopTest {
// Run an app with -javaagent make sure it works as expected - // Run an app with -javaagent make sure it works as expected -
// system properties are ignored // system properties are ignored
System.out.println("**** Test fourteen ****"); System.out.println("**** Test thirteen ****");
String agent = TEST_JDK + "/jre/lib/management-agent.jar"; String agent = TEST_JDK + "/jre/lib/management-agent.jar";
if (!new File(agent).exists()) { if (!new File(agent).exists()) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册