jdk/test/sun/management/jmxremote/bootstrap/RmiBootstrapTest.java
author jbachorik
Mon, 18 Nov 2013 15:25:15 +0100
changeset 21802 b36494ddf19e
parent 21408 6468b29c9877
child 23031 995cf5c2eb55
permissions -rw-r--r--
8027163: sun/management/jmxremote/bootstrap/CustomLauncherTest.java should be updated for jdk8 removal of solaris-32bit support Reviewed-by: sla
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2013, 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
import sun.management.jmxremote.ConnectorBootstrap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.FilenameFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
    29
import java.net.BindException;
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
    30
import java.net.ServerSocket;
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
    31
import java.rmi.server.ExportException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.remote.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.management.AgentConfigurationError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import util.TestLogger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>This class implements unit test for RMI Bootstrap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * When called with no arguments main() looks in the directory indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * by the "test.src" system property for files called management*ok.properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * or management*ko.properties. The *ok.properties files are assumed to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * valid Java M&M config files for which the bootstrap should succeed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * The *ko.properties files are assumed to be configurations for which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * bootstrap & connection test will fail.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>The rmi port number can be specified with the "rmi.port" system property.
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
    58
 * If not, this test will use the first available port</p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>When called with some argument, the main() will interprete its args to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * be Java M&M configuration file names. The filenames are expected to end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * with ok.properties or ko.properties - and are interpreted as above.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>Note that a limitation of the RMI registry (bug 4267864) prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * this test from succeeding if more than 1 configuration is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * As long as 4267864 isn't fix, this test must be called as many times
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * as needed but with a single argument (no arguments, or several arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * will fail).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>Debug traces are logged in "sun.management.test"</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
public class RmiBootstrapTest {
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
    73
    // the number of consecutive ports to test for availability
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
    74
    private static final int PORT_TEST_LEN = 800;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static TestLogger log =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        new TestLogger("RmiBootstrapTest");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * When launching several registries, we increment the port number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * to avoid falling into "port number already in use" problems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    static int testPort = 0;
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
    83
    static int basePort = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Default values for RMI configuration properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static interface DefaultValues {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        public static final String PORT="0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        public static final String CONFIG_FILE_NAME="management.properties";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        public static final String USE_SSL="true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        public static final String USE_AUTHENTICATION="true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        public static final String PASSWORD_FILE_NAME="jmxremote.password";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        public static final String ACCESS_FILE_NAME="jmxremote.access";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        public static final String KEYSTORE="keystore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        public static final String KEYSTORE_PASSWD="password";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        public static final String TRUSTSTORE="truststore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        public static final String TRUSTSTORE_PASSWD="trustword";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        public static final String SSL_NEED_CLIENT_AUTH="false";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Names of RMI configuration properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public static interface PropertyNames {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        public static final String PORT=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            "com.sun.management.jmxremote.port";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        public static final String CONFIG_FILE_NAME=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            "com.sun.management.config.file";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        public static final String USE_SSL=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            "com.sun.management.jmxremote.ssl";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        public static final String USE_AUTHENTICATION=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            "com.sun.management.jmxremote.authenticate";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        public static final String PASSWORD_FILE_NAME=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            "com.sun.management.jmxremote.password.file";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        public static final String ACCESS_FILE_NAME=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            "com.sun.management.jmxremote.access.file";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        public static final String INSTRUMENT_ALL=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            "com.sun.management.instrumentall";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        public static final String CREDENTIALS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            "jmx.remote.credentials";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        public static final String KEYSTORE=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            "javax.net.ssl.keyStore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        public static final String KEYSTORE_PASSWD=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            "javax.net.ssl.keyStorePassword";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        public static final String TRUSTSTORE=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            "javax.net.ssl.trustStore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        public static final String TRUSTSTORE_PASSWD=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            "javax.net.ssl.trustStorePassword";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        public static final String SSL_ENABLED_CIPHER_SUITES =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            "com.sun.management.jmxremote.ssl.enabled.cipher.suites";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        public static final String SSL_ENABLED_PROTOCOLS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            "com.sun.management.jmxremote.ssl.enabled.protocols";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        public static final String SSL_NEED_CLIENT_AUTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            "com.sun.management.jmxremote.ssl.need.client.auth";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * A filter to find all filenames who match <prefix>*<suffix>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Note that <prefix> and <suffix> can overlap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private static class ConfigFilenameFilter implements FilenameFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        final String suffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        final String prefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        ConfigFilenameFilter(String prefix, String suffix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            this.suffix=suffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            this.prefix=prefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        public boolean accept(File dir, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            return (name.startsWith(prefix) && name.endsWith(suffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Get all "management*ok.properties" files in the directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * indicated by the "test.src" management property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private static File[] findConfigurationFilesOk() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        final String testSrc = System.getProperty("test.src");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        final File dir = new File(testSrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        final FilenameFilter filter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            new ConfigFilenameFilter("management_test","ok.properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return dir.listFiles(filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Get all "management*ko.properties" files in the directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * indicated by the "test.src" management property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private static File[] findConfigurationFilesKo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        final String testSrc = System.getProperty("test.src");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        final File dir = new File(testSrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        final FilenameFilter filter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            new ConfigFilenameFilter("management_test","ko.properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return dir.listFiles(filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * List all MBeans and their attributes. Used to test communication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * with the Java M&M MBean Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @return the number of queried MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public static int listMBeans(MBeanServerConnection server)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return listMBeans(server,null,null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * List all matching MBeans and their attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Used to test communication with the Java M&M MBean Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @return the number of matching MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public static int listMBeans(MBeanServerConnection server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                  ObjectName pattern, QueryExp query)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        final Set names = server.queryNames(pattern,query);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        for (final Iterator i=names.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            ObjectName name = (ObjectName)i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            log.trace("listMBeans","Got MBean: "+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                MBeanInfo info =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    server.getMBeanInfo((ObjectName)name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                MBeanAttributeInfo[] attrs = info.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                if (attrs == null) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                for (int j=0; j<attrs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    if (attrs[j].isReadable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                            Object o =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                server.getAttribute(name,attrs[j].getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                            if (log.isDebugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                log.debug("listMBeans","\t\t" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                          attrs[j].getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                                          " = "+o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                            log.trace("listMBeans","JmxClient failed to get " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                      attrs[j].getName() + ": " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                            final IOException io =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                new IOException("JmxClient failed to get " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                                attrs[j].getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                            io.initCause(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                            throw io;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
               log.trace("listMBeans",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                         "JmxClient failed to get MBeanInfo: "  + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                final IOException io =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    new IOException("JmxClient failed to get MBeanInfo: "+x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                io.initCause(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                throw io;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return names.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Compute the full path name for a default file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param basename basename (with extension) of the default file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @return ${JRE}/lib/management/${basename}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    private static String getDefaultFileName(String basename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        final String fileSeparator = File.separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        final StringBuffer defaultFileName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            new StringBuffer(System.getProperty("java.home")).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            append(fileSeparator).append("lib").append(fileSeparator).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            append("management").append(fileSeparator).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            append(basename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return defaultFileName.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Compute the full path name for a default file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param basename basename (with extension) of the default file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return ${JRE}/lib/management/${basename}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    private static String getDefaultStoreName(String basename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        final String fileSeparator = File.separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        final StringBuffer defaultFileName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            new StringBuffer(System.getProperty("test.src")).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            append(fileSeparator).append("ssl").append(fileSeparator).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            append(basename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return defaultFileName.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Parses the password file to read the credentials.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Returns an ArrayList of arrays of 2 string:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * {<subject>, <password>}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * If the password file does not exists, return an empty list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * (File not found = empty file).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private ArrayList readCredentials(String passwordFileName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        final Properties pws = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        final ArrayList  result = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        final File f = new File(passwordFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (!f.exists()) return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        FileInputStream fin = new FileInputStream(passwordFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        try {pws.load(fin);}finally{fin.close();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        for (Enumeration en=pws.propertyNames();en.hasMoreElements();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            final String[] cred = new String[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            cred[0]=(String)en.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            cred[1]=pws.getProperty(cred[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            result.add(cred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Connect with the given url, using all given credentials in turn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * A null entry in the useCredentials arrays indicate a connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * where no credentials are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @param url JMXServiceURL of the server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @param useCredentials An array of credentials (a credential
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *        is a two String array, so this is an array of arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *        of strings:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *           useCredentials[i][0]=subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *           useCredentials[i][1]=password
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *        if useCredentials[i] == null means no credentials.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @param expectConnectOk true if connection is expected to succeed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *    Note: if expectConnectOk=false and the test fails to connect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *          the number of failure is not incremented. Conversely,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *          if expectConnectOk=false and the test does not fail to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *          connect the number of failure is incremented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @param expectReadOk true if communication (listMBeans) is expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *        to succeed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *    Note: if expectReadOk=false and the test fails to read MBeans
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *          the number of failure is not incremented. Conversely,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *          if expectReadOk=false and the test does not fail to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *          read MBeans the number of failure is incremented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @return number of failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public int connectAndRead(JMXServiceURL url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                              Object[] useCredentials,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                              boolean  expectConnectOk,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                              boolean  expectReadOk)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        int errorCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        for (int i=0 ; i<useCredentials.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            final Map m = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            final String[] credentials = (String[])useCredentials[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            final String   crinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            if (credentials != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                crinfo = "{"+credentials[0] + ", " + credentials[1] + "}";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                m.put(PropertyNames.CREDENTIALS,credentials);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                crinfo="no credentials";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            log.trace("testCommunication","using credentials: " + crinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            final JMXConnector c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                c = JMXConnectorFactory.connect(url,m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            } catch (IOException x ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                if (expectConnectOk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    final String err = "Connection failed for " + crinfo +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                        ": " + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    System.out.println(err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    log.trace("testCommunication",err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    log.debug("testCommunication",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    errorCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    System.out.println("Connection failed as expected for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                                       crinfo + ": " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            } catch (RuntimeException x ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                if (expectConnectOk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                    final String err = "Connection failed for " + crinfo +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        ": " + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    System.out.println(err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    log.trace("testCommunication",err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    log.debug("testCommunication",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    errorCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    System.out.println("Connection failed as expected for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                       crinfo + ": " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                MBeanServerConnection conn =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    c.getMBeanServerConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                if (log.isDebugOn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    log.debug("testCommunication","Connection is:" + conn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    log.debug("testCommunication","Server domain is: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                              conn.getDefaultDomain());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                final ObjectName pattern =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                    new ObjectName("java.lang:type=Memory,*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                final int count = listMBeans(conn,pattern,null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                if (count == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    throw new Exception("Expected at least one matching "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                                        "MBean for "+pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                if (expectReadOk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    System.out.println("Communication succeeded " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                                       "as expected for "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                                       crinfo + ": found " + count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                                       + ((count<2)?"MBean":"MBeans"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    final String err = "Expected failure didn't occur for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                        crinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    System.out.println(err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    errorCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            } catch (IOException x ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                if (expectReadOk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    final String err = "Communication failed with " + crinfo +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                        ": " + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    System.out.println(err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    log.trace("testCommunication",err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    log.debug("testCommunication",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    errorCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    System.out.println("Communication failed as expected for "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                                       crinfo + ": " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            } catch (RuntimeException x ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                if (expectReadOk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    final String err = "Communication failed with " + crinfo +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                        ": " + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    System.out.println(err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    log.trace("testCommunication",err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    log.debug("testCommunication",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    errorCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    System.out.println("Communication failed as expected for "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                                       crinfo + ": " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                final String err = "Failed to read MBeans with " + crinfo +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    ": " + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                System.out.println(err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                log.trace("testCommunication",err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                log.debug("testCommunication",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                errorCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                c.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return errorCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    private void setSslProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        final String defaultKeyStore =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            getDefaultStoreName(DefaultValues.KEYSTORE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        final String defaultTrustStore =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            getDefaultStoreName(DefaultValues.TRUSTSTORE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        final String keyStore =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            System.getProperty(PropertyNames.KEYSTORE, defaultKeyStore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        System.setProperty(PropertyNames.KEYSTORE,keyStore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        log.trace("setSslProperties",PropertyNames.KEYSTORE+"="+keyStore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        final String password =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            System.getProperty(PropertyNames.KEYSTORE_PASSWD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                               DefaultValues.KEYSTORE_PASSWD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        System.setProperty(PropertyNames.KEYSTORE_PASSWD,password);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        log.trace("setSslProperties",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                  PropertyNames.KEYSTORE_PASSWD+"="+password);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        final String trustStore =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            System.getProperty(PropertyNames.TRUSTSTORE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                               defaultTrustStore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        System.setProperty(PropertyNames.TRUSTSTORE,trustStore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        log.trace("setSslProperties",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                  PropertyNames.TRUSTSTORE+"="+trustStore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        final String trustword =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            System.getProperty(PropertyNames.TRUSTSTORE_PASSWD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                               DefaultValues.TRUSTSTORE_PASSWD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        System.setProperty(PropertyNames.TRUSTSTORE_PASSWD,trustword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        log.trace("setSslProperties",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                  PropertyNames.TRUSTSTORE_PASSWD+"="+trustword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    private void checkSslConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            final String defaultConf =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                getDefaultFileName(DefaultValues.CONFIG_FILE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            final String confname =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                System.getProperty(PropertyNames.CONFIG_FILE_NAME,defaultConf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            final Properties props = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            final File conf = new File(confname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            if (conf.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                FileInputStream fin = new FileInputStream(conf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                try {props.load(fin);} finally {fin.close();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            // Do we use SSL?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            final String  useSslStr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                props.getProperty(PropertyNames.USE_SSL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                  DefaultValues.USE_SSL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            final boolean useSsl =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                Boolean.valueOf(useSslStr).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            log.debug("checkSslConfiguration",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                      PropertyNames.USE_SSL+"="+useSsl+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                      ": setting SSL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            // Do we use SSL client authentication?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            final String  useSslClientAuthStr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                props.getProperty(PropertyNames.SSL_NEED_CLIENT_AUTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                  DefaultValues.SSL_NEED_CLIENT_AUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            final boolean useSslClientAuth =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                Boolean.valueOf(useSslClientAuthStr).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            log.debug("checkSslConfiguration",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                      PropertyNames.SSL_NEED_CLIENT_AUTH+"="+useSslClientAuth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            // Do we use customized SSL cipher suites?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            final String sslCipherSuites =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                props.getProperty(PropertyNames.SSL_ENABLED_CIPHER_SUITES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            log.debug("checkSslConfiguration",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                      PropertyNames.SSL_ENABLED_CIPHER_SUITES + "=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                      sslCipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            // Do we use customized SSL protocols?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            final String sslProtocols =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                props.getProperty(PropertyNames.SSL_ENABLED_PROTOCOLS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            log.debug("checkSslConfiguration",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                      PropertyNames.SSL_ENABLED_PROTOCOLS + "=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                      sslProtocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            if (useSsl) setSslProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            System.out.println("Failed to setup SSL configuration: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            log.debug("checkSslConfiguration",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * Tests the server bootstraped at the given URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Uses the system properties to determine which config file is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * Loads the config file to determine which password file is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * Loads the password file to find out wich credentials to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * Also checks that unregistered user/passwords are not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * connect when a password file is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * This method calls connectAndRead().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public void testCommunication(JMXServiceURL url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        final String defaultConf =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            getDefaultFileName(DefaultValues.CONFIG_FILE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        final String confname =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            System.getProperty(PropertyNames.CONFIG_FILE_NAME,defaultConf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        final Properties props = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        final File conf = new File(confname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        if (conf.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            FileInputStream fin = new FileInputStream(conf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            try {props.load(fin);} finally {fin.close();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        // Do we use authentication?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        final String  useAuthenticationStr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            props.getProperty(PropertyNames.USE_AUTHENTICATION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                              DefaultValues.USE_AUTHENTICATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        final boolean useAuthentication =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            Boolean.valueOf(useAuthenticationStr).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        // Get Password File
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        final String defaultPasswordFileName = Utils.convertPath(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            getDefaultFileName(DefaultValues.PASSWORD_FILE_NAME));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        final String passwordFileName = Utils.convertPath(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            props.getProperty(PropertyNames.PASSWORD_FILE_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                              defaultPasswordFileName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        // Get Access File
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        final String defaultAccessFileName = Utils.convertPath(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            getDefaultFileName(DefaultValues.ACCESS_FILE_NAME));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        final String accessFileName = Utils.convertPath(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            props.getProperty(PropertyNames.ACCESS_FILE_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                              defaultAccessFileName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (useAuthentication) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            System.out.println("PasswordFileName: " + passwordFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            System.out.println("accessFileName: " + accessFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        final Object[] allCredentials;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        final Object[] noCredentials = { null };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        if (useAuthentication) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            final ArrayList l = readCredentials(passwordFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            if (l.size() == 0) allCredentials = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            else allCredentials = l.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        } else allCredentials = noCredentials;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        int errorCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        if (allCredentials!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            // Tests that the registered user/passwords are allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            // connect & read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            errorCount += connectAndRead(url,allCredentials,true,true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            // Tests that no one is allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            // connect & read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            final String[][] someCredentials = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                { "modify", "R&D" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                { "measure", "QED" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            errorCount += connectAndRead(url,someCredentials,false,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        if (useAuthentication && allCredentials != noCredentials) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            // Tests that the registered user/passwords are not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            // connect & read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            final String[][] badCredentials = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                { "bad.user", "R&D" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                { "measure", "bad.password" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            errorCount += connectAndRead(url,badCredentials,false,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        if (errorCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            final String err = "Test " + confname + " failed with " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                errorCount + " error(s)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            log.debug("testCommunication",err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            throw new RuntimeException(err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Test the configuration indicated by `file'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * Sets the appropriate System properties for config file and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * port and then calls ConnectorBootstrap.initialize().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * eventually cleans up by calling ConnectorBootstrap.terminate().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @return null if the test succeeds, an error message otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     **/
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   630
    private String testConfiguration(File file,int port) throws BindException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        final String path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            path=(file==null)?null:file.getCanonicalPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        } catch(IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            final String err = "Failed to test configuration " + file +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                ": " + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            log.trace("testConfiguration",err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            log.debug("testConfiguration",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            return err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        final String config = (path==null)?"Default config file":path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        System.out.println("***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        System.out.println("*** Testing configuration (port=" + port + "): "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                           + path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        System.out.println("***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        System.setProperty("com.sun.management.jmxremote.port",
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   650
                            Integer.toString(port));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        if (path != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            System.setProperty("com.sun.management.config.file", path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            System.getProperties().remove("com.sun.management.config.file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        log.trace("testConfiguration","com.sun.management.jmxremote.port="+port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        if (path != null && log.isDebugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            log.trace("testConfiguration",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                      "com.sun.management.config.file="+path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        checkSslConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        final JMXConnectorServer cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            cs = ConnectorBootstrap.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        } catch (AgentConfigurationError x) {
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   667
            if (x.getCause() instanceof ExportException) {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   668
                if (x.getCause().getCause() instanceof BindException) {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   669
                    throw (BindException)x.getCause().getCause();
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   670
                }
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   671
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            final String err = "Failed to initialize connector:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                "\n\tcom.sun.management.jmxremote.port=" + port +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                ((path!=null)?"\n\tcom.sun.management.config.file="+path:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                 "\n\t"+config) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                "\n\tError is: " + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            log.trace("testConfiguration",err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            log.debug("testConfiguration",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            return err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            log.debug("testConfiguration",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            return x.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            JMXServiceURL url =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                new JMXServiceURL("rmi",null,0,"/jndi/rmi://localhost:"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                                  port+"/jmxrmi");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                testCommunication(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                final String err = "Failed to connect to agent {url="+url+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    "}: " + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                log.trace("testConfiguration",err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                log.debug("testConfiguration",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                return err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            final String err = "Failed to test configuration "+config+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                ": "+x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            log.trace("testConfiguration",err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            log.debug("testConfiguration",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            return err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                cs.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                final String err = "Failed to terminate: "+x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                log.trace("testConfiguration",err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                log.debug("testConfiguration",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        System.out.println("Configuration " + config + " successfully tested");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * Test a configuration file which should make the bootstrap fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * The test is assumed to have succeeded if the bootstrap fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * @return null if the test succeeds, an error message otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    private String testConfigurationKo(File conf,int port) {
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   724
        String errStr = null;
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   725
        for (int i = 0; i < PORT_TEST_LEN; i++) {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   726
            try {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   727
                errStr = testConfiguration(conf,port+testPort++);
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   728
                break;
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   729
            } catch (BindException e) {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   730
                // port conflict; try another port
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   731
            }
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   732
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        if (errStr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            return "Configuration " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                conf + " should have failed!";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        System.out.println("Configuration " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                           conf + " failed as expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        log.debug("runko","Error was: " + errStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * Test a configuration file. Determines whether the bootstrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * should succeed or fail depending on the file name:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     *     *ok.properties: bootstrap should succeed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *     *ko.properties: bootstrap or connection should fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * @return null if the test succeeds, an error message otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    private String testConfigurationFile(String fileName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        File file = new File(fileName);
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   752
        final String portStr = System.getProperty("rmi.port",null);
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   753
        final int port       = portStr != null ?
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   754
                                Integer.parseInt(portStr) : basePort;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        if (fileName.endsWith("ok.properties")) {
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   757
            String errStr = null;
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   758
            for (int i = 0; i < PORT_TEST_LEN; i++) {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   759
                try {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   760
                    errStr = testConfiguration(file,port+testPort++);
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   761
                    return errStr;
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   762
                } catch (BindException e) {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   763
                    // port conflict; try another port
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   764
                }
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   765
            }
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   766
            return "Can not locate available port";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        if (fileName.endsWith("ko.properties")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            return testConfigurationKo(file,port+testPort++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        return fileName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            ": test file suffix must be one of [ko|ok].properties";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * Find all *ko.property files and test them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * (see findConfigurationFilesKo() and testConfigurationKo())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @throws RuntimeException if the test fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    public void runko() {
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   781
        final String portStr = System.getProperty("rmi.port",null);
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   782
        final int port       = portStr != null ?
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   783
                                Integer.parseInt(portStr) : basePort;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        final File[] conf = findConfigurationFilesKo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        if ((conf == null)||(conf.length == 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            throw new RuntimeException("No configuration found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        String errStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        for (int i=0;i<conf.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            errStr = testConfigurationKo(conf[i],port+testPort++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            if (errStr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                throw new RuntimeException(errStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * Find all *ok.property files and test them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * (see findConfigurationFilesOk() and testConfiguration())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @throws RuntimeException if the test fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    public void runok() {
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   804
        final String portStr = System.getProperty("rmi.port",null);
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   805
        final int port       = portStr != null ?
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   806
                                Integer.parseInt(portStr) : basePort;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        final File[] conf = findConfigurationFilesOk();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        if ((conf == null)||(conf.length == 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            throw new RuntimeException("No configuration found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   811
        String errStr = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        for (int i=0;i<conf.length;i++) {
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   813
            for (int j = 0; j < PORT_TEST_LEN; i++) {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   814
                try {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   815
                    errStr = testConfiguration(conf[i],port+testPort++);
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   816
                    break;
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   817
                } catch (BindException e) {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   818
                    // port conflict; try another port
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   819
                }
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   820
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            if (errStr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                throw new RuntimeException(errStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        // FIXME: No jmxremote.password is not installed in JRE by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        // - disable the following test case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        // Test default config
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        // errStr = testConfiguration(null,port+testPort++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        // if (errStr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        //    throw new RuntimeException(errStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        // }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * Finds all configuration files (*ok.properties and *ko.properties)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * and tests them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * (see runko() and runok()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @throws RuntimeException if the test fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        runok();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        runko();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * Tests the specified configuration files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * If args[] is not empty, each element in args[] is expected to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * a filename ending either by ok.properties or ko.properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * Otherwise, the configuration files will be automatically determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * by looking at all *.properties files located in the directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * indicated by the System property "test.src".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @throws RuntimeException if the test fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    public void run(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        if (args.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            run() ; return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        for (int i=0; i<args.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            final String errStr =testConfigurationFile(args[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            if (errStr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                throw new RuntimeException(errStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * Calls run(args[]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * exit(1) if the test fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     **/
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   873
    public static void main(String args[]) throws Exception {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   874
        setupBasePort();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        RmiBootstrapTest manager = new RmiBootstrapTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            manager.run(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        } catch (RuntimeException r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            System.out.println("Test Failed: "+ r.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            System.out.println("Test Failed: "+ t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            t.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            System.exit(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        System.out.println("**** Test  RmiBootstrap Passed ****");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
21408
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   889
    private static void setupBasePort() throws IOException {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   890
        try (ServerSocket s = new ServerSocket(0)) {
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   891
            basePort = s.getLocalPort() + 1;
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   892
        }
6468b29c9877 8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents: 5506
diff changeset
   893
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
}