jdk/test/javax/management/remote/mandatory/connection/RMIExitTest.java
author dbuck
Tue, 18 Aug 2015 04:29:28 -0700
changeset 32417 6859107fc6c3
parent 30376 2ccf2cf7ea48
child 43503 bc7f8619ab70
permissions -rw-r--r--
8133666: OperatingSystemMXBean reports abnormally high machine CPU consumption on Linux Reviewed-by: sla, mgronlun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2015, 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: 4156
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @bug 4917237
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary test that process exit immediately after stop() / close() called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Jean Francois Denise
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
    30
 * @modules java.management
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run clean RMIExitTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run build RMIExitTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @run main RMIExitTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.MBeanServerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.MBeanServerConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.NotificationListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.Notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.remote.JMXServiceURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.remote.JMXConnectorServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.remote.JMXConnector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.management.remote.JMXConnectorServerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.management.remote.JMXConnectorFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * VM shutdown hook. Test that the hook is called less than 5 secs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * after expected exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
class TimeChecker extends Thread {
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    57
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        System.out.println("shutdown hook called");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        long elapsedTime =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            System.currentTimeMillis() - RMIExitTest.exitStartTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        if(elapsedTime >= 5000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            System.out.println("BUG 4917237 not Fixed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            // Once in hook, to provide an exit status != 0, halt must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            // be called. Hooks are not called when halt is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            Runtime.getRuntime().halt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            System.out.println("BUG 4917237 Fixed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * Start a server, connect a client, add/remove listeners, close client,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * stop server. Check that VM exits in less than 5 secs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
public class RMIExitTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static final MBeanServer mbs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        MBeanServerFactory.createMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static long exitStartTime = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        System.out.println("Start test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        Runtime.getRuntime().addShutdownHook(new TimeChecker());
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
    86
        test();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        exitStartTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        System.out.println("End test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
    91
    private static void test() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            JMXConnectorServer server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            JMXServiceURL addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            JMXConnector client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            MBeanServerConnection mserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            final ObjectName delegateName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                new ObjectName("JMImplementation:type=MBeanServerDelegate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            final NotificationListener dummyListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                new NotificationListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                        public void handleNotification(Notification n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                                       Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                            // do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            server = JMXConnectorServerFactory.newJMXConnectorServer(u,
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
   111
                                                                     null,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                                                     mbs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            server.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            addr = server.getAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            client = JMXConnectorFactory.newJMXConnector(addr, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            client.connect(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            mserver = client.getMBeanServerConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            String s1 = "1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            String s2 = "2";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            String s3 = "3";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            mserver.addNotificationListener(delegateName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                            dummyListener, null, s1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            mserver.addNotificationListener(delegateName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                            dummyListener, null, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            mserver.addNotificationListener(delegateName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                            dummyListener, null, s3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            mserver.removeNotificationListener(delegateName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                               dummyListener, null, s3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            mserver.removeNotificationListener(delegateName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                               dummyListener, null, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            mserver.removeNotificationListener(delegateName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                               dummyListener, null, s1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            client.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            server.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            System.out.println(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}