Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/registry/reexport/Reexport.java
38828 views
1
/*
2
* Copyright (c) 1999, 2013, 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 4120329
26
* @summary RMI registry creation is impossible if first attempt fails.
27
* @library ../../testlibrary
28
* @build TestLibrary JavaVM RegistryRunner RegistryRunner_Stub
29
* @run main/othervm Reexport
30
*/
31
32
/*
33
* If a VM could not create an RMI registry because another registry
34
* usually in another process, was using the registry port, the next
35
* time the VM tried to create a registry (after the other registry
36
* was brought down) the attempt would fail. The second try to create
37
* a registry would fail because the registry ObjID would still be in
38
* use when it should never have been allocated.
39
*
40
* The test creates this conflict using Runtime.exec and ensures that
41
* a registry can still be created after the conflict is resolved.
42
*/
43
44
import java.io.*;
45
import java.rmi.*;
46
import java.rmi.registry.*;
47
import java.rmi.server.*;
48
49
public class Reexport {
50
static public void main(String[] argv) {
51
52
Registry reg = null;
53
int regPort = TestLibrary.getUnusedRandomPort();
54
55
try {
56
System.err.println("\nregression test for 4120329\n");
57
58
// establish the registry (we hope)
59
System.err.println("Starting registry on port " + regPort);
60
Reexport.makeRegistry(regPort);
61
62
// Get a handle to the registry
63
System.err.println("Creating duplicate registry, this should fail...");
64
reg = createReg(true, regPort);
65
66
if (reg != null) {
67
TestLibrary.bomb("failed was able to duplicate the registry?!?");
68
}
69
70
// Kill the first registry.
71
System.err.println("Bringing down the first registry");
72
try {
73
Reexport.killRegistry(regPort);
74
} catch (Exception foo) {
75
}
76
77
// start another registry now that the first is gone; this should work
78
System.err.println("Trying again to start our own " +
79
"registry... this should work");
80
81
reg = createReg(false, regPort);
82
83
if (reg == null) {
84
TestLibrary.bomb("Could not create registry on second try");
85
}
86
87
System.err.println("Test passed");
88
89
} catch (Exception e) {
90
TestLibrary.bomb(e);
91
} finally {
92
// dont leave the registry around to affect other tests.
93
killRegistry(regPort);
94
95
reg = null;
96
}
97
}
98
99
static Registry createReg(boolean remoteOk, int port) {
100
Registry reg = null;
101
102
try {
103
reg = LocateRegistry.createRegistry(port);
104
} catch (Throwable e) {
105
if (remoteOk) {
106
System.err.println("EXPECTING PORT IN USE EXCEPTION:");
107
System.err.println(e.getMessage());
108
e.printStackTrace();
109
} else {
110
TestLibrary.bomb((Exception) e);
111
}
112
}
113
114
return reg;
115
}
116
117
public static void makeRegistry(int p) {
118
// sadly, we can't kill a registry if we have too-close control
119
// over it. We must make it in a subprocess, and then kill the
120
// subprocess when it has served our needs.
121
122
try {
123
JavaVM jvm = new JavaVM("RegistryRunner", "", Integer.toString(p));
124
jvm.start();
125
Reexport.subreg = jvm;
126
} catch (IOException e) {
127
// one of these is summarily dropped, can't remember which one
128
System.out.println ("Test setup failed - cannot run rmiregistry");
129
TestLibrary.bomb("Test setup failed - cannot run test", e);
130
}
131
// Slop - wait for registry to come up. This is stupid.
132
try {
133
Thread.sleep (5000);
134
} catch (Exception whatever) {
135
}
136
}
137
138
private static JavaVM subreg = null;
139
140
public static void killRegistry(int port) {
141
if (Reexport.subreg != null) {
142
143
RegistryRunner.requestExit(port);
144
145
try {
146
Reexport.subreg.waitFor();
147
} catch (InterruptedException ie) {
148
}
149
}
150
Reexport.subreg = null;
151
}
152
}
153
154