J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* @test |
| 25 | * @bug 4720528 |
| 26 | * |
| 27 | * @summary synopsis: (spec) ActivationSystem.activeGroup spec should be |
| 28 | * relaxed (duplicate call to activeGroup with same instantiator and |
| 29 | * incarnation should not throw ActivationException; it should succeed) |
| 30 | * @author Ann Wollrath |
| 31 | * |
| 32 | * @library ../../../testlibrary |
| 33 | * @build TestLibrary RMID |
| 34 | * @build IdempotentActiveGroup |
| 35 | * @run main/othervm/policy=security.policy/timeout=480 IdempotentActiveGroup |
| 36 | */ |
| 37 | |
| 38 | import java.rmi.MarshalledObject; |
| 39 | import java.rmi.NoSuchObjectException; |
| 40 | import java.rmi.RemoteException; |
| 41 | import java.rmi.activation.ActivationDesc; |
| 42 | import java.rmi.activation.ActivationException; |
| 43 | import java.rmi.activation.ActivationGroup; |
| 44 | import java.rmi.activation.ActivationGroupDesc; |
| 45 | import java.rmi.activation.ActivationGroupID; |
| 46 | import java.rmi.activation.ActivationID; |
| 47 | import java.rmi.activation.ActivationInstantiator; |
| 48 | import java.rmi.activation.ActivationSystem; |
| 49 | import java.rmi.server.UnicastRemoteObject; |
| 50 | |
| 51 | public class IdempotentActiveGroup { |
| 52 | |
| 53 | public static void main(String[] args) { |
| 54 | |
| 55 | System.err.println("\nRegression test for bug 4720528\n"); |
| 56 | |
| 57 | TestLibrary.suggestSecurityManager("java.lang.SecurityManager"); |
| 58 | RMID rmid = null; |
| 59 | ActivationInstantiator inst1 = null; |
| 60 | ActivationInstantiator inst2 = null; |
| 61 | |
| 62 | try { |
| 63 | RMID.removeLog(); |
| 64 | rmid = RMID.createRMID(); |
| 65 | rmid.start(); |
| 66 | |
| 67 | System.err.println("Create group descriptor"); |
| 68 | ActivationGroupDesc groupDesc = |
| 69 | new ActivationGroupDesc(null, null); |
| 70 | ActivationSystem system = ActivationGroup.getSystem(); |
| 71 | System.err.println("Register group descriptor"); |
| 72 | ActivationGroupID groupID = system.registerGroup(groupDesc); |
| 73 | inst1 = new FakeInstantiator(); |
| 74 | inst2 = new FakeInstantiator(); |
| 75 | |
| 76 | System.err.println("Invoke activeGroup with inst1"); |
| 77 | system.activeGroup(groupID, inst1, 0); |
| 78 | |
| 79 | try { |
| 80 | System.err.println("Invoke activeGroup with inst2"); |
| 81 | system.activeGroup(groupID, inst2, 0); |
| 82 | throw new RuntimeException( |
| 83 | "TEST FAILED: activeGroup with unequal groups succeeded!"); |
| 84 | } catch (ActivationException expected) { |
| 85 | System.err.println("Caught expected ActivationException"); |
| 86 | System.err.println("Test 1 (of 2) passed"); |
| 87 | } |
| 88 | |
| 89 | try { |
| 90 | System.err.println("Invoke activeGroup with inst1"); |
| 91 | system.activeGroup(groupID, inst1, 0); |
| 92 | System.err.println("activeGroup call succeeded"); |
| 93 | System.err.println("Test 2 (of 2) passed"); |
| 94 | } catch (ActivationException unexpected) { |
| 95 | throw new RuntimeException( |
| 96 | "TEST FAILED: activeGroup with equal groups failed!", |
| 97 | unexpected); |
| 98 | } |
| 99 | |
| 100 | } catch (Exception e) { |
| 101 | TestLibrary.bomb("test failed", e); |
| 102 | } finally { |
| 103 | try { |
| 104 | if (inst1 != null) { |
| 105 | UnicastRemoteObject.unexportObject(inst1, true); |
| 106 | } |
| 107 | if (inst2 != null) { |
| 108 | UnicastRemoteObject.unexportObject(inst2, true); |
| 109 | } |
| 110 | } catch (NoSuchObjectException unexpected) { |
| 111 | throw new AssertionError(unexpected); |
| 112 | } |
| 113 | ActivationLibrary.rmidCleanup(rmid); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | private static class FakeInstantiator |
| 118 | extends UnicastRemoteObject |
| 119 | implements ActivationInstantiator |
| 120 | { |
| 121 | FakeInstantiator() throws RemoteException {} |
| 122 | |
| 123 | public MarshalledObject newInstance(ActivationID id, |
| 124 | ActivationDesc desc) |
| 125 | { |
| 126 | throw new AssertionError(); |
| 127 | } |
| 128 | } |
| 129 | } |