Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/ActivationSystem/activeGroup/IdempotentActiveGroup.java
38889 views
/*1* Copyright (c) 2003, 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 472052825* @summary synopsis: (spec) ActivationSystem.activeGroup spec should be26* relaxed (duplicate call to activeGroup with same instantiator and27* incarnation should not throw ActivationException; it should succeed)28* @author Ann Wollrath29*30* @library ../../../testlibrary31* @build TestLibrary RMID ActivationLibrary32* @run main/othervm/policy=security.policy/timeout=480 IdempotentActiveGroup33*/3435import java.rmi.MarshalledObject;36import java.rmi.NoSuchObjectException;37import java.rmi.RemoteException;38import java.rmi.activation.ActivationDesc;39import java.rmi.activation.ActivationException;40import java.rmi.activation.ActivationGroup;41import java.rmi.activation.ActivationGroupDesc;42import java.rmi.activation.ActivationGroupID;43import java.rmi.activation.ActivationID;44import java.rmi.activation.ActivationInstantiator;45import java.rmi.activation.ActivationSystem;46import java.rmi.server.UnicastRemoteObject;4748public class IdempotentActiveGroup {4950public static void main(String[] args) {5152System.err.println("\nRegression test for bug 4720528\n");5354TestLibrary.suggestSecurityManager("java.lang.SecurityManager");55RMID rmid = null;56ActivationInstantiator inst1 = null;57ActivationInstantiator inst2 = null;5859try {60RMID.removeLog();61rmid = RMID.createRMID();62rmid.start();6364System.err.println("Create group descriptor");65ActivationGroupDesc groupDesc =66new ActivationGroupDesc(null, null);67ActivationSystem system = ActivationGroup.getSystem();68System.err.println("Register group descriptor");69ActivationGroupID groupID = system.registerGroup(groupDesc);70inst1 = new FakeInstantiator();71inst2 = new FakeInstantiator();7273System.err.println("Invoke activeGroup with inst1");74system.activeGroup(groupID, inst1, 0);7576try {77System.err.println("Invoke activeGroup with inst2");78system.activeGroup(groupID, inst2, 0);79throw new RuntimeException(80"TEST FAILED: activeGroup with unequal groups succeeded!");81} catch (ActivationException expected) {82System.err.println("Caught expected ActivationException");83System.err.println("Test 1 (of 2) passed");84}8586try {87System.err.println("Invoke activeGroup with inst1");88system.activeGroup(groupID, inst1, 0);89System.err.println("activeGroup call succeeded");90System.err.println("Test 2 (of 2) passed");91} catch (ActivationException unexpected) {92throw new RuntimeException(93"TEST FAILED: activeGroup with equal groups failed!",94unexpected);95}9697} catch (Exception e) {98TestLibrary.bomb("test failed", e);99} finally {100try {101if (inst1 != null) {102UnicastRemoteObject.unexportObject(inst1, true);103}104if (inst2 != null) {105UnicastRemoteObject.unexportObject(inst2, true);106}107} catch (NoSuchObjectException unexpected) {108throw new AssertionError(unexpected);109}110ActivationLibrary.rmidCleanup(rmid);111}112}113114private static class FakeInstantiator115extends UnicastRemoteObject116implements ActivationInstantiator117{118FakeInstantiator() throws RemoteException {}119120public MarshalledObject newInstance(ActivationID id,121ActivationDesc desc)122{123throw new AssertionError();124}125}126}127128129