37
37
* java.rmi/sun.rmi.server
38
38
* java.rmi/sun.rmi.transport
39
39
* 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
42
44
*/
43
45
44
46
import javax .rmi .ssl .SslRMIClientSocketFactory ;
45
47
import java .net .InetSocketAddress ;
46
48
import java .net .ServerSocket ;
47
49
import java .rmi .ConnectException ;
48
50
import java .rmi .ConnectIOException ;
49
- import java .rmi .MarshalException ;
50
51
import java .rmi .registry .LocateRegistry ;
51
52
import java .rmi .registry .Registry ;
52
53
53
54
public class HandshakeTimeout {
54
55
55
- private static final int TIMEOUT = 10000 ;
56
-
57
56
public static void main (String [] args ) throws Exception {
58
57
59
- System .setProperty ("sun.rmi.transport.tcp.handshakeTimeout" ,
60
- String .valueOf (TIMEOUT / 2 ));
61
-
62
58
/*
63
59
* Listen on port, but never process connections made to it.
64
60
*/
@@ -76,69 +72,16 @@ public static void main(String[] args) throws Exception {
76
72
address .getPort (), new SslRMIClientSocketFactory ());
77
73
}
78
74
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 (
91
78
"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" );
142
85
}
143
86
}
144
87
}
0 commit comments