Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/Activatable/checkRegisterInLog/CheckRegisterInLog.java
38829 views
/*1* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 411054825* @summary activate fails if rmid is restarted26* @author Ann Wollrath27*28* @library ../../../testlibrary29* @build TestLibrary RMID ActivationLibrary30* ActivateMe CheckRegisterInLog_Stub31* @run main/othervm/policy=security.policy/timeout=240 CheckRegisterInLog32*/3334import java.io.*;35import java.rmi.*;36import java.rmi.server.*;37import java.rmi.activation.*;38import sun.rmi.server.ActivatableRef;39import java.lang.reflect.*;40import java.util.Properties;4142public class CheckRegisterInLog43extends Activatable44implements ActivateMe, Runnable45{4647public CheckRegisterInLog(ActivationID id, MarshalledObject obj)48throws ActivationException, RemoteException49{50super(id, 0);51}5253public void ping()54{}5556/**57* Spawns a thread to deactivate the object.58*/59public void shutdown() throws Exception60{61(new Thread(this,"CheckRegisterInLog")).start();62}6364/**65* Thread to deactivate object. First attempts to make object66* inactive (via the inactive method). If that fails (the67* object may still have pending/executing calls), then68* unexport the object forcibly.69*/70public void run() {71ActivationLibrary.deactivate(this, getID());72}7374public static void main(String[] args) {75/*76* The following line is required with the JDK 1.2 VM so that the77* VM can exit gracefully when this test completes. Otherwise, the78* conservative garbage collector will find a handle to the server79* object on the native stack and not clear the weak reference to80* it in the RMI runtime's object table.81*/82Object dummy = new Object();83RMID rmid = null;84ActivateMe obj;8586System.out.println("\nRegression test for bug 4110548\n");8788CheckRegisterInLog server;8990try {91TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");9293/*94* Start up activation system daemon "rmid".95*/96RMID.removeLog();97rmid = RMID.createRMID();98rmid.start();99100/* Cause activation groups to have a security policy that will101* allow security managers to be downloaded and installed102*/103Properties p = new Properties();104// this test must always set policies/managers in its105// activation groups106p.put("java.security.policy",107TestParams.defaultGroupPolicy);108p.put("java.security.manager",109TestParams.defaultSecurityManager);110111/*112* Register an activation group and an object113* in that group.114*/115System.err.println("Creating group descriptor");116ActivationGroupDesc groupDesc =117new ActivationGroupDesc(p, null);118System.err.println("Registering group");119ActivationSystem system = ActivationGroup.getSystem();120ActivationGroupID groupID = system.registerGroup(groupDesc);121122System.err.println("Creating descriptor");123ActivationDesc desc =124new ActivationDesc(groupID, "CheckRegisterInLog",125null, null);126System.err.println("Registering descriptor");127obj = (ActivateMe)Activatable.register(desc);128129/*130* Restart rmid to force it to read the log file131*/132rmid.restart();133134135/*136* 4212096: Give rmid time to go away - we want to make137* sure that an attempt to activate the test object is not made138* on the ActivationSystem that is about to be shutdown.139*/140try {141Thread.sleep(5000);142} catch (InterruptedException ie) {143}144145/*146* Activate the object via a method call.147*/148System.err.println("Activate the object via method call");149obj.ping();150151/*152* Clean up object too.153*/154System.err.println("Deactivate object via method call");155obj.shutdown();156157System.err.println("\nsuccess: CheckRegisterInLog test passed ");158159} catch (Exception e) {160System.err.println("\nfailure: unexpected exception " +161e.getClass().getName() + ": " + e.getMessage());162e.printStackTrace(System.err);163throw new RuntimeException("CheckRegisterInLog got exception " +164e.getMessage());165} finally {166ActivationLibrary.rmidCleanup(rmid);167}168}169}170171172