Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java
38889 views
/*1* Copyright (c) 1998, 2013, 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 413423325* @bug 421318626* @summary synopsis: ActivationSystem.unregisterGroup should unregister objects in group27* @author Ann Wollrath28*29* @library ../../../testlibrary30* @build TestLibrary RMID ActivationLibrary ActivateMe31* @run main/othervm/policy=security.policy UnregisterGroup32*/3334import java.io.*;35import java.rmi.*;36import java.rmi.activation.*;37import java.rmi.server.*;38import java.util.Properties;3940public class UnregisterGroup extends Activatable implements ActivateMe41{42private static volatile Exception exception = null;43private static volatile String error = null;44private static volatile boolean done = false;45private static final int NUM_OBJECTS = 10;4647public UnregisterGroup(ActivationID id, MarshalledObject mobj)48throws Exception49{50super(id, 0);51}5253/**54* Does nothing, but serves to activate this object.55*/56public void ping() { }5758/**59* Deactivates the object. We need to unexport forcibly because60* this call is in-progress on this object, which is the same object61* that we are trying to deactivate.62*/63public void shutdown() throws Exception {64Activatable.unexportObject(this, true);65ActivationLibrary.deactivate(this, getID());66}6768public static void main(String[] args) throws RemoteException {69TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");70RMID rmid = null;7172try {73RMID.removeLog();74rmid = RMID.createRMID();75rmid.start();7677/* Cause activation groups to have a security policy that will78* allow security managers to be downloaded and installed79*/80final Properties p = new Properties();81// this test must always set policies/managers in its82// activation groups83p.put("java.security.policy", TestParams.defaultGroupPolicy);84p.put("java.security.manager", TestParams.defaultSecurityManager);8586Thread t = new Thread() {87public void run () {88try {89System.err.println("Creating group descriptor");90ActivationGroupDesc groupDesc =91new ActivationGroupDesc(p, null);92ActivationSystem system = ActivationGroup.getSystem();93ActivationGroupID groupID =94system.registerGroup(groupDesc);9596ActivateMe[] obj = new ActivateMe[NUM_OBJECTS];9798for (int i = 0; i < NUM_OBJECTS; i++) {99System.err.println("Creating descriptor: " + i);100ActivationDesc desc =101new ActivationDesc(groupID, "UnregisterGroup",102null, null);103System.err.println("Registering descriptor: " + i);104obj[i] = (ActivateMe) Activatable.register(desc);105System.err.println("Activating object: " + i);106obj[i].ping();107}108109System.err.println("Unregistering group");110system.unregisterGroup(groupID);111112try {113System.err.println("Get the group descriptor");114system.getActivationGroupDesc(groupID);115error = "test failed: group still registered";116} catch (UnknownGroupException e) {117System.err.println("Test passed: " +118"group unregistered");119}120121/*122* Deactivate objects so group VM will exit.123*/124for (int i = 0; i < NUM_OBJECTS; i++) {125System.err.println("Deactivating object: " + i);126obj[i].shutdown();127obj[i] = null;128}129System.err.println("Successfully deactivated all objects.");130131} catch (Exception e) {132exception = e;133}134135done = true;136}137};138139t.start();140141// Default jtreg timeout is two minutes.142// Timeout ourselves after one minute so that143// we can clean up.144t.join(60000);145146if (exception != null) {147TestLibrary.bomb("test failed", exception);148} else if (error != null) {149TestLibrary.bomb(error, null);150} else if (!done) {151TestLibrary.bomb("test failed: not completed before timeout", null);152} else {153System.err.println("Test passed");154}155} catch (Exception e) {156TestLibrary.bomb("test failed", e);157} finally {158ActivationLibrary.rmidCleanup(rmid);159}160}161}162163164