Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/rmi/transport/handshakeTimeout/HandshakeTimeout.java
41155 views
1
/*
2
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
* @bug 4322806
26
* @summary When an RMI (JRMP) connection is made to a TCP address that is
27
* listening, so the connection is accepted, but the server never responds
28
* to the initial JRMP handshake (nor does it terminate the connection),
29
* the client should not hang forever; instead, it should throw an exception
30
* after a reasonable timeout interval. The exception should be a
31
* java.rmi.ConnectException or ConnectIOException, not a MarshalException,
32
* because it should be clear that no partial call execution has occurred at
33
* this point (because no data for the invocation has yet been written).
34
* @author Peter Jones
35
*
36
* @modules java.rmi/sun.rmi.registry
37
* java.rmi/sun.rmi.server
38
* java.rmi/sun.rmi.transport
39
* java.rmi/sun.rmi.transport.tcp
40
* @run main/othervm HandshakeTimeout
41
*/
42
43
import java.net.ServerSocket;
44
import java.rmi.ConnectException;
45
import java.rmi.ConnectIOException;
46
import java.rmi.MarshalException;
47
import java.rmi.registry.LocateRegistry;
48
import java.rmi.registry.Registry;
49
50
public class HandshakeTimeout {
51
52
private static final int TIMEOUT = 10000;
53
54
public static void main(String[] args) throws Exception {
55
56
System.setProperty("sun.rmi.transport.tcp.handshakeTimeout",
57
String.valueOf(TIMEOUT / 2));
58
59
/*
60
* Listen on port, but never process connections made to it.
61
*/
62
ServerSocket serverSocket = new ServerSocket(0);
63
int port = serverSocket.getLocalPort();
64
65
/*
66
* Attempt RMI call to port in separate thread.
67
*/
68
Registry registry = LocateRegistry.getRegistry(port);
69
Connector connector = new Connector(registry);
70
Thread t = new Thread(connector);
71
t.setDaemon(true);
72
t.start();
73
74
/*
75
* Wait for call attempt to finished, and analyze result.
76
*/
77
t.join(TIMEOUT);
78
synchronized (connector) {
79
if (connector.success) {
80
throw new RuntimeException(
81
"TEST FAILED: remote call succeeded??");
82
}
83
if (connector.exception == null) {
84
throw new RuntimeException(
85
"TEST FAILED: remote call did not time out");
86
} else {
87
System.err.println("remote call failed with exception:");
88
connector.exception.printStackTrace();
89
System.err.println();
90
91
if (connector.exception instanceof MarshalException) {
92
throw new RuntimeException(
93
"TEST FAILED: MarshalException thrown, expecting " +
94
"java.rmi.ConnectException or ConnectIOException");
95
} else if (connector.exception instanceof ConnectException ||
96
connector.exception instanceof ConnectIOException)
97
{
98
System.err.println(
99
"TEST PASSED: java.rmi.ConnectException or " +
100
"ConnectIOException thrown");
101
} else {
102
throw new RuntimeException(
103
"TEST FAILED: unexpected Exception thrown",
104
connector.exception);
105
}
106
}
107
}
108
}
109
110
private static class Connector implements Runnable {
111
112
private final Registry registry;
113
114
boolean success = false;
115
Exception exception = null;
116
117
Connector(Registry registry) {
118
this.registry = registry;
119
}
120
121
public void run() {
122
try {
123
registry.lookup("Dale Cooper");
124
synchronized (this) {
125
success = true;
126
}
127
} catch (Exception e) {
128
synchronized (this) {
129
exception = e;
130
}
131
}
132
}
133
}
134
}
135
136