提交 14f8e141 编写于 作者: J jbachorik

8146015: JMXInterfaceBindingTest is failing intermittently for IPv6 addresses

Reviewed-by: dfuchs, sspitsyn
上级 4f258664
...@@ -130,7 +130,7 @@ public class JMXAgentInterfaceBinding { ...@@ -130,7 +130,7 @@ public class JMXAgentInterfaceBinding {
private static class JMXConnectorThread extends Thread { private static class JMXConnectorThread extends Thread {
private final InetAddress addr; private final String addr;
private final int jmxPort; private final int jmxPort;
private final int rmiPort; private final int rmiPort;
private final boolean useSSL; private final boolean useSSL;
...@@ -139,7 +139,7 @@ public class JMXAgentInterfaceBinding { ...@@ -139,7 +139,7 @@ public class JMXAgentInterfaceBinding {
private boolean jmxConnectWorked; private boolean jmxConnectWorked;
private boolean rmiConnectWorked; private boolean rmiConnectWorked;
private JMXConnectorThread(InetAddress addr, private JMXConnectorThread(String addr,
int jmxPort, int jmxPort,
int rmiPort, int rmiPort,
boolean useSSL, boolean useSSL,
...@@ -163,11 +163,11 @@ public class JMXAgentInterfaceBinding { ...@@ -163,11 +163,11 @@ public class JMXAgentInterfaceBinding {
private void connect() throws IOException { private void connect() throws IOException {
System.out.println( System.out.println(
"JMXConnectorThread: Attempting JMX connection on: " "JMXConnectorThread: Attempting JMX connection on: "
+ addr.getHostAddress() + " on port " + jmxPort); + addr + " on port " + jmxPort);
JMXServiceURL url; JMXServiceURL url;
try { try {
url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"
+ addr.getHostAddress() + ":" + jmxPort + "/jmxrmi"); + addr + ":" + jmxPort + "/jmxrmi");
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
throw new RuntimeException("Test failed.", e); throw new RuntimeException("Test failed.", e);
} }
...@@ -200,7 +200,7 @@ public class JMXAgentInterfaceBinding { ...@@ -200,7 +200,7 @@ public class JMXAgentInterfaceBinding {
} }
System.out.println( System.out.println(
"JMXConnectorThread: connection to rmi socket worked host/port = " "JMXConnectorThread: connection to rmi socket worked host/port = "
+ addr.getHostAddress() + "/" + rmiPort); + addr + "/" + rmiPort);
rmiConnectWorked = true; rmiConnectWorked = true;
// Closing the channel without sending any data will cause an // Closing the channel without sending any data will cause an
// java.io.EOFException on the server endpoint. We don't care about this // java.io.EOFException on the server endpoint. We don't care about this
...@@ -224,7 +224,7 @@ public class JMXAgentInterfaceBinding { ...@@ -224,7 +224,7 @@ public class JMXAgentInterfaceBinding {
private static class MainThread extends Thread { private static class MainThread extends Thread {
private static final int WAIT_FOR_JMX_AGENT_TIMEOUT_MS = 500; private static final int WAIT_FOR_JMX_AGENT_TIMEOUT_MS = 500;
private final InetAddress bindAddress; private final String addr;
private final int jmxPort; private final int jmxPort;
private final int rmiPort; private final int rmiPort;
private final boolean useSSL; private final boolean useSSL;
...@@ -233,7 +233,7 @@ public class JMXAgentInterfaceBinding { ...@@ -233,7 +233,7 @@ public class JMXAgentInterfaceBinding {
private Exception excptn; private Exception excptn;
private MainThread(InetAddress bindAddress, int jmxPort, int rmiPort, boolean useSSL) { private MainThread(InetAddress bindAddress, int jmxPort, int rmiPort, boolean useSSL) {
this.bindAddress = bindAddress; this.addr = wrapAddress(bindAddress.getHostAddress());
this.jmxPort = jmxPort; this.jmxPort = jmxPort;
this.rmiPort = rmiPort; this.rmiPort = rmiPort;
this.useSSL = useSSL; this.useSSL = useSSL;
...@@ -259,7 +259,7 @@ public class JMXAgentInterfaceBinding { ...@@ -259,7 +259,7 @@ public class JMXAgentInterfaceBinding {
private void waitUntilReadyForConnections() { private void waitUntilReadyForConnections() {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
JMXConnectorThread connectionTester = new JMXConnectorThread( JMXConnectorThread connectionTester = new JMXConnectorThread(
bindAddress, jmxPort, rmiPort, useSSL, latch); addr, jmxPort, rmiPort, useSSL, latch);
connectionTester.start(); connectionTester.start();
boolean expired = false; boolean expired = false;
try { try {
...@@ -294,4 +294,13 @@ public class JMXAgentInterfaceBinding { ...@@ -294,4 +294,13 @@ public class JMXAgentInterfaceBinding {
} }
} }
/**
* Will wrap IPv6 address in '[]'
*/
static String wrapAddress(String address) {
if (address.contains(":")) {
return "[" + address + "]";
}
return address;
}
} }
...@@ -23,8 +23,10 @@ ...@@ -23,8 +23,10 @@
import java.io.File; import java.io.File;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -74,23 +76,24 @@ public class JMXInterfaceBindingTest { ...@@ -74,23 +76,24 @@ public class JMXInterfaceBindingTest {
"truststore"; "truststore";
public static final String TEST_CLASSPATH = System.getProperty("test.classes", "."); public static final String TEST_CLASSPATH = System.getProperty("test.classes", ".");
public void run(InetAddress[] addrs) { public void run(List<InetAddress> addrs) {
System.out.println("DEBUG: Running tests with plain sockets."); System.out.println("DEBUG: Running tests with plain sockets.");
runTests(addrs, false); runTests(addrs, false);
System.out.println("DEBUG: Running tests with SSL sockets."); System.out.println("DEBUG: Running tests with SSL sockets.");
runTests(addrs, true); runTests(addrs, true);
} }
private void runTests(InetAddress[] addrs, boolean useSSL) { private void runTests(List<InetAddress> addrs, boolean useSSL) {
TestProcessThread[] jvms = new TestProcessThread[addrs.length]; TestProcessThread[] jvms = new TestProcessThread[addrs.size()];
for (int i = 0; i < addrs.length; i++) { for (int i = 0; i < addrs.size(); i++) {
String addr = JMXAgentInterfaceBinding.wrapAddress(addrs.get(i).getHostAddress());
System.out.println(); System.out.println();
String msg = String.format("DEBUG: Launching java tester for triplet (HOSTNAME,JMX_PORT,RMI_PORT) == (%s,%d,%d)", String msg = String.format("DEBUG: Launching java tester for triplet (HOSTNAME,JMX_PORT,RMI_PORT) == (%s,%d,%d)",
addrs[i].getHostAddress(), addr,
JMX_PORT, JMX_PORT,
RMI_PORT); RMI_PORT);
System.out.println(msg); System.out.println(msg);
jvms[i] = runJMXBindingTest(addrs[i], useSSL); jvms[i] = runJMXBindingTest(addr, useSSL);
jvms[i].start(); jvms[i].start();
System.out.println("DEBUG: Started " + (i + 1) + " Process(es)."); System.out.println("DEBUG: Started " + (i + 1) + " Process(es).");
} }
...@@ -119,15 +122,15 @@ public class JMXInterfaceBindingTest { ...@@ -119,15 +122,15 @@ public class JMXInterfaceBindingTest {
} }
} }
if (failedProcesses > 0) { if (failedProcesses > 0) {
throw new RuntimeException("Test FAILED. " + failedProcesses + " out of " + addrs.length + " process(es) failed to start the JMX agent."); throw new RuntimeException("Test FAILED. " + failedProcesses + " out of " + addrs.size() + " process(es) failed to start the JMX agent.");
} }
} }
private TestProcessThread runJMXBindingTest(InetAddress a, boolean useSSL) { private TestProcessThread runJMXBindingTest(String address, boolean useSSL) {
List<String> args = new ArrayList<>(); List<String> args = new ArrayList<>();
args.add("-classpath"); args.add("-classpath");
args.add(TEST_CLASSPATH); args.add(TEST_CLASSPATH);
args.add("-Dcom.sun.management.jmxremote.host=" + a.getHostAddress()); args.add("-Dcom.sun.management.jmxremote.host=" + address);
args.add("-Dcom.sun.management.jmxremote.port=" + JMX_PORT); args.add("-Dcom.sun.management.jmxremote.port=" + JMX_PORT);
args.add("-Dcom.sun.management.jmxremote.rmi.port=" + RMI_PORT); args.add("-Dcom.sun.management.jmxremote.rmi.port=" + RMI_PORT);
args.add("-Dcom.sun.management.jmxremote.authenticate=false"); args.add("-Dcom.sun.management.jmxremote.authenticate=false");
...@@ -140,14 +143,14 @@ public class JMXInterfaceBindingTest { ...@@ -140,14 +143,14 @@ public class JMXInterfaceBindingTest {
args.add("-Djavax.net.ssl.trustStorePassword=trustword"); args.add("-Djavax.net.ssl.trustStorePassword=trustword");
} }
args.add(TEST_CLASS); args.add(TEST_CLASS);
args.add(a.getHostAddress()); args.add(address);
args.add(Integer.toString(JMX_PORT)); args.add(Integer.toString(JMX_PORT));
args.add(Integer.toString(RMI_PORT)); args.add(Integer.toString(RMI_PORT));
args.add(Boolean.toString(useSSL)); args.add(Boolean.toString(useSSL));
try { try {
ProcessBuilder builder = ProcessTools.createJavaProcessBuilder(args.toArray(new String[] {})); ProcessBuilder builder = ProcessTools.createJavaProcessBuilder(args.toArray(new String[] {}));
System.out.println(ProcessTools.getCommandLine(builder)); System.out.println(ProcessTools.getCommandLine(builder));
TestProcessThread jvm = new TestProcessThread("JMX-Tester-" + a.getHostAddress(), JMXInterfaceBindingTest::isJMXAgentResponseAvailable, builder); TestProcessThread jvm = new TestProcessThread("JMX-Tester-" + address, JMXInterfaceBindingTest::isJMXAgentResponseAvailable, builder);
return jvm; return jvm;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Test failed", e); throw new RuntimeException("Test failed", e);
...@@ -173,8 +176,8 @@ public class JMXInterfaceBindingTest { ...@@ -173,8 +176,8 @@ public class JMXInterfaceBindingTest {
} }
public static void main(String[] args) { public static void main(String[] args) {
InetAddress[] addrs = getAddressesForLocalHost(); List<InetAddress> addrs = getAddressesForLocalHost();
if (addrs.length < 2) { if (addrs.size() < 2) {
System.out.println("Ignoring manual test since no more than one IPs are configured for 'localhost'"); System.out.println("Ignoring manual test since no more than one IPs are configured for 'localhost'");
return; return;
} }
...@@ -183,14 +186,29 @@ public class JMXInterfaceBindingTest { ...@@ -183,14 +186,29 @@ public class JMXInterfaceBindingTest {
System.out.println("All tests PASSED."); System.out.println("All tests PASSED.");
} }
private static InetAddress[] getAddressesForLocalHost() { private static List<InetAddress> getAddressesForLocalHost() {
InetAddress[] addrs;
try { try {
addrs = InetAddress.getAllByName("localhost"); List<InetAddress> filtered = new ArrayList<>();
} catch (UnknownHostException e) { for (NetworkInterface iface: Collections.list(NetworkInterface.getNetworkInterfaces())) {
for (InetAddress addr: Collections.list(iface.getInetAddresses())) {
if (isNonloopbackLocalhost(addr)) {
filtered.add(addr);
}
}
}
return filtered;
} catch (SocketException e) {
throw new RuntimeException("Test failed", e); throw new RuntimeException("Test failed", e);
} }
return addrs; }
// we need 'real' localhost addresses only (eg. not loopback ones)
// so we can bind the remote JMX connector to them
private static boolean isNonloopbackLocalhost(InetAddress i) {
if (!i.isLoopbackAddress()) {
return i.getHostName().toLowerCase().equals("localhost");
}
return false;
} }
private static class TestProcessThread extends Thread { private static class TestProcessThread extends Thread {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册