8301214: Adjust handshakeTimeout value in test HandshakeTimeout.java after 8189338

Reviewed-by: msheppar, vtewari
This commit is contained in:
Daniel Jeliński 2023-02-08 08:01:43 +00:00
parent ac7119f0d5
commit e628fd5c39

View File

@ -37,8 +37,10 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @run main/othervm HandshakeTimeout
* @run main/othervm HandshakeTimeout SSL
* @run main/othervm/timeout=10 -Dsun.rmi.transport.tcp.handshakeTimeout=1
* HandshakeTimeout
* @run main/othervm/timeout=10 -Dsun.rmi.transport.tcp.handshakeTimeout=1
* HandshakeTimeout SSL
*/
import javax.rmi.ssl.SslRMIClientSocketFactory;
@ -46,19 +48,13 @@ import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.rmi.ConnectException;
import java.rmi.ConnectIOException;
import java.rmi.MarshalException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class HandshakeTimeout {
private static final int TIMEOUT = 10000;
public static void main(String[] args) throws Exception {
System.setProperty("sun.rmi.transport.tcp.handshakeTimeout",
String.valueOf(TIMEOUT / 2));
/*
* Listen on port, but never process connections made to it.
*/
@ -76,69 +72,16 @@ public class HandshakeTimeout {
address.getPort(), new SslRMIClientSocketFactory());
}
Connector connector = new Connector(registry);
Thread t = new Thread(connector);
t.setDaemon(true);
t.start();
/*
* Wait for call attempt to finished, and analyze result.
*/
t.join(TIMEOUT);
synchronized (connector) {
if (connector.success) {
throw new RuntimeException(
try {
registry.lookup("Dale Cooper");
throw new RuntimeException(
"TEST FAILED: remote call succeeded??");
}
if (connector.exception == null) {
throw new RuntimeException(
"TEST FAILED: remote call did not time out");
} else {
System.err.println("remote call failed with exception:");
connector.exception.printStackTrace();
System.err.println();
if (connector.exception instanceof MarshalException) {
throw new RuntimeException(
"TEST FAILED: MarshalException thrown, expecting " +
"java.rmi.ConnectException or ConnectIOException");
} else if (connector.exception instanceof ConnectException ||
connector.exception instanceof ConnectIOException)
{
System.err.println(
"TEST PASSED: java.rmi.ConnectException or " +
"ConnectIOException thrown");
} else {
throw new RuntimeException(
"TEST FAILED: unexpected Exception thrown",
connector.exception);
}
}
}
}
private static class Connector implements Runnable {
private final Registry registry;
boolean success = false;
Exception exception = null;
Connector(Registry registry) {
this.registry = registry;
}
public void run() {
try {
registry.lookup("Dale Cooper");
synchronized (this) {
success = true;
}
} catch (Exception e) {
synchronized (this) {
exception = e;
}
}
} catch (ConnectException | ConnectIOException e) {
System.err.println("Got expected exception:");
e.printStackTrace();
System.err.println(
"TEST PASSED: java.rmi.ConnectException or " +
"ConnectIOException thrown");
}
}
}