author | mli |
Wed, 11 Apr 2018 09:08:43 +0800 | |
changeset 49570 | 25515c7e96b0 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
1 |
/* |
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
25 |
* @bug 4120329 |
|
26 |
* @summary RMI registry creation is impossible if first attempt fails. |
|
27 |
* @library ../../testlibrary |
|
30820 | 28 |
* @modules java.rmi/sun.rmi.registry |
29 |
* java.rmi/sun.rmi.server |
|
30 |
* java.rmi/sun.rmi.transport |
|
31 |
* java.rmi/sun.rmi.transport.tcp |
|
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
32 |
* @build TestLibrary |
2 | 33 |
* @run main/othervm Reexport |
34 |
*/ |
|
35 |
||
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
36 |
/* |
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
37 |
* If a VM could not create an RMI registry because the registry port |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
38 |
* was already occupied by this or other processes, the next |
2 | 39 |
* time the VM tried to create a registry (after the other registry |
40 |
* was brought down) the attempt would fail. The second try to create |
|
41 |
* a registry would fail because the registry ObjID would still be in |
|
42 |
* use when it should never have been allocated. |
|
43 |
* |
|
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
44 |
* The test creates this conflict starting a dummy tcp server and ensures |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
45 |
* that a registry can still be created after the conflict is resolved. |
2 | 46 |
*/ |
47 |
||
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
48 |
import java.io.IOException; |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
49 |
import java.net.InetSocketAddress; |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
50 |
import java.nio.channels.ServerSocketChannel; |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
51 |
import java.rmi.registry.LocateRegistry; |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
52 |
import java.rmi.registry.Registry; |
2 | 53 |
|
54 |
public class Reexport { |
|
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
55 |
static public void main(String[] argv) throws IOException { |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
56 |
|
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
57 |
for (int loop = 0; loop < 10; loop++) { |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
58 |
System.err.println("\nat loop: " + loop); |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
59 |
int port = -1; |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
60 |
try (ServerSocketChannel server = ServerSocketChannel.open();) { |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
61 |
server.bind(null); |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
62 |
InetSocketAddress addr = (InetSocketAddress)server.getLocalAddress(); |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
63 |
port = addr.getPort(); |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
64 |
|
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
65 |
System.err.println("Creating duplicate registry, this should fail..."); |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
66 |
createReg(port, true); |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
67 |
} |
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
68 |
try { |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
69 |
if (createReg(port, false) == null) { |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
70 |
TestLibrary.bomb("Could not create registry on second try"); |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
71 |
} |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
72 |
System.err.println("Test passed"); |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
73 |
return; |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
74 |
} catch (Exception e) { |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
75 |
String err = e.getMessage(); |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
76 |
if (err.contains("Address already in use") |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
77 |
|| err.contains("Port already in use")) { |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
78 |
continue; |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
79 |
} |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
80 |
TestLibrary.bomb(e); |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
81 |
} |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
82 |
} |
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
83 |
TestLibrary.bomb("Test failed"); |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
84 |
} |
2 | 85 |
|
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
86 |
static Registry createReg(int port, boolean expectException) { |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
87 |
Registry reg = null; |
2 | 88 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
89 |
try { |
13256 | 90 |
reg = LocateRegistry.createRegistry(port); |
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
91 |
if (expectException) { |
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
92 |
TestLibrary.bomb("Registry is up, an Exception is expected!"); |
42760
902ae4f76a3e
8171133: java/rmi/registry/reexport/Reexport.java, there is a missing case check in createReg(..)
mli
parents:
30820
diff
changeset
|
93 |
} |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
94 |
} catch (Throwable e) { |
49570
25515c7e96b0
8188897: java/rmi/registry/reexport/Reexport.java failed with Port already in use
mli
parents:
47216
diff
changeset
|
95 |
if (expectException) { |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
96 |
System.err.println("EXPECTING PORT IN USE EXCEPTION:"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
97 |
System.err.println(e.getMessage()); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
98 |
e.printStackTrace(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
99 |
} else { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
100 |
TestLibrary.bomb((Exception) e); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
101 |
} |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
102 |
} |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
103 |
return reg; |
2 | 104 |
} |
105 |
} |