1 /* 2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. 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 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. 22 */ 23 24 /* @test 25 * @bug 4110548 26 * @summary activate fails if rmid is restarted 27 * @author Ann Wollrath 28 * 29 * @library ../../../testlibrary 30 * @build TestLibrary RMID ActivationLibrary 31 * ActivateMe CheckRegisterInLog_Stub 32 * @run main/othervm/policy=security.policy/timeout=240 CheckRegisterInLog 33 */ 34 35 import java.io.*; 36 import java.rmi.*; 37 import java.rmi.server.*; 38 import java.rmi.activation.*; 39 import sun.rmi.server.ActivatableRef; 40 import java.lang.reflect.*; 41 import java.util.Properties; 42 43 public class CheckRegisterInLog 44 extends Activatable 45 implements ActivateMe, Runnable 46 { 47 48 public CheckRegisterInLog(ActivationID id, MarshalledObject obj) 49 throws ActivationException, RemoteException 50 { 51 super(id, 0); 52 } 53 54 public void ping() 55 {} 56 57 /** 58 * Spawns a thread to deactivate the object. 59 */ 60 public void shutdown() throws Exception 61 { 62 (new Thread(this,"CheckRegisterInLog")).start(); 63 } 64 65 /** 66 * Thread to deactivate object. First attempts to make object 67 * inactive (via the inactive method). If that fails (the 68 * object may still have pending/executing calls), then 69 * unexport the object forcibly. 70 */ 71 public void run() { 72 ActivationLibrary.deactivate(this, getID()); 73 } 74 75 public static void main(String[] args) { 76 /* 77 * The following line is required with the JDK 1.2 VM so that the 78 * VM can exit gracefully when this test completes. Otherwise, the 79 * conservative garbage collector will find a handle to the server 80 * object on the native stack and not clear the weak reference to 81 * it in the RMI runtime's object table. 82 */ 83 Object dummy = new Object(); 84 RMID rmid = null; 85 ActivateMe obj; 86 87 System.out.println("\nRegression test for bug 4110548\n"); 88 89 CheckRegisterInLog server; 90 91 try { 92 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); 93 94 /* 95 * Start up activation system daemon "rmid". 96 */ 97 RMID.removeLog(); 98 rmid = RMID.createRMID(); 99 rmid.start(); 100 101 /* Cause activation groups to have a security policy that will 102 * allow security managers to be downloaded and installed 103 */ 104 Properties p = new Properties(); 105 // this test must always set policies/managers in its 106 // activation groups 107 p.put("java.security.policy", 108 TestParams.defaultGroupPolicy); 109 p.put("java.security.manager", 110 TestParams.defaultSecurityManager); 111 112 /* 113 * Register an activation group and an object 114 * in that group. 115 */ 116 System.err.println("Creating group descriptor"); 117 ActivationGroupDesc groupDesc = 118 new ActivationGroupDesc(p, null); 119 System.err.println("Registering group"); 120 ActivationSystem system = ActivationGroup.getSystem(); 121 ActivationGroupID groupID = system.registerGroup(groupDesc); 122 123 System.err.println("Creating descriptor"); 124 ActivationDesc desc = 125 new ActivationDesc(groupID, "CheckRegisterInLog", 126 null, null); 127 System.err.println("Registering descriptor"); 128 obj = (ActivateMe)Activatable.register(desc); 129 130 /* 131 * Restart rmid to force it to read the log file 132 */ 133 rmid.restart(); 134 135 136 /* 137 * 4212096: Give rmid time to go away - we want to make 138 * sure that an attempt to activate the test object is not made 139 * on the ActivationSystem that is about to be shutdown. 140 */ 141 try { 142 Thread.sleep(5000); 143 } catch (InterruptedException ie) { 144 } 145 146 /* 147 * Activate the object via a method call. 148 */ 149 System.err.println("Activate the object via method call"); 150 obj.ping(); 151 152 /* 153 * Clean up object too. 154 */ 155 System.err.println("Deactivate object via method call"); 156 obj.shutdown(); 157 158 System.err.println("\nsuccess: CheckRegisterInLog test passed "); 159 160 } catch (Exception e) { 161 System.err.println("\nfailure: unexpected exception " + 162 e.getClass().getName() + ": " + e.getMessage()); 163 e.printStackTrace(System.err); 164 throw new RuntimeException("CheckRegisterInLog got exception " + 165 e.getMessage()); 166 } finally { 167 rmid.cleanup(); 168 } 169 } 170 }