jdk/test/java/rmi/activation/ActivateFailedException/activateFails/ActivateFails.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 309 bda219d843f6
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 1998-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 4097135
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary Need a specific subtype of RemoteException for activation failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * 	    If activation fails to happen during a call to a remote object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *	    then the call should end in an ActivateFailedException. In this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *	    test, the actual "activatable" remote object fails to activate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *	    since its * "activation" constructor throws an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @author Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @library ../../../testlibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @build TestLibrary RMID JavaVM StreamPipe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @build ActivateMe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @build ActivateFails
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @build ActivateFails_Stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @build ShutdownThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @run main/othervm/policy=security.policy/timeout=240 ActivateFails
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.rmi.server.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.rmi.activation.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class ActivateFails
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
	extends Activatable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
	implements ActivateMe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public ActivateFails(ActivationID id, MarshalledObject obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
	throws ActivationException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
	super(id, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
	boolean refuseToActivate = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
	try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
	    refuseToActivate = ((Boolean)obj.get()).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
	} catch (Exception impossible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
	}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
	
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
	if (refuseToActivate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
	    throw new RemoteException("object refuses to activate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public void ping()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Spawns a thread to deactivate the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public ShutdownThread shutdown() throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
	ShutdownThread shutdownThread = new ShutdownThread(this, getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
	shutdownThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
	return(shutdownThread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static void main(String[] args) 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
	RMID rmid = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
	ActivateMe obj1, obj2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
	ShutdownThread shutdownThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
	
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
	System.err.println("\nRegression test for bug 4097135\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
	try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
	    TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
	    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
	     * First run "rmid" and wait for it to start up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
	     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
	    RMID.removeLog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
	    rmid = RMID.createRMID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
	    rmid.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
	    /* Cause activation groups to have a security policy that will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
	     * allow security managers to be downloaded and installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
	     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
	    Properties p = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
	    // this test must always set policies/managers in its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
	    // activation groups
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
	    p.put("java.security.policy", 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
		  TestParams.defaultGroupPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
	    p.put("java.security.manager", 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
		  TestParams.defaultSecurityManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
	    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
	     * Create activation descriptor...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
	     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
	    System.err.println("creating activation descriptor...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
	    ActivationGroupDesc groupDesc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
		new ActivationGroupDesc(p, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
	    ActivationGroupID groupID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
		ActivationGroup.getSystem().registerGroup(groupDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
	    
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
	    ActivationDesc desc1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
		new ActivationDesc(groupID, "ActivateFails",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
				   null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
				   new MarshalledObject(new Boolean(true)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
	    
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
	    ActivationDesc desc2 = 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
		new ActivationDesc(groupID, "ActivateFails",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
				   null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
				   new MarshalledObject(new Boolean(false)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
	    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
	     * Register activation descriptor and make a call on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
	     * the stub. Activation should fail with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
	     * ActivateFailedException.  If not, report an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
	     * error as a RuntimeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
	     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
	    System.err.println("registering activation descriptor...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
	    obj1 = (ActivateMe)Activatable.register(desc1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
	    obj2 = (ActivateMe)Activatable.register(desc2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
	    System.err.println("invoking method on activatable object...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
	    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
		obj1.ping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
	    
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
	    } catch (ActivateFailedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
		/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
		 * This is what is expected so exit with status 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
		 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
		System.err.println("\nsuccess: ActivateFailedException " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
				   "generated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
		e.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
	    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
	    obj2.ping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
	    shutdownThread = obj2.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
	    // wait for shutdown to work 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
	    Thread.sleep(2000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
	    shutdownThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
	    
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
	} catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
	    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
	     * Test failed; unexpected exception generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
	     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
	    TestLibrary.bomb("\nfailure: unexpected exception " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
			       e.getClass().getName() + ": " + e.getMessage(), e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
	    
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
	} finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
	    obj1 = obj2 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
	    ActivationLibrary.rmidCleanup(rmid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
	}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173