jdk/test/java/rmi/transport/httpSocket/HttpSocketTest.java
author dmocek
Tue, 17 Jul 2012 11:01:44 -0700
changeset 13256 5886d7607acd
parent 5506 202f599c92aa
child 14778 5947768d173d
permissions -rw-r--r--
7142596: RMI JPRT tests are failing Summary: Changed RMI tests to use random port numbers for the RMI Registry and RMID so the tests can be run concurrently without test failures due to tests using the same port numbers. Reviewed-by: smarks, alanb Contributed-by: olivier.lagneau@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
     1
/*
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2012, 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: 715
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary HttpSocket functionality test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @author Dana Burns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @library ../../testlibrary
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
    30
 * @build HttpSocketTest HttpSocketTest_Stub TestLibrary
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run main/othervm/policy=security.policy HttpSocketTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *  This test assures remote methods can be carried out over RMI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *  After setting the RMI runtime socket factory to the http proxy version,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *  a registry is created, a remote object (an instance of this class) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *  registered with it, and then it is exercised.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.rmi.Naming;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.rmi.RMISecurityManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.rmi.registry.LocateRegistry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.rmi.registry.Registry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.rmi.server.RMISocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.rmi.server.UnicastRemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.rmi.transport.proxy.RMIHttpToPortSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
interface MyRemoteInterface extends Remote {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    void setRemoteObject( Remote r ) throws RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    Remote getRemoteObject() throws RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    56
public class HttpSocketTest extends UnicastRemoteObject
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    implements MyRemoteInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final String NAME = "HttpSocketTest";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public HttpSocketTest() throws RemoteException{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private Remote ro;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public static void main(String[] args)
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    66
        throws Exception
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    {
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    68
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    69
        Registry registry = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    71
        TestLibrary.suggestSecurityManager(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    73
        // Set the socket factory.
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    74
        System.err.println("installing socket factory");
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    75
        RMISocketFactory.setSocketFactory(new RMIHttpToPortSocketFactory());
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
    76
        int registryPort = -1;
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    77
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    78
        try {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            System.err.println("Starting registry");
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
    80
            registry = TestLibrary.createRegistryOnUnusedPort();
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
    81
            registryPort = TestLibrary.getRegistryPort(registry);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        } catch (Exception e) {
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    83
            TestLibrary.bomb(e);
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    84
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    86
        try {
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    87
            registry.rebind( NAME, new HttpSocketTest() );
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    88
            MyRemoteInterface httpTest =
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
    89
                (MyRemoteInterface)Naming.lookup("//:" + registryPort + "/" + NAME);
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    90
            httpTest.setRemoteObject( new HttpSocketTest() );
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    91
            Remote r = httpTest.getRemoteObject();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    93
        } catch (Exception e) {
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    94
            TestLibrary.bomb(e);
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    95
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public void setRemoteObject( Remote ro ) throws RemoteException {
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
   101
        this.ro = ro;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public Remote getRemoteObject() throws RemoteException {
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
   105
        return( this.ro );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}