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/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java
38889 views
1
/*
2
* Copyright (c) 1998, 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 4134233
26
* @bug 4213186
27
* @summary synopsis: ActivationSystem.unregisterGroup should unregister objects in group
28
* @author Ann Wollrath
29
*
30
* @library ../../../testlibrary
31
* @build TestLibrary RMID ActivationLibrary ActivateMe
32
* @run main/othervm/policy=security.policy UnregisterGroup
33
*/
34
35
import java.io.*;
36
import java.rmi.*;
37
import java.rmi.activation.*;
38
import java.rmi.server.*;
39
import java.util.Properties;
40
41
public class UnregisterGroup extends Activatable implements ActivateMe
42
{
43
private static volatile Exception exception = null;
44
private static volatile String error = null;
45
private static volatile boolean done = false;
46
private static final int NUM_OBJECTS = 10;
47
48
public UnregisterGroup(ActivationID id, MarshalledObject mobj)
49
throws Exception
50
{
51
super(id, 0);
52
}
53
54
/**
55
* Does nothing, but serves to activate this object.
56
*/
57
public void ping() { }
58
59
/**
60
* Deactivates the object. We need to unexport forcibly because
61
* this call is in-progress on this object, which is the same object
62
* that we are trying to deactivate.
63
*/
64
public void shutdown() throws Exception {
65
Activatable.unexportObject(this, true);
66
ActivationLibrary.deactivate(this, getID());
67
}
68
69
public static void main(String[] args) throws RemoteException {
70
TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
71
RMID rmid = null;
72
73
try {
74
RMID.removeLog();
75
rmid = RMID.createRMID();
76
rmid.start();
77
78
/* Cause activation groups to have a security policy that will
79
* allow security managers to be downloaded and installed
80
*/
81
final Properties p = new Properties();
82
// this test must always set policies/managers in its
83
// activation groups
84
p.put("java.security.policy", TestParams.defaultGroupPolicy);
85
p.put("java.security.manager", TestParams.defaultSecurityManager);
86
87
Thread t = new Thread() {
88
public void run () {
89
try {
90
System.err.println("Creating group descriptor");
91
ActivationGroupDesc groupDesc =
92
new ActivationGroupDesc(p, null);
93
ActivationSystem system = ActivationGroup.getSystem();
94
ActivationGroupID groupID =
95
system.registerGroup(groupDesc);
96
97
ActivateMe[] obj = new ActivateMe[NUM_OBJECTS];
98
99
for (int i = 0; i < NUM_OBJECTS; i++) {
100
System.err.println("Creating descriptor: " + i);
101
ActivationDesc desc =
102
new ActivationDesc(groupID, "UnregisterGroup",
103
null, null);
104
System.err.println("Registering descriptor: " + i);
105
obj[i] = (ActivateMe) Activatable.register(desc);
106
System.err.println("Activating object: " + i);
107
obj[i].ping();
108
}
109
110
System.err.println("Unregistering group");
111
system.unregisterGroup(groupID);
112
113
try {
114
System.err.println("Get the group descriptor");
115
system.getActivationGroupDesc(groupID);
116
error = "test failed: group still registered";
117
} catch (UnknownGroupException e) {
118
System.err.println("Test passed: " +
119
"group unregistered");
120
}
121
122
/*
123
* Deactivate objects so group VM will exit.
124
*/
125
for (int i = 0; i < NUM_OBJECTS; i++) {
126
System.err.println("Deactivating object: " + i);
127
obj[i].shutdown();
128
obj[i] = null;
129
}
130
System.err.println("Successfully deactivated all objects.");
131
132
} catch (Exception e) {
133
exception = e;
134
}
135
136
done = true;
137
}
138
};
139
140
t.start();
141
142
// Default jtreg timeout is two minutes.
143
// Timeout ourselves after one minute so that
144
// we can clean up.
145
t.join(60000);
146
147
if (exception != null) {
148
TestLibrary.bomb("test failed", exception);
149
} else if (error != null) {
150
TestLibrary.bomb(error, null);
151
} else if (!done) {
152
TestLibrary.bomb("test failed: not completed before timeout", null);
153
} else {
154
System.err.println("Test passed");
155
}
156
} catch (Exception e) {
157
TestLibrary.bomb("test failed", e);
158
} finally {
159
ActivationLibrary.rmidCleanup(rmid);
160
}
161
}
162
}
163
164