blob: 49c7fbb3c47fb0e3625b7d6e614b28b3889fa3d0 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-2001 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/* @test
25 * @bug 4097135
26 * @summary Need a specific subtype of RemoteException for activation failure.
27 * If activation fails to happen during a call to a remote object,
28 * then the call should end in an ActivateFailedException. In this
29 * test, the actual "activatable" remote object fails to activate
30 * since its * "activation" constructor throws an exception.
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
42import java.rmi.*;
43import java.rmi.server.*;
44import java.rmi.activation.*;
45import java.io.*;
46import java.util.Properties;
47
48public class ActivateFails
49 extends Activatable
50 implements ActivateMe
51{
52
53 public ActivateFails(ActivationID id, MarshalledObject obj)
54 throws ActivationException, RemoteException
55 {
56 super(id, 0);
57
58 boolean refuseToActivate = false;
59 try {
60 refuseToActivate = ((Boolean)obj.get()).booleanValue();
61 } catch (Exception impossible) {
62 }
63
64 if (refuseToActivate)
65 throw new RemoteException("object refuses to activate");
66 }
67
68 public void ping()
69 {}
70
71 /**
72 * Spawns a thread to deactivate the object.
73 */
74 public ShutdownThread shutdown() throws Exception
75 {
76 ShutdownThread shutdownThread = new ShutdownThread(this, getID());
77 shutdownThread.start();
78 return(shutdownThread);
79 }
80
81 public static void main(String[] args)
82 {
83 RMID rmid = null;
84 ActivateMe obj1, obj2;
85 ShutdownThread shutdownThread;
86
87 System.err.println("\nRegression test for bug 4097135\n");
88 try {
89 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
90
91 /*
92 * First run "rmid" and wait for it to start up.
93 */
94 RMID.removeLog();
95 rmid = RMID.createRMID();
96 rmid.start();
97
98 /* Cause activation groups to have a security policy that will
99 * allow security managers to be downloaded and installed
100 */
101 Properties p = new Properties();
102 // this test must always set policies/managers in its
103 // activation groups
104 p.put("java.security.policy",
105 TestParams.defaultGroupPolicy);
106 p.put("java.security.manager",
107 TestParams.defaultSecurityManager);
108
109 /*
110 * Create activation descriptor...
111 */
112 System.err.println("creating activation descriptor...");
113 ActivationGroupDesc groupDesc =
114 new ActivationGroupDesc(p, null);
115 ActivationGroupID groupID =
116 ActivationGroup.getSystem().registerGroup(groupDesc);
117
118 ActivationDesc desc1 =
119 new ActivationDesc(groupID, "ActivateFails",
120 null,
121 new MarshalledObject(new Boolean(true)));
122
123 ActivationDesc desc2 =
124 new ActivationDesc(groupID, "ActivateFails",
125 null,
126 new MarshalledObject(new Boolean(false)));
127 /*
128 * Register activation descriptor and make a call on
129 * the stub. Activation should fail with an
130 * ActivateFailedException. If not, report an
131 * error as a RuntimeException
132 */
133
134 System.err.println("registering activation descriptor...");
135 obj1 = (ActivateMe)Activatable.register(desc1);
136 obj2 = (ActivateMe)Activatable.register(desc2);
137
138 System.err.println("invoking method on activatable object...");
139 try {
140 obj1.ping();
141
142 } catch (ActivateFailedException e) {
143
144 /*
145 * This is what is expected so exit with status 0
146 */
147 System.err.println("\nsuccess: ActivateFailedException " +
148 "generated");
149 e.getMessage();
150 }
151
152 obj2.ping();
153 shutdownThread = obj2.shutdown();
154
155 // wait for shutdown to work
156 Thread.sleep(2000);
157
158 shutdownThread = null;
159
160 } catch (Exception e) {
161 /*
162 * Test failed; unexpected exception generated.
163 */
164 TestLibrary.bomb("\nfailure: unexpected exception " +
165 e.getClass().getName() + ": " + e.getMessage(), e);
166
167 } finally {
168 obj1 = obj2 = null;
169 ActivationLibrary.rmidCleanup(rmid);
170 }
171 }
172}
173