Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/Activatable/inactiveGroup/InactiveGroup.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 411608225*26* @summary synopsis: rmid should not destroy group when it reports27* inactiveGroup28* @author Ann Wollrath29*30* @library ../../../testlibrary31* @build TestLibrary RMID ActivationLibrary ActivateMe InactiveGroup_Stub32* @run main/othervm/policy=security.policy/timeout=240 InactiveGroup33*/3435import java.io.*;36import java.rmi.*;37import java.rmi.activation.*;38import java.rmi.server.*;39import java.rmi.registry.*;40import java.util.Properties;4142public class InactiveGroup43implements ActivateMe, Runnable44{4546private ActivationID id;4748public InactiveGroup(ActivationID id, MarshalledObject obj)49throws ActivationException, RemoteException50{51this.id = id;52Activatable.exportObject(this, id, 0);53}5455public InactiveGroup() throws RemoteException {56UnicastRemoteObject.exportObject(this, 0);57}5859public void ping()60{}6162public ActivateMe getUnicastVersion() throws RemoteException {63return new InactiveGroup();64}6566public ActivationID getID() {67return id;68}6970/**71* Spawns a thread to deactivate the object.72*/73public void shutdown() throws Exception74{75(new Thread(this,"InactiveGroup")).start();76}7778/**79* Thread to deactivate object. First attempts to make object80* inactive (via the inactive method). If that fails (the81* object may still have pending/executing calls), then82* unexport the object forcibly.83*/84public void run()85{86ActivationLibrary.deactivate(this, getID());87}8889public static void main(String[] args) {9091System.out.println("\nRegression test for bug 4116082\n");9293TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");9495RMID rmid = null;9697try {98RMID.removeLog();99rmid = RMID.createRMID();100rmid.start();101102/* Cause activation groups to have a security policy that will103* allow security managers to be downloaded and installed104*/105Properties p = new Properties();106// this test must always set policies/managers in its107// activation groups108p.put("java.security.policy",109TestParams.defaultGroupPolicy);110p.put("java.security.manager",111TestParams.defaultSecurityManager);112113/*114* Create descriptor and activate object in a separate VM.115*/116System.err.println("Creating descriptor");117ActivationGroupDesc groupDesc =118new ActivationGroupDesc(p, null);119ActivationGroupID groupID =120ActivationGroup.getSystem().registerGroup(groupDesc);121ActivationDesc desc =122new ActivationDesc(groupID, "InactiveGroup", null, null);123124System.err.println("Registering descriptor");125ActivateMe activatableObj = (ActivateMe) Activatable.register(desc);126127System.err.println("Activate object via method call");128activatableObj.ping();129130/*131* Create a unicast object in the activatable object's VM.132*/133System.err.println("Obtain unicast object");134ActivateMe unicastObj = activatableObj.getUnicastVersion();135136/*137* Make activatable object (and therefore group) inactive.138*/139System.err.println("Make activatable object inactive");140activatableObj.shutdown();141142/*143* Ping the unicast object a few times to make sure that the144* activation group's process hasn't gone away.145*/146System.err.println("Ping unicast object for existence");147for (int i = 0; i < 10; i++) {148unicastObj.ping();149Thread.sleep(500);150}151152/*153* Now, reactivate the activatable object; the unicast object154* should no longer be accessible, since reactivating the155* activatable object should kill the previous group's VM156* and the unicast object along with it.157*/158System.err.println("Reactivate activatable obj");159activatableObj.ping();160161try {162System.err.println("Ping unicast object again");163unicastObj.ping();164} catch (Exception thisShouldFail) {165System.err.println("Test passed: couldn't reach unicast obj: " +166thisShouldFail.getMessage());167return;168}169170TestLibrary.bomb("Test failed: unicast obj accessible after group reactivates",171null);172173} catch (Exception e) {174TestLibrary.bomb("test failed", e);175} finally {176ActivationLibrary.rmidCleanup(rmid);177}178}179}180181182