2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1998, 2001, 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 4116082
|
|
26 |
*
|
|
27 |
* @summary synopsis: rmid should not destroy group when it reports
|
|
28 |
* inactiveGroup
|
|
29 |
* @author Ann Wollrath
|
|
30 |
*
|
|
31 |
* @library ../../../testlibrary
|
14778
|
32 |
* @build TestLibrary RMID ActivationLibrary ActivateMe InactiveGroup_Stub
|
2
|
33 |
* @run main/othervm/policy=security.policy/timeout=240 InactiveGroup
|
|
34 |
*/
|
|
35 |
|
|
36 |
import java.io.*;
|
|
37 |
import java.rmi.*;
|
|
38 |
import java.rmi.activation.*;
|
|
39 |
import java.rmi.server.*;
|
|
40 |
import java.rmi.registry.*;
|
|
41 |
import java.util.Properties;
|
|
42 |
|
|
43 |
public class InactiveGroup
|
|
44 |
implements ActivateMe, Runnable
|
|
45 |
{
|
|
46 |
|
|
47 |
private ActivationID id;
|
|
48 |
|
|
49 |
public InactiveGroup(ActivationID id, MarshalledObject obj)
|
|
50 |
throws ActivationException, RemoteException
|
|
51 |
{
|
|
52 |
this.id = id;
|
|
53 |
Activatable.exportObject(this, id, 0);
|
|
54 |
}
|
|
55 |
|
|
56 |
public InactiveGroup() throws RemoteException {
|
|
57 |
UnicastRemoteObject.exportObject(this, 0);
|
|
58 |
}
|
|
59 |
|
|
60 |
public void ping()
|
|
61 |
{}
|
|
62 |
|
|
63 |
public ActivateMe getUnicastVersion() throws RemoteException {
|
|
64 |
return new InactiveGroup();
|
|
65 |
}
|
|
66 |
|
|
67 |
public ActivationID getID() {
|
|
68 |
return id;
|
|
69 |
}
|
|
70 |
|
|
71 |
/**
|
|
72 |
* Spawns a thread to deactivate the object.
|
|
73 |
*/
|
|
74 |
public void shutdown() throws Exception
|
|
75 |
{
|
|
76 |
(new Thread(this,"InactiveGroup")).start();
|
|
77 |
}
|
|
78 |
|
|
79 |
/**
|
|
80 |
* Thread to deactivate object. First attempts to make object
|
|
81 |
* inactive (via the inactive method). If that fails (the
|
|
82 |
* object may still have pending/executing calls), then
|
|
83 |
* unexport the object forcibly.
|
|
84 |
*/
|
|
85 |
public void run()
|
|
86 |
{
|
|
87 |
ActivationLibrary.deactivate(this, getID());
|
|
88 |
}
|
|
89 |
|
|
90 |
public static void main(String[] args) {
|
|
91 |
|
|
92 |
System.out.println("\nRegression test for bug 4116082\n");
|
|
93 |
|
|
94 |
TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
|
|
95 |
|
|
96 |
RMID rmid = null;
|
|
97 |
|
|
98 |
try {
|
|
99 |
RMID.removeLog();
|
|
100 |
rmid = RMID.createRMID();
|
|
101 |
rmid.start();
|
|
102 |
|
|
103 |
/* Cause activation groups to have a security policy that will
|
|
104 |
* allow security managers to be downloaded and installed
|
|
105 |
*/
|
|
106 |
Properties p = new Properties();
|
|
107 |
// this test must always set policies/managers in its
|
|
108 |
// activation groups
|
|
109 |
p.put("java.security.policy",
|
|
110 |
TestParams.defaultGroupPolicy);
|
|
111 |
p.put("java.security.manager",
|
|
112 |
TestParams.defaultSecurityManager);
|
|
113 |
|
|
114 |
/*
|
|
115 |
* Create descriptor and activate object in a separate VM.
|
|
116 |
*/
|
|
117 |
System.err.println("Creating descriptor");
|
|
118 |
ActivationGroupDesc groupDesc =
|
|
119 |
new ActivationGroupDesc(p, null);
|
|
120 |
ActivationGroupID groupID =
|
|
121 |
ActivationGroup.getSystem().registerGroup(groupDesc);
|
|
122 |
ActivationDesc desc =
|
|
123 |
new ActivationDesc(groupID, "InactiveGroup", null, null);
|
|
124 |
|
|
125 |
System.err.println("Registering descriptor");
|
|
126 |
ActivateMe activatableObj = (ActivateMe) Activatable.register(desc);
|
|
127 |
|
|
128 |
System.err.println("Activate object via method call");
|
|
129 |
activatableObj.ping();
|
|
130 |
|
|
131 |
/*
|
|
132 |
* Create a unicast object in the activatable object's VM.
|
|
133 |
*/
|
|
134 |
System.err.println("Obtain unicast object");
|
|
135 |
ActivateMe unicastObj = activatableObj.getUnicastVersion();
|
|
136 |
|
|
137 |
/*
|
|
138 |
* Make activatable object (and therefore group) inactive.
|
|
139 |
*/
|
|
140 |
System.err.println("Make activatable object inactive");
|
|
141 |
activatableObj.shutdown();
|
|
142 |
|
|
143 |
/*
|
|
144 |
* Ping the unicast object a few times to make sure that the
|
|
145 |
* activation group's process hasn't gone away.
|
|
146 |
*/
|
|
147 |
System.err.println("Ping unicast object for existence");
|
22085
|
148 |
// set timeout 5 seconds
|
|
149 |
final long stopTime = System.currentTimeMillis() + 5000;
|
|
150 |
while (System.currentTimeMillis() < stopTime) {
|
2
|
151 |
unicastObj.ping();
|
|
152 |
Thread.sleep(500);
|
|
153 |
}
|
|
154 |
|
|
155 |
/*
|
|
156 |
* Now, reactivate the activatable object; the unicast object
|
|
157 |
* should no longer be accessible, since reactivating the
|
|
158 |
* activatable object should kill the previous group's VM
|
|
159 |
* and the unicast object along with it.
|
|
160 |
*/
|
|
161 |
System.err.println("Reactivate activatable obj");
|
|
162 |
activatableObj.ping();
|
|
163 |
|
|
164 |
try {
|
|
165 |
System.err.println("Ping unicast object again");
|
|
166 |
unicastObj.ping();
|
|
167 |
} catch (Exception thisShouldFail) {
|
|
168 |
System.err.println("Test passed: couldn't reach unicast obj: " +
|
|
169 |
thisShouldFail.getMessage());
|
|
170 |
return;
|
|
171 |
}
|
|
172 |
|
|
173 |
TestLibrary.bomb("Test failed: unicast obj accessible after group reactivates",
|
|
174 |
null);
|
|
175 |
|
|
176 |
} catch (Exception e) {
|
|
177 |
TestLibrary.bomb("test failed", e);
|
|
178 |
} finally {
|
|
179 |
ActivationLibrary.rmidCleanup(rmid);
|
|
180 |
}
|
|
181 |
}
|
|
182 |
}
|