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