blob: c5f13fea4111d8c7e632ca555bdb8a29a5eef857 [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 4115296
26 *
27 * @summary synopsis: NoSuchObjectException not thrown for non-existent
28 * activatable objects
29 * @author Ann Wollrath
30 *
31 * @library ../../../testlibrary
32 * @build TestLibrary RMID ActivationLibrary
33 * @build ActivateMe
34 * @build NonExistentActivatable
35 * @build NonExistentActivatable_Stub
36 * @run main/othervm/policy=security.policy/timeout=240 NonExistentActivatable
37 */
38
39import java.io.*;
40import java.rmi.*;
41import java.rmi.activation.*;
42import java.rmi.server.*;
43import java.rmi.registry.*;
44import java.util.Properties;
45
46public class NonExistentActivatable
47 extends Activatable
48 implements ActivateMe, Runnable
49{
50
51 public NonExistentActivatable(ActivationID id, MarshalledObject obj)
52 throws ActivationException, RemoteException
53 {
54 super(id, 0);
55 }
56
57 public void ping()
58 {}
59
60 public void unregister() throws Exception {
61 super.unregister(super.getID());
62 }
63
64 /**
65 * Spawns a thread to deactivate the object.
66 */
67 public void shutdown() throws Exception
68 {
69 (new Thread(this,"NonExistentActivatable")).start();
70 }
71
72 /**
73 * Thread to deactivate object. First attempts to make object
74 * inactive (via the inactive method). If that fails (the
75 * object may still have pending/executing calls), then
76 * unexport the object forcibly.
77 */
78 public void run()
79 {
80 ActivationLibrary.deactivate(this, getID());
81 }
82
83 public static void main(String[] args) {
84
85 System.out.println("\nRegression test for bug 4115331\n");
86
87 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
88
89 RMID rmid = null;
90
91 try {
92 RMID.removeLog();
93 rmid = RMID.createRMID();
94 rmid.start();
95
96 /* Cause activation groups to have a security policy that will
97 * allow security managers to be downloaded and installed
98 */
99 Properties p = new Properties();
100 // this test must always set policies/managers in its
101 // activation groups
102 p.put("java.security.policy",
103 TestParams.defaultGroupPolicy);
104 p.put("java.security.manager",
105 TestParams.defaultSecurityManager);
106
107 System.err.println("Create activation group in this VM");
108 ActivationGroupDesc groupDesc =
109 new ActivationGroupDesc(p, null);
110 ActivationSystem system = ActivationGroup.getSystem();
111 ActivationGroupID groupID = system.registerGroup(groupDesc);
112 ActivationGroup.createGroup(groupID, groupDesc, 0);
113
114 System.err.println("Creating descriptor");
115 ActivationDesc desc =
116 new ActivationDesc("NonExistentActivatable", null, null);
117
118 System.err.println("Registering descriptor");
119 ActivateMe obj = (ActivateMe) Activatable.register(desc);
120
121 System.err.println("Activate object via method call");
122 obj.ping();
123
124 System.err.println("Unregister object");
125 obj.unregister();
126
127 System.err.println("Make object inactive");
128 obj.shutdown();
129
130 System.err.println("Reactivate object");
131 try {
132 obj.ping();
133 } catch (NoSuchObjectException e) {
134 System.err.println("Test succeeded: " +
135 "NoSuchObjectException caught");
136 return;
137 } catch (Exception e) {
138 TestLibrary.bomb("Test failed: exception other than NoSuchObjectException",
139 e);
140 }
141
142 } catch (Exception e) {
143 TestLibrary.bomb("test failed", e);
144 } finally {
145 ActivationLibrary.rmidCleanup(rmid);
146 }
147 }
148}