author | mchung |
Mon, 27 Oct 2014 13:45:39 -0700 | |
changeset 27260 | 8d82d0e9556b |
parent 23010 | 6dadb192ad81 |
child 27784 | a51d6d4e0528 |
permissions | -rw-r--r-- |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
14778
diff
changeset
|
2 |
* Copyright (c) 1998, 2012, 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 |
|
14778 | 34 |
* @build TestLibrary RMID ActivationLibrary |
35 |
* ActivateMe ActivateFails_Stub ShutdownThread |
|
27260
8d82d0e9556b
8043277: Update jdk regression tests to extend the default security policy instead of override
mchung
parents:
23010
diff
changeset
|
36 |
* @run main/othervm/java.security.policy=security.policy/timeout=240 ActivateFails |
2 | 37 |
*/ |
38 |
||
39 |
import java.rmi.*; |
|
40 |
import java.rmi.server.*; |
|
41 |
import java.rmi.activation.*; |
|
42 |
import java.io.*; |
|
43 |
import java.util.Properties; |
|
44 |
||
45 |
public class ActivateFails |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
46 |
extends Activatable |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
47 |
implements ActivateMe |
2 | 48 |
{ |
49 |
||
50 |
public ActivateFails(ActivationID id, MarshalledObject obj) |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
51 |
throws ActivationException, RemoteException |
2 | 52 |
{ |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
53 |
super(id, 0); |
2 | 54 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
55 |
boolean refuseToActivate = false; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
56 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
57 |
refuseToActivate = ((Boolean)obj.get()).booleanValue(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
58 |
} catch (Exception impossible) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
59 |
} |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
60 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
61 |
if (refuseToActivate) |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
62 |
throw new RemoteException("object refuses to activate"); |
2 | 63 |
} |
64 |
||
65 |
public void ping() |
|
66 |
{} |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
67 |
|
2 | 68 |
/** |
69 |
* Spawns a thread to deactivate the object. |
|
70 |
*/ |
|
71 |
public ShutdownThread shutdown() throws Exception |
|
72 |
{ |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
73 |
ShutdownThread shutdownThread = new ShutdownThread(this, getID()); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
74 |
shutdownThread.start(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
75 |
return(shutdownThread); |
2 | 76 |
} |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
77 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
78 |
public static void main(String[] args) |
2 | 79 |
{ |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
80 |
RMID rmid = null; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
81 |
ActivateMe obj1, obj2; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
82 |
ShutdownThread shutdownThread; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
83 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
84 |
System.err.println("\nRegression test for bug 4097135\n"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
85 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
86 |
TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
87 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
88 |
/* |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
89 |
* 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
|
90 |
*/ |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
91 |
RMID.removeLog(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
92 |
rmid = RMID.createRMID(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
93 |
rmid.start(); |
2 | 94 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
95 |
/* 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
|
96 |
* allow security managers to be downloaded and installed |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
97 |
*/ |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
98 |
Properties p = new Properties(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
99 |
// this test must always set policies/managers in its |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
100 |
// activation groups |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
101 |
p.put("java.security.policy", |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
102 |
TestParams.defaultGroupPolicy); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
103 |
p.put("java.security.manager", |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
104 |
TestParams.defaultSecurityManager); |
2 | 105 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
106 |
/* |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
107 |
* Create activation descriptor... |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
108 |
*/ |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
109 |
System.err.println("creating activation descriptor..."); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
110 |
ActivationGroupDesc groupDesc = |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
111 |
new ActivationGroupDesc(p, null); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
112 |
ActivationGroupID groupID = |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
113 |
ActivationGroup.getSystem().registerGroup(groupDesc); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
114 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
115 |
ActivationDesc desc1 = |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
116 |
new ActivationDesc(groupID, "ActivateFails", |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
117 |
null, |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
118 |
new MarshalledObject(new Boolean(true))); |
2 | 119 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
120 |
ActivationDesc desc2 = |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
121 |
new ActivationDesc(groupID, "ActivateFails", |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
122 |
null, |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
123 |
new MarshalledObject(new Boolean(false))); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
124 |
/* |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
125 |
* Register activation descriptor and make a call on |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
126 |
* the stub. Activation should fail with an |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
127 |
* ActivateFailedException. If not, report an |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
128 |
* error as a RuntimeException |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
129 |
*/ |
2 | 130 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
131 |
System.err.println("registering activation descriptor..."); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
132 |
obj1 = (ActivateMe)Activatable.register(desc1); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
133 |
obj2 = (ActivateMe)Activatable.register(desc2); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
134 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
135 |
System.err.println("invoking method on activatable object..."); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
136 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
137 |
obj1.ping(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
138 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
139 |
} catch (ActivateFailedException e) { |
2 | 140 |
|
309
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 |
* 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
|
143 |
*/ |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
144 |
System.err.println("\nsuccess: ActivateFailedException " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
145 |
"generated"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
146 |
e.getMessage(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
147 |
} |
2 | 148 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
149 |
obj2.ping(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
150 |
shutdownThread = obj2.shutdown(); |
2 | 151 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
152 |
// wait for shutdown to work |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
153 |
Thread.sleep(2000); |
2 | 154 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
155 |
shutdownThread = null; |
2 | 156 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
157 |
} catch (Exception e) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
158 |
/* |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
159 |
* Test failed; unexpected exception generated. |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
160 |
*/ |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
161 |
TestLibrary.bomb("\nfailure: unexpected exception " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
162 |
e.getClass().getName() + ": " + e.getMessage(), e); |
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 |
} finally { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
165 |
obj1 = obj2 = null; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
166 |
ActivationLibrary.rmidCleanup(rmid); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
167 |
} |
2 | 168 |
} |
169 |
} |