Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/Activatable/unregisterInactive/UnregisterInactive.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 411533125* @summary synopsis: activatable object fails to go inactive after26* unregister/inactive sequence.27* @author Ann Wollrath28*29* @library ../../../testlibrary30* @build TestLibrary RMID ActivationLibrary ActivateMe UnregisterInactive_Stub31* @run main/othervm/policy=security.policy/timeout=240 UnregisterInactive32*/3334import java.io.*;35import java.rmi.*;36import java.rmi.activation.*;37import java.rmi.server.*;38import java.rmi.registry.*;39import java.util.Properties;4041public class UnregisterInactive42extends Activatable43implements ActivateMe, Runnable44{4546public UnregisterInactive(ActivationID id, MarshalledObject obj)47throws ActivationException, RemoteException48{49super(id, 0);50}5152public void ping()53{}5455public void unregister() throws Exception {56super.unregister(super.getID());57}5859/**60* Spawns a thread to deactivate the object.61*/62public void shutdown() throws Exception63{64(new Thread(this,"UnregisterInactive")).start();65}6667/**68* Thread to deactivate object. First attempts to make object69* inactive (via the inactive method). If that fails (the70* object may still have pending/executing calls), then71* unexport the object forcibly.72*/73public void run() {74ActivationLibrary.deactivate(this, getID());75}7677public static void main(String[] args) {7879System.out.println("\nRegression test for bug 4115331\n");8081TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");8283RMID rmid = null;8485try {86RMID.removeLog();87rmid = RMID.createRMID();88rmid.start();89System.err.println("Creating descriptor");909192/* Cause activation groups to have a security policy that will93* allow security managers to be downloaded and installed94*/95Properties p = new Properties();96// this test must always set policies/managers in its97// activation groups98p.put("java.security.policy",99TestParams.defaultGroupPolicy);100p.put("java.security.manager",101TestParams.defaultSecurityManager);102103ActivationGroupDesc groupDesc =104new ActivationGroupDesc(p, null);105ActivationSystem system = ActivationGroup.getSystem();106ActivationGroupID groupID = system.registerGroup(groupDesc);107ActivationGroup.createGroup(groupID, groupDesc, 0);108109ActivationDesc desc =110new ActivationDesc("UnregisterInactive", null, null);111112System.err.println("Registering descriptor");113ActivateMe obj = (ActivateMe) Activatable.register(desc);114115System.err.println("Activate object via method call");116obj.ping();117118System.err.println("Unregister object");119obj.unregister();120121System.err.println("Make object inactive");122obj.shutdown();123124} catch (Exception e) {125TestLibrary.bomb("test failed", e);126} finally {127ActivationLibrary.rmidCleanup(rmid);128}129}130}131132133