jdk/test/java/rmi/activation/Activatable/checkImplClassLoader/CheckImplClassLoader.java
author smarks
Mon, 01 Dec 2014 17:59:39 -0800
changeset 27784 a51d6d4e0528
parent 23010 6dadb192ad81
child 30820 0d4717a011d3
permissions -rw-r--r--
8035000: clean up ActivationLibrary.DestroyThread Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
27784
a51d6d4e0528 8035000: clean up ActivationLibrary.DestroyThread
smarks
parents: 23010
diff changeset
     2
 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
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
 * @author Laird Dornin; code borrowed from Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @library ../../../testlibrary
14778
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    30
 * @build TestLibrary RMID
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    31
 *     MyRMI ActivatableImpl ActivatableImpl ActivatableImpl_Stub
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main/othervm/policy=security.policy/timeout=150 CheckImplClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.rmi.server.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.rmi.activation.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * sun.rmi.server.ActivationGroupImpl.newInstance() needs to set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * context class loader when it constructs the implementation class of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * an Activatable object.  It needs to set the ccl to be the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * loader of the implementation class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Test creates an Activatable object whose impl is loaded outside of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * CLASSPATH.  The impls constructor checks to make sure that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * correct context class loader has been set when the constructor is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class CheckImplClassLoader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static Object dummy = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static MyRMI myRMI = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static ActivationGroup group = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static void main(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
         * The following line is required with the JDK 1.2 VM because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
         * of gc hocus pocus that may no longer be needed with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
         * exact vm (hotspot).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        Object dummy1 = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        RMID rmid = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        System.err.println("\nRegression test for bug/rfe 4289544\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            URL implcb = TestLibrary.installClassInCodebase("ActivatableImpl",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                                            "implcb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            TestLibrary.installClassInCodebase("ActivatableImpl_Stub",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                               "implcb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            TestLibrary.suggestSecurityManager(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                TestParams.defaultSecurityManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            RMID.removeLog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            rmid = RMID.createRMID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            rmid.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            System.err.println("Create activation group in this VM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            ActivationGroupDesc groupDesc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                new ActivationGroupDesc(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            ActivationSystem system = ActivationGroup.getSystem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            ActivationGroupID groupID = system.registerGroup(groupDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            group = ActivationGroup.createGroup(groupID, groupDesc, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            ActivationDesc desc = new ActivationDesc("ActivatableImpl",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                                     implcb.toString(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            myRMI = (MyRMI) Activatable.register(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            System.err.println("Checking that impl has correct " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                               "context class loader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            if (!myRMI.classLoaderOk()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                TestLibrary.bomb("incorrect context class loader for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                 "activation constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            System.err.println("Deactivate object via method call");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            myRMI.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            System.err.println("\nsuccess: CheckImplClassLoader test passed ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            TestLibrary.bomb("\nfailure: unexpected exception ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                Thread.sleep(4000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            myRMI = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            System.err.println("rmid shut down");
27784
a51d6d4e0528 8035000: clean up ActivationLibrary.DestroyThread
smarks
parents: 23010
diff changeset
   115
            rmid.cleanup();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            TestLibrary.unexport(group);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
}