Skip to content

Commit

Permalink
8301214: Adjust handshakeTimeout value in test HandshakeTimeout.java …
Browse files Browse the repository at this point in the history
…after 8189338

Reviewed-by: msheppar, vtewari
  • Loading branch information
djelinski committed Feb 8, 2023
1 parent ac7119f commit e628fd5
Showing 1 changed file with 13 additions and 70 deletions.
83 changes: 13 additions & 70 deletions test/jdk/java/rmi/transport/handshakeTimeout/HandshakeTimeout.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,24 @@
* 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;
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.
*/
Expand All @@ -76,69 +72,16 @@ public static void main(String[] args) throws Exception {
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");
}
}
}

1 comment on commit e628fd5

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.