8073794: jdk/test/com/sun/jdi/BadHandshakeTest.java should retry if tcp port is taken
Reviewed-by: jbachorik
This commit is contained in:
parent
03e307c40a
commit
20be94ae55
@ -283,9 +283,6 @@ tools/launcher/FXLauncherTest.java linux-all
|
|||||||
|
|
||||||
# jdk_jdi
|
# jdk_jdi
|
||||||
|
|
||||||
# 6983531
|
|
||||||
com/sun/jdi/BadHandshakeTest.java linux-all,windows-all
|
|
||||||
|
|
||||||
# 8004127
|
# 8004127
|
||||||
com/sun/jdi/RedefineImplementor.sh generic-all
|
com/sun/jdi/RedefineImplementor.sh generic-all
|
||||||
|
|
||||||
|
@ -21,22 +21,15 @@
|
|||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @test
|
|
||||||
* @bug 6306165 6432567
|
|
||||||
* @summary Check that a bad handshake doesn't cause a debuggee to abort
|
|
||||||
* @library /lib/testlibrary
|
|
||||||
*
|
|
||||||
* @build jdk.testlibrary.* VMConnection BadHandshakeTest Exit0
|
|
||||||
* @run driver BadHandshakeTest
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.InetAddress;
|
|
||||||
import com.sun.jdi.Bootstrap;
|
import com.sun.jdi.Bootstrap;
|
||||||
import com.sun.jdi.VirtualMachine;
|
import com.sun.jdi.VirtualMachine;
|
||||||
import com.sun.jdi.event.*;
|
import com.sun.jdi.event.*;
|
||||||
import com.sun.jdi.connect.Connector;
|
import com.sun.jdi.connect.Connector;
|
||||||
import com.sun.jdi.connect.AttachingConnector;
|
import com.sun.jdi.connect.AttachingConnector;
|
||||||
|
import com.sun.jdi.connect.Connector.Argument;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -46,13 +39,22 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
import jdk.testlibrary.Utils;
|
import jdk.testlibrary.Utils;
|
||||||
import jdk.testlibrary.ProcessTools;
|
import jdk.testlibrary.ProcessTools;
|
||||||
|
|
||||||
|
/* @test
|
||||||
|
* @bug 6306165 6432567
|
||||||
|
* @summary Check that a bad handshake doesn't cause a debuggee to abort
|
||||||
|
* @library /lib/testlibrary
|
||||||
|
*
|
||||||
|
* @build jdk.testlibrary.* VMConnection BadHandshakeTest Exit0
|
||||||
|
* @run driver BadHandshakeTest
|
||||||
|
*/
|
||||||
public class BadHandshakeTest {
|
public class BadHandshakeTest {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find a connector by name
|
* Find a connector by name
|
||||||
*/
|
*/
|
||||||
private static Connector findConnector(String name) {
|
private static Connector findConnector(String name) {
|
||||||
List connectors = Bootstrap.virtualMachineManager().allConnectors();
|
List<Connector> connectors = Bootstrap.virtualMachineManager().allConnectors();
|
||||||
Iterator iter = connectors.iterator();
|
Iterator<Connector> iter = connectors.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Connector connector = (Connector)iter.next();
|
Connector connector = (Connector)iter.next();
|
||||||
if (connector.name().equals(name)) {
|
if (connector.name().equals(name)) {
|
||||||
@ -65,7 +67,7 @@ public class BadHandshakeTest {
|
|||||||
/*
|
/*
|
||||||
* Launch a server debuggee with the given address
|
* Launch a server debuggee with the given address
|
||||||
*/
|
*/
|
||||||
private static Process launch(String address, String class_name) throws Exception {
|
private static LaunchResult launch(String address, String class_name) throws Exception {
|
||||||
String[] args = VMConnection.insertDebuggeeVMOptions(new String[] {
|
String[] args = VMConnection.insertDebuggeeVMOptions(new String[] {
|
||||||
"-agentlib:jdwp=transport=dt_socket" +
|
"-agentlib:jdwp=transport=dt_socket" +
|
||||||
",server=y" + ",suspend=y" + ",address=" + address,
|
",server=y" + ",suspend=y" + ",address=" + address,
|
||||||
@ -75,6 +77,7 @@ public class BadHandshakeTest {
|
|||||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
|
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
|
||||||
|
|
||||||
final AtomicBoolean success = new AtomicBoolean();
|
final AtomicBoolean success = new AtomicBoolean();
|
||||||
|
final AtomicBoolean bindFailed = new AtomicBoolean();
|
||||||
Process p = ProcessTools.startProcess(
|
Process p = ProcessTools.startProcess(
|
||||||
class_name,
|
class_name,
|
||||||
pb,
|
pb,
|
||||||
@ -83,13 +86,17 @@ public class BadHandshakeTest {
|
|||||||
// Listening for transport dt_socket at address: xxxxx
|
// Listening for transport dt_socket at address: xxxxx
|
||||||
// which shows the debuggee is ready to accept connections.
|
// which shows the debuggee is ready to accept connections.
|
||||||
success.set(line.contains("Listening for transport dt_socket at address:"));
|
success.set(line.contains("Listening for transport dt_socket at address:"));
|
||||||
|
// If the first line contains 'Address already in use'
|
||||||
|
// that means the debuggee has failed to start due to busy port
|
||||||
|
bindFailed.set(line.contains("Address already in use"));
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
Integer.MAX_VALUE,
|
Integer.MAX_VALUE,
|
||||||
TimeUnit.MILLISECONDS
|
TimeUnit.MILLISECONDS
|
||||||
);
|
);
|
||||||
|
|
||||||
return success.get() ? p : null;
|
return new LaunchResult(success.get() ? p : null,
|
||||||
|
bindFailed.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -99,15 +106,21 @@ public class BadHandshakeTest {
|
|||||||
* - verify we saw no error
|
* - verify we saw no error
|
||||||
*/
|
*/
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
int port = Utils.getFreePort();
|
// Launch the server debuggee
|
||||||
|
int port = 0;
|
||||||
|
Process process = null;
|
||||||
|
while (process == null) {
|
||||||
|
port = Utils.getFreePort();
|
||||||
String address = String.valueOf(port);
|
String address = String.valueOf(port);
|
||||||
|
LaunchResult launchResult = launch(address, "Exit0");
|
||||||
// launch the server debuggee
|
process = launchResult.getProcess();
|
||||||
Process process = launch(address, "Exit0");
|
if (launchResult.isBindFailed()) {
|
||||||
if (process == null) {
|
System.out.println("Port " + port + " already in use. Trying to restart debuggee with a new one...");
|
||||||
|
Thread.sleep(100);
|
||||||
|
} else if (process == null ) {
|
||||||
throw new RuntimeException("Unable to start debugee");
|
throw new RuntimeException("Unable to start debugee");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Connect to the debuggee and handshake with garbage
|
// Connect to the debuggee and handshake with garbage
|
||||||
Socket s = new Socket("localhost", port);
|
Socket s = new Socket("localhost", port);
|
||||||
@ -119,9 +132,9 @@ public class BadHandshakeTest {
|
|||||||
s.getOutputStream().write("JDWP-".getBytes("UTF-8"));
|
s.getOutputStream().write("JDWP-".getBytes("UTF-8"));
|
||||||
|
|
||||||
|
|
||||||
// attach to server debuggee and resume it so it can exit
|
// Attach to server debuggee and resume it so it can exit
|
||||||
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
|
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
|
||||||
Map conn_args = conn.defaultArguments();
|
Map<String, Argument> conn_args = conn.defaultArguments();
|
||||||
Connector.IntegerArgument port_arg =
|
Connector.IntegerArgument port_arg =
|
||||||
(Connector.IntegerArgument)conn_args.get("port");
|
(Connector.IntegerArgument)conn_args.get("port");
|
||||||
port_arg.setValue(port);
|
port_arg.setValue(port);
|
||||||
@ -143,4 +156,24 @@ public class BadHandshakeTest {
|
|||||||
process.waitFor();
|
process.waitFor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class LaunchResult {
|
||||||
|
|
||||||
|
private final Process p;
|
||||||
|
private final boolean bindFailed;
|
||||||
|
|
||||||
|
public LaunchResult(Process p, boolean bindFailed) {
|
||||||
|
this.p = p;
|
||||||
|
this.bindFailed = bindFailed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Process getProcess() {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBindFailed() {
|
||||||
|
return bindFailed;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user