jdk/test/java/rmi/activation/Activatable/checkImplClassLoader/CheckImplClassLoader.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2001 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 4289544
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary ActivationGroupImpl.newInstance does not set context classloader for impl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Laird Dornin; code borrowed from Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @library ../../../testlibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @build TestLibrary RMID JavaVM StreamPipe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @build MyRMI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @build CheckImplClassLoader ActivatableImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @build ActivatableImpl ActivatableImpl_Stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @run main/othervm/policy=security.policy/timeout=150 CheckImplClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.rmi.server.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.rmi.activation.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * sun.rmi.server.ActivationGroupImpl.newInstance() needs to set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * context class loader when it constructs the implementation class of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * an Activatable object.  It needs to set the ccl to be the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * loader of the implementation class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Test creates an Activatable object whose impl is loaded outside of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * CLASSPATH.  The impls constructor checks to make sure that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * correct context class loader has been set when the constructor is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class CheckImplClassLoader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static Object dummy = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static MyRMI myRMI = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static ActivationGroup group = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public static void main(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
         * The following line is required with the JDK 1.2 VM because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
         * of gc hocus pocus that may no longer be needed with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
         * exact vm (hotspot).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        Object dummy1 = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        RMID rmid = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        System.err.println("\nRegression test for bug/rfe 4289544\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            URL implcb = TestLibrary.installClassInCodebase("ActivatableImpl",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                                            "implcb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            TestLibrary.installClassInCodebase("ActivatableImpl_Stub",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                                               "implcb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            TestLibrary.suggestSecurityManager(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                TestParams.defaultSecurityManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            RMID.removeLog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            rmid = RMID.createRMID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            rmid.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            System.err.println("Create activation group in this VM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            ActivationGroupDesc groupDesc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                new ActivationGroupDesc(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            ActivationSystem system = ActivationGroup.getSystem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            ActivationGroupID groupID = system.registerGroup(groupDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            group = ActivationGroup.createGroup(groupID, groupDesc, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            ActivationDesc desc = new ActivationDesc("ActivatableImpl",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                                     implcb.toString(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            myRMI = (MyRMI) Activatable.register(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            System.err.println("Checking that impl has correct " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                               "context class loader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            if (!myRMI.classLoaderOk()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                TestLibrary.bomb("incorrect context class loader for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                 "activation constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            System.err.println("Deactivate object via method call");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            myRMI.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            System.err.println("\nsuccess: CheckImplClassLoader test passed ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            TestLibrary.bomb("\nfailure: unexpected exception ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                Thread.sleep(4000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            myRMI = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            System.err.println("rmid shut down");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            ActivationLibrary.rmidCleanup(rmid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            TestLibrary.unexport(group);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}