Skip to content

Commit e628fd5

Browse files
committed
8301214: Adjust handshakeTimeout value in test HandshakeTimeout.java after 8189338
Reviewed-by: msheppar, vtewari
1 parent ac7119f commit e628fd5

File tree

1 file changed

+13
-70
lines changed

1 file changed

+13
-70
lines changed

test/jdk/java/rmi/transport/handshakeTimeout/HandshakeTimeout.java

Lines changed: 13 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,24 @@
3737
* java.rmi/sun.rmi.server
3838
* java.rmi/sun.rmi.transport
3939
* java.rmi/sun.rmi.transport.tcp
40-
* @run main/othervm HandshakeTimeout
41-
* @run main/othervm HandshakeTimeout SSL
40+
* @run main/othervm/timeout=10 -Dsun.rmi.transport.tcp.handshakeTimeout=1
41+
* HandshakeTimeout
42+
* @run main/othervm/timeout=10 -Dsun.rmi.transport.tcp.handshakeTimeout=1
43+
* HandshakeTimeout SSL
4244
*/
4345

4446
import javax.rmi.ssl.SslRMIClientSocketFactory;
4547
import java.net.InetSocketAddress;
4648
import java.net.ServerSocket;
4749
import java.rmi.ConnectException;
4850
import java.rmi.ConnectIOException;
49-
import java.rmi.MarshalException;
5051
import java.rmi.registry.LocateRegistry;
5152
import java.rmi.registry.Registry;
5253

5354
public class HandshakeTimeout {
5455

55-
private static final int TIMEOUT = 10000;
56-
5756
public static void main(String[] args) throws Exception {
5857

59-
System.setProperty("sun.rmi.transport.tcp.handshakeTimeout",
60-
String.valueOf(TIMEOUT / 2));
61-
6258
/*
6359
* Listen on port, but never process connections made to it.
6460
*/
@@ -76,69 +72,16 @@ public static void main(String[] args) throws Exception {
7672
address.getPort(), new SslRMIClientSocketFactory());
7773
}
7874

79-
Connector connector = new Connector(registry);
80-
Thread t = new Thread(connector);
81-
t.setDaemon(true);
82-
t.start();
83-
84-
/*
85-
* Wait for call attempt to finished, and analyze result.
86-
*/
87-
t.join(TIMEOUT);
88-
synchronized (connector) {
89-
if (connector.success) {
90-
throw new RuntimeException(
75+
try {
76+
registry.lookup("Dale Cooper");
77+
throw new RuntimeException(
9178
"TEST FAILED: remote call succeeded??");
92-
}
93-
if (connector.exception == null) {
94-
throw new RuntimeException(
95-
"TEST FAILED: remote call did not time out");
96-
} else {
97-
System.err.println("remote call failed with exception:");
98-
connector.exception.printStackTrace();
99-
System.err.println();
100-
101-
if (connector.exception instanceof MarshalException) {
102-
throw new RuntimeException(
103-
"TEST FAILED: MarshalException thrown, expecting " +
104-
"java.rmi.ConnectException or ConnectIOException");
105-
} else if (connector.exception instanceof ConnectException ||
106-
connector.exception instanceof ConnectIOException)
107-
{
108-
System.err.println(
109-
"TEST PASSED: java.rmi.ConnectException or " +
110-
"ConnectIOException thrown");
111-
} else {
112-
throw new RuntimeException(
113-
"TEST FAILED: unexpected Exception thrown",
114-
connector.exception);
115-
}
116-
}
117-
}
118-
}
119-
120-
private static class Connector implements Runnable {
121-
122-
private final Registry registry;
123-
124-
boolean success = false;
125-
Exception exception = null;
126-
127-
Connector(Registry registry) {
128-
this.registry = registry;
129-
}
130-
131-
public void run() {
132-
try {
133-
registry.lookup("Dale Cooper");
134-
synchronized (this) {
135-
success = true;
136-
}
137-
} catch (Exception e) {
138-
synchronized (this) {
139-
exception = e;
140-
}
141-
}
79+
} catch (ConnectException | ConnectIOException e) {
80+
System.err.println("Got expected exception:");
81+
e.printStackTrace();
82+
System.err.println(
83+
"TEST PASSED: java.rmi.ConnectException or " +
84+
"ConnectIOException thrown");
14285
}
14386
}
14487
}

0 commit comments

Comments
 (0)