169N/A/*
2362N/A * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 4720528
0N/A * @summary synopsis: (spec) ActivationSystem.activeGroup spec should be
0N/A * relaxed (duplicate call to activeGroup with same instantiator and
0N/A * incarnation should not throw ActivationException; it should succeed)
0N/A * @author Ann Wollrath
0N/A *
0N/A * @library ../../../testlibrary
5551N/A * @build TestLibrary RMID ActivationLibrary
0N/A * @run main/othervm/policy=security.policy/timeout=480 IdempotentActiveGroup
0N/A */
0N/A
0N/Aimport java.rmi.MarshalledObject;
0N/Aimport java.rmi.NoSuchObjectException;
0N/Aimport java.rmi.RemoteException;
0N/Aimport java.rmi.activation.ActivationDesc;
0N/Aimport java.rmi.activation.ActivationException;
0N/Aimport java.rmi.activation.ActivationGroup;
0N/Aimport java.rmi.activation.ActivationGroupDesc;
0N/Aimport java.rmi.activation.ActivationGroupID;
0N/Aimport java.rmi.activation.ActivationID;
0N/Aimport java.rmi.activation.ActivationInstantiator;
0N/Aimport java.rmi.activation.ActivationSystem;
0N/Aimport java.rmi.server.UnicastRemoteObject;
0N/A
0N/Apublic class IdempotentActiveGroup {
169N/A
0N/A public static void main(String[] args) {
0N/A
169N/A System.err.println("\nRegression test for bug 4720528\n");
169N/A
169N/A TestLibrary.suggestSecurityManager("java.lang.SecurityManager");
169N/A RMID rmid = null;
169N/A ActivationInstantiator inst1 = null;
169N/A ActivationInstantiator inst2 = null;
169N/A
169N/A try {
169N/A RMID.removeLog();
169N/A rmid = RMID.createRMID();
169N/A rmid.start();
0N/A
169N/A System.err.println("Create group descriptor");
169N/A ActivationGroupDesc groupDesc =
169N/A new ActivationGroupDesc(null, null);
169N/A ActivationSystem system = ActivationGroup.getSystem();
169N/A System.err.println("Register group descriptor");
169N/A ActivationGroupID groupID = system.registerGroup(groupDesc);
169N/A inst1 = new FakeInstantiator();
169N/A inst2 = new FakeInstantiator();
169N/A
169N/A System.err.println("Invoke activeGroup with inst1");
169N/A system.activeGroup(groupID, inst1, 0);
0N/A
169N/A try {
169N/A System.err.println("Invoke activeGroup with inst2");
169N/A system.activeGroup(groupID, inst2, 0);
169N/A throw new RuntimeException(
169N/A "TEST FAILED: activeGroup with unequal groups succeeded!");
169N/A } catch (ActivationException expected) {
169N/A System.err.println("Caught expected ActivationException");
169N/A System.err.println("Test 1 (of 2) passed");
169N/A }
0N/A
169N/A try {
169N/A System.err.println("Invoke activeGroup with inst1");
169N/A system.activeGroup(groupID, inst1, 0);
169N/A System.err.println("activeGroup call succeeded");
169N/A System.err.println("Test 2 (of 2) passed");
169N/A } catch (ActivationException unexpected) {
169N/A throw new RuntimeException(
169N/A "TEST FAILED: activeGroup with equal groups failed!",
169N/A unexpected);
169N/A }
169N/A
169N/A } catch (Exception e) {
169N/A TestLibrary.bomb("test failed", e);
169N/A } finally {
169N/A try {
169N/A if (inst1 != null) {
169N/A UnicastRemoteObject.unexportObject(inst1, true);
169N/A }
169N/A if (inst2 != null) {
169N/A UnicastRemoteObject.unexportObject(inst2, true);
169N/A }
169N/A } catch (NoSuchObjectException unexpected) {
169N/A throw new AssertionError(unexpected);
169N/A }
169N/A ActivationLibrary.rmidCleanup(rmid);
169N/A }
0N/A }
0N/A
0N/A private static class FakeInstantiator
169N/A extends UnicastRemoteObject
169N/A implements ActivationInstantiator
0N/A {
169N/A FakeInstantiator() throws RemoteException {}
0N/A
169N/A public MarshalledObject newInstance(ActivationID id,
169N/A ActivationDesc desc)
169N/A {
169N/A throw new AssertionError();
169N/A }
0N/A }
0N/A}