author | ohair |
Tue, 25 May 2010 15:58:33 -0700 | |
changeset 5506 | 202f599c92aa |
parent 715 | f16baef3a20e |
child 14778 | 5947768d173d |
permissions | -rw-r--r-- |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 1998, 2008, 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 4097135 |
|
26 |
* @summary Need a specific subtype of RemoteException for activation failure. |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
27 |
* If activation fails to happen during a call to a remote object, |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
28 |
* then the call should end in an ActivateFailedException. In this |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
29 |
* test, the actual "activatable" remote object fails to activate |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
30 |
* since its * "activation" constructor throws an exception. |
2 | 31 |
* @author Ann Wollrath |
32 |
* |
|
33 |
* @library ../../../testlibrary |
|
34 |
* @build TestLibrary RMID JavaVM StreamPipe |
|
35 |
* @build ActivateMe |
|
36 |
* @build ActivateFails |
|
37 |
* @build ActivateFails_Stub |
|
38 |
* @build ShutdownThread |
|
39 |
* @run main/othervm/policy=security.policy/timeout=240 ActivateFails |
|
40 |
*/ |
|
41 |
||
42 |
import java.rmi.*; |
|
43 |
import java.rmi.server.*; |
|
44 |
import java.rmi.activation.*; |
|
45 |
import java.io.*; |
|
46 |
import java.util.Properties; |
|
47 |
||
48 |
public class ActivateFails |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
49 |
extends Activatable |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
50 |
implements ActivateMe |
2 | 51 |
{ |
52 |
||
53 |
public ActivateFails(ActivationID id, MarshalledObject obj) |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
54 |
throws ActivationException, RemoteException |
2 | 55 |
{ |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
56 |
super(id, 0); |
2 | 57 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
58 |
boolean refuseToActivate = false; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
59 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
60 |
refuseToActivate = ((Boolean)obj.get()).booleanValue(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
61 |
} catch (Exception impossible) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
62 |
} |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
63 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
64 |
if (refuseToActivate) |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
65 |
throw new RemoteException("object refuses to activate"); |
2 | 66 |
} |
67 |
||
68 |
public void ping() |
|
69 |
{} |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
70 |
|
2 | 71 |
/** |
72 |
* Spawns a thread to deactivate the object. |
|
73 |
*/ |
|
74 |
public ShutdownThread shutdown() throws Exception |
|
75 |
{ |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
76 |
ShutdownThread shutdownThread = new ShutdownThread(this, getID()); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
77 |
shutdownThread.start(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
78 |
return(shutdownThread); |
2 | 79 |
} |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
80 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
81 |
public static void main(String[] args) |
2 | 82 |
{ |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
83 |
RMID rmid = null; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
84 |
ActivateMe obj1, obj2; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
85 |
ShutdownThread shutdownThread; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
86 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
87 |
System.err.println("\nRegression test for bug 4097135\n"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
88 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
89 |
TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
90 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
91 |
/* |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
92 |
* First run "rmid" and wait for it to start up. |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
93 |
*/ |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
94 |
RMID.removeLog(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
95 |
rmid = RMID.createRMID(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
96 |
rmid.start(); |
2 | 97 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
98 |
/* Cause activation groups to have a security policy that will |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
99 |
* allow security managers to be downloaded and installed |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
100 |
*/ |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
101 |
Properties p = new Properties(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
102 |
// this test must always set policies/managers in its |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
103 |
// activation groups |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
104 |
p.put("java.security.policy", |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
105 |
TestParams.defaultGroupPolicy); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
106 |
p.put("java.security.manager", |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
107 |
TestParams.defaultSecurityManager); |
2 | 108 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
109 |
/* |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
110 |
* Create activation descriptor... |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
111 |
*/ |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
112 |
System.err.println("creating activation descriptor..."); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
113 |
ActivationGroupDesc groupDesc = |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
114 |
new ActivationGroupDesc(p, null); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
115 |
ActivationGroupID groupID = |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
116 |
ActivationGroup.getSystem().registerGroup(groupDesc); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
117 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
118 |
ActivationDesc desc1 = |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
119 |
new ActivationDesc(groupID, "ActivateFails", |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
120 |
null, |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
121 |
new MarshalledObject(new Boolean(true))); |
2 | 122 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
123 |
ActivationDesc desc2 = |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
124 |
new ActivationDesc(groupID, "ActivateFails", |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
125 |
null, |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
126 |
new MarshalledObject(new Boolean(false))); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
127 |
/* |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
128 |
* Register activation descriptor and make a call on |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
129 |
* the stub. Activation should fail with an |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
130 |
* ActivateFailedException. If not, report an |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
131 |
* error as a RuntimeException |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
132 |
*/ |
2 | 133 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
134 |
System.err.println("registering activation descriptor..."); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
135 |
obj1 = (ActivateMe)Activatable.register(desc1); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
136 |
obj2 = (ActivateMe)Activatable.register(desc2); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
137 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
138 |
System.err.println("invoking method on activatable object..."); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
139 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
140 |
obj1.ping(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
141 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
142 |
} catch (ActivateFailedException e) { |
2 | 143 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
144 |
/* |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
145 |
* This is what is expected so exit with status 0 |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
146 |
*/ |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
147 |
System.err.println("\nsuccess: ActivateFailedException " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
148 |
"generated"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
149 |
e.getMessage(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
150 |
} |
2 | 151 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
152 |
obj2.ping(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
153 |
shutdownThread = obj2.shutdown(); |
2 | 154 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
155 |
// wait for shutdown to work |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
156 |
Thread.sleep(2000); |
2 | 157 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
158 |
shutdownThread = null; |
2 | 159 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
160 |
} catch (Exception e) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
161 |
/* |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
162 |
* Test failed; unexpected exception generated. |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
163 |
*/ |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
164 |
TestLibrary.bomb("\nfailure: unexpected exception " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
165 |
e.getClass().getName() + ": " + e.getMessage(), e); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
166 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
167 |
} finally { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
168 |
obj1 = obj2 = null; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
169 |
ActivationLibrary.rmidCleanup(rmid); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
170 |
} |
2 | 171 |
} |
172 |
} |