Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/ActivateFails.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 409713525* @summary Need a specific subtype of RemoteException for activation failure.26* If activation fails to happen during a call to a remote object,27* then the call should end in an ActivateFailedException. In this28* test, the actual "activatable" remote object fails to activate29* since its * "activation" constructor throws an exception.30* @author Ann Wollrath31*32* @library ../../../testlibrary33* @build TestLibrary RMID ActivationLibrary34* ActivateMe ActivateFails_Stub ShutdownThread35* @run main/othervm/policy=security.policy/timeout=240 ActivateFails36*/3738import java.rmi.*;39import java.rmi.server.*;40import java.rmi.activation.*;41import java.io.*;42import java.util.Properties;4344public class ActivateFails45extends Activatable46implements ActivateMe47{4849public ActivateFails(ActivationID id, MarshalledObject obj)50throws ActivationException, RemoteException51{52super(id, 0);5354boolean refuseToActivate = false;55try {56refuseToActivate = ((Boolean)obj.get()).booleanValue();57} catch (Exception impossible) {58}5960if (refuseToActivate)61throw new RemoteException("object refuses to activate");62}6364public void ping()65{}6667/**68* Spawns a thread to deactivate the object.69*/70public ShutdownThread shutdown() throws Exception71{72ShutdownThread shutdownThread = new ShutdownThread(this, getID());73shutdownThread.start();74return(shutdownThread);75}7677public static void main(String[] args)78{79RMID rmid = null;80ActivateMe obj1, obj2;81ShutdownThread shutdownThread;8283System.err.println("\nRegression test for bug 4097135\n");84try {85TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");8687/*88* First run "rmid" and wait for it to start up.89*/90RMID.removeLog();91rmid = RMID.createRMID();92rmid.start();9394/* Cause activation groups to have a security policy that will95* allow security managers to be downloaded and installed96*/97Properties p = new Properties();98// this test must always set policies/managers in its99// activation groups100p.put("java.security.policy",101TestParams.defaultGroupPolicy);102p.put("java.security.manager",103TestParams.defaultSecurityManager);104105/*106* Create activation descriptor...107*/108System.err.println("creating activation descriptor...");109ActivationGroupDesc groupDesc =110new ActivationGroupDesc(p, null);111ActivationGroupID groupID =112ActivationGroup.getSystem().registerGroup(groupDesc);113114ActivationDesc desc1 =115new ActivationDesc(groupID, "ActivateFails",116null,117new MarshalledObject(new Boolean(true)));118119ActivationDesc desc2 =120new ActivationDesc(groupID, "ActivateFails",121null,122new MarshalledObject(new Boolean(false)));123/*124* Register activation descriptor and make a call on125* the stub. Activation should fail with an126* ActivateFailedException. If not, report an127* error as a RuntimeException128*/129130System.err.println("registering activation descriptor...");131obj1 = (ActivateMe)Activatable.register(desc1);132obj2 = (ActivateMe)Activatable.register(desc2);133134System.err.println("invoking method on activatable object...");135try {136obj1.ping();137138} catch (ActivateFailedException e) {139140/*141* This is what is expected so exit with status 0142*/143System.err.println("\nsuccess: ActivateFailedException " +144"generated");145e.getMessage();146}147148obj2.ping();149shutdownThread = obj2.shutdown();150151// wait for shutdown to work152Thread.sleep(2000);153154shutdownThread = null;155156} catch (Exception e) {157/*158* Test failed; unexpected exception generated.159*/160TestLibrary.bomb("\nfailure: unexpected exception " +161e.getClass().getName() + ": " + e.getMessage(), e);162163} finally {164obj1 = obj2 = null;165ActivationLibrary.rmidCleanup(rmid);166}167}168}169170171