IdempotentActiveGroup.java revision 169
0N/A/*
2362N/A * Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
2362N/A * CA 95054 USA or visit www.sun.com if you need additional information or
2362N/A * have any questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 4720528
0N/A *
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
0N/A * @build TestLibrary RMID
0N/A * @build IdempotentActiveGroup
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 {
0N/A
0N/A public static void main(String[] args) {
0N/A
0N/A System.err.println("\nRegression test for bug 4720528\n");
0N/A
0N/A TestLibrary.suggestSecurityManager("java.lang.SecurityManager");
0N/A RMID rmid = null;
0N/A ActivationInstantiator inst1 = null;
0N/A ActivationInstantiator inst2 = null;
0N/A
0N/A try {
0N/A RMID.removeLog();
0N/A rmid = RMID.createRMID();
0N/A rmid.start();
0N/A
0N/A System.err.println("Create group descriptor");
0N/A ActivationGroupDesc groupDesc =
0N/A new ActivationGroupDesc(null, null);
0N/A ActivationSystem system = ActivationGroup.getSystem();
0N/A System.err.println("Register group descriptor");
0N/A ActivationGroupID groupID = system.registerGroup(groupDesc);
0N/A inst1 = new FakeInstantiator();
0N/A inst2 = new FakeInstantiator();
0N/A
0N/A System.err.println("Invoke activeGroup with inst1");
0N/A system.activeGroup(groupID, inst1, 0);
0N/A
0N/A try {
0N/A System.err.println("Invoke activeGroup with inst2");
0N/A system.activeGroup(groupID, inst2, 0);
0N/A throw new RuntimeException(
0N/A "TEST FAILED: activeGroup with unequal groups succeeded!");
0N/A } catch (ActivationException expected) {
0N/A System.err.println("Caught expected ActivationException");
0N/A System.err.println("Test 1 (of 2) passed");
0N/A }
0N/A
0N/A try {
0N/A System.err.println("Invoke activeGroup with inst1");
0N/A system.activeGroup(groupID, inst1, 0);
0N/A System.err.println("activeGroup call succeeded");
0N/A System.err.println("Test 2 (of 2) passed");
0N/A } catch (ActivationException unexpected) {
0N/A throw new RuntimeException(
0N/A "TEST FAILED: activeGroup with equal groups failed!",
0N/A unexpected);
0N/A }
0N/A
0N/A } catch (Exception e) {
0N/A TestLibrary.bomb("test failed", e);
} finally {
try {
if (inst1 != null) {
UnicastRemoteObject.unexportObject(inst1, true);
}
if (inst2 != null) {
UnicastRemoteObject.unexportObject(inst2, true);
}
} catch (NoSuchObjectException unexpected) {
throw new AssertionError(unexpected);
}
ActivationLibrary.rmidCleanup(rmid);
}
}
private static class FakeInstantiator
extends UnicastRemoteObject
implements ActivationInstantiator
{
FakeInstantiator() throws RemoteException {}
public MarshalledObject newInstance(ActivationID id,
ActivationDesc desc)
{
throw new AssertionError();
}
}
}