test/jdk/sun/rmi/rmic/newrmic/equivalence/AppleUserImpl.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 42686 jdk/test/sun/rmi/rmic/newrmic/equivalence/AppleUserImpl.java@a907a774b802
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
42686
a907a774b802 8171076: improve rmi tests by replacing TestLibrary.createRegistryOnUnusedPort, getUnusedRandomPort
mli
parents: 13256
diff changeset
     2
 * Copyright (c) 2003, 2016, 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
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.rmi.Naming;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.rmi.server.UnicastRemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.rmi.registry.LocateRegistry;
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
    28
import java.rmi.registry.Registry;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Random;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.logging.Logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The AppleUserImpl class implements the behavior of the remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * "apple user" objects exported by the server.  The application server
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * passes each of its remote "apple" objects to an apple user, and an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * AppleUserThread is created for each apple.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class AppleUserImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    extends UnicastRemoteObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    implements AppleUser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static Logger logger = Logger.getLogger("reliability.appleuser");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static int threadNum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static long testDuration = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static int maxLevel = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static Thread server = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static Exception status = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static Random random = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public AppleUserImpl() throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Allows the other server process to indicate that it is ready
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * to start "juicing".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public synchronized void startTest() throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        this.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Allows the other server process to report an exception to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * process and thereby terminate the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public void reportException(Exception status) throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        synchronized (AppleUserImpl.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            this.status = status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            AppleUserImpl.class.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * "Use" supplied apple object.  Create an AppleUserThread to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * stress it out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public synchronized void useApple(Apple apple) throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        String threadName = Thread.currentThread().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        logger.log(Level.FINEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            threadName + ": AppleUserImpl.useApple(): BEGIN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        AppleUserThread t =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            new AppleUserThread("AppleUserThread-" + (++threadNum), apple);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        t.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        logger.log(Level.FINEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            threadName + ": AppleUserImpl.useApple(): END");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * The AppleUserThread class repeatedly invokes calls on its associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Apple object to stress the RMI system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    class AppleUserThread extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        Apple apple;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        public AppleUserThread(String name, Apple apple) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            this.apple = apple;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            int orangeNum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            long stopTime = System.currentTimeMillis() + testDuration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            Logger logger = Logger.getLogger("reliability.appleuserthread");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                do { // loop until stopTime is reached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                     * Notify apple with some apple events.  This tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                     * serialization of arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    int numEvents = Math.abs(random.nextInt() % 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    AppleEvent[] events = new AppleEvent[numEvents];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    for (int i = 0; i < events.length; ++ i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                        events[i] = new AppleEvent(orangeNum % 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    apple.notify(events);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                     * Request a new orange object be created in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                     * the application server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    Orange orange = apple.newOrange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        "Orange(" + getName() + ")-" + (++orangeNum));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                     * Create a large message of random ints to pass to orange.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    int msgLength = 1000 + Math.abs(random.nextInt() % 3000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    int[] message = new int[msgLength];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    for (int i = 0; i < message.length; ++ i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                        message[i] = random.nextInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                     * Invoke recursive call on the orange.  Base case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                     * of recursion inverts messgage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    OrangeEchoImpl echo = new OrangeEchoImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                        "OrangeEcho(" + getName() + ")-" + orangeNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    int[] response = orange.recurse(echo, message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                        2 + Math.abs(random.nextInt() % (maxLevel + 1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                     * Verify message was properly inverted and not corrupted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                     * through all the recursive method invocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    if (response.length != message.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                        throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                            "ERROR: CORRUPTED RESPONSE: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                            "wrong length of returned array " + "(should be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                            message.length + ", is " + response.length + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    for (int i = 0; i < message.length; ++ i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                        if (~message[i] != response[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                            throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                "ERROR: CORRUPTED RESPONSE: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                "at element " + i + "/" + message.length +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                " of returned array (should be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                Integer.toHexString(~message[i]) + ", is " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                Integer.toHexString(response[i]) + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                        Thread.sleep(Math.abs(random.nextInt() % 10) * 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                } while (System.currentTimeMillis() < stopTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                status = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            synchronized (AppleUserImpl.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                AppleUserImpl.class.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    private static void usage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        System.out.println("Usage: AppleUserImpl [-hours <hours> | " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                                 "-seconds <seconds>]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        System.out.println("                     [-maxLevel <maxLevel>]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        System.out.println("  hours    The number of hours to run the juicer.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        System.out.println("           The default is 0 hours.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        System.out.println("  seconds  The number of seconds to run the juicer.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        System.out.println("           The default is 0 seconds.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        System.out.println("  maxLevel The maximum number of levels to ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        System.out.println("           recurse on each call.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        System.out.println("           The default is 7 levels.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        //TestLibrary.bomb("Bad argument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Entry point for the "juicer" server process.  Create and export
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * an apple user implementation in an rmiregistry running on localhost.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public static void main(String[] args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        //TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        long startTime = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        String durationString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // parse command line args
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            for (int i = 0; i < args.length ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                String arg = args[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                if (arg.equals("-hours")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    if (durationString != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    int hours = Integer.parseInt(args[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    durationString = hours + " hours";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    testDuration = hours * 60 * 60 * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                } else if (arg.equals("-seconds")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    if (durationString != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    long seconds = Long.parseLong(args[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    durationString = seconds + " seconds";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    testDuration = seconds * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                } else if (arg.equals("-maxLevel")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    maxLevel = Integer.parseInt(args[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            if (durationString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                durationString = testDuration + " milliseconds";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        AppleUserImpl user = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            user = new AppleUserImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            //TestLibrary.bomb("Failed to create AppleUser", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        synchronized (user) {
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
   253
            int port = -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            // create new registry and bind new AppleUserImpl in registry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            try {
42686
a907a774b802 8171076: improve rmi tests by replacing TestLibrary.createRegistryOnUnusedPort, getUnusedRandomPort
mli
parents: 13256
diff changeset
   256
                Registry registry = TestLibrary.createRegistryOnEphemeralPort();
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
   257
                port = TestLibrary.getRegistryPort(registry);
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
   258
                Naming.rebind("rmi://localhost:" + port + "/AppleUser",user);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                //TestLibrary.bomb("Failed to bind AppleUser", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            } catch (java.net.MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                //TestLibrary.bomb("Failed to bind AppleUser", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            // start the other server if available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                Class app = Class.forName("ApplicationServer");
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
   268
                java.lang.reflect.Constructor appConstructor =
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
   269
                        app.getDeclaredConstructor(new Class[] {Integer.TYPE});
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
   270
                server = new Thread((Runnable) appConstructor.newInstance(port));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                // assume the other server is running in a separate process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                logger.log(Level.INFO, "Application server must be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    "started in separate process");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            } catch (Exception ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                //TestLibrary.bomb("Could not instantiate server", ie);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            // wait for other server to call startTest method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                logger.log(Level.INFO, "Waiting for application server " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    "process to start");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                user.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                //TestLibrary.bomb("AppleUserImpl interrupted", ie);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        startTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        logger.log(Level.INFO, "Test starting");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        // wait for exception to be reported or first thread to complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            logger.log(Level.INFO, "Waiting " + durationString + " for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                "test to complete or exception to be thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            synchronized (AppleUserImpl.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                AppleUserImpl.class.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            if (status != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                //TestLibrary.bomb("juicer server reported an exception", status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                logger.log(Level.INFO, "TEST PASSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            logger.log(Level.INFO, "TEST FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            //TestLibrary.bomb("unexpected exception", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            logger.log(Level.INFO, "Test finished");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            long actualDuration = System.currentTimeMillis() - startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            logger.log(Level.INFO, "Test duration was " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                (actualDuration/1000) + " seconds " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                "(" + (actualDuration/3600000) + " hours)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
}