jdk/test/javax/management/namespace/ExportNamespaceTest.java
author dfuchs
Wed, 10 Sep 2008 16:27:13 +0200
changeset 1227 4546977d0d66
parent 1156 bbc2d15aaf7a
permissions -rw-r--r--
6746754: jmx namespace: test for leading separator missing 6669137: RFE: InstanceNotFoundException should have a constructor that takes an ObjectName 6746796: jmx namespaces: Several tests are missing an @bug or @run keyword Summary: Note on 6669137: first implementation of 6669137 was actually pushed with 5072476 - here we only have a small update and a test case. Also re-fixes 6737133: Compilation failure of test/javax/management/eventService/LeaseManagerDeadlockTest.java which had failed. Reviewed-by: emcmanus, yjoan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     1
/*
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     4
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     8
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    14
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    18
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    21
 * have any questions.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    22
 */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    23
/*
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    24
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    25
 * @test ExportNamespaceTest.java
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    26
 * @summary Test that you can export a single namespace through a
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    27
 *          JMXConnectorServer.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    28
 * @author Daniel Fuchs
1227
4546977d0d66 6746754: jmx namespace: test for leading separator missing
dfuchs
parents: 1156
diff changeset
    29
 * @bug 5072476
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    30
 * @run clean ExportNamespaceTest Wombat WombatMBean
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    31
 * @run build ExportNamespaceTest Wombat WombatMBean
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    32
 * @run main ExportNamespaceTest
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    33
 */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    34
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    35
import javax.management.JMX;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    36
import javax.management.ObjectName;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    37
import javax.management.namespace.JMXNamespace;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    38
import javax.management.namespace.JMXNamespaces;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    39
import javax.management.MBeanServer;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    40
import javax.management.MBeanServerConnection;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    41
import javax.management.MBeanServerFactory;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    42
import javax.management.remote.JMXConnector;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    43
import javax.management.remote.JMXConnectorFactory;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    44
import javax.management.remote.JMXConnectorServer;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    45
import javax.management.remote.JMXConnectorServerFactory;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    46
import javax.management.remote.JMXServiceURL;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    47
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    48
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    49
/**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    50
 * Test simple creation/registration of namespace.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    51
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    52
 */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    53
public class ExportNamespaceTest {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    54
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    55
    public static void testExport() throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    56
        final JMXNamespace my =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    57
                new JMXNamespace(MBeanServerFactory.newMBeanServer());
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    58
        final MBeanServer s = MBeanServerFactory.newMBeanServer();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    59
        final ObjectName myname = JMXNamespaces.getNamespaceObjectName("my");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    60
        final ObjectName wname = ObjectName.getInstance("backyard:type=Wombat");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    61
        my.getSourceServer().registerMBean(new Wombat(),wname);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    62
        s.registerMBean(my,myname);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    63
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    64
        if (!s.queryNames(new ObjectName("my//b*:*"),null).contains(
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    65
                JMXNamespaces.insertPath("my", wname))) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    66
            throw new RuntimeException("1: Wombat not found: "+wname);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    67
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    68
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    69
        final MBeanServer cd = JMXNamespaces.narrowToNamespace(s, "my");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    70
        if (!cd.queryNames(new ObjectName("b*:*"),null).contains(wname)) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    71
            throw new RuntimeException("2: Wombat not found: "+wname);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    72
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    73
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    74
        final JMXServiceURL url = new JMXServiceURL("rmi",null,0);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    75
        final JMXConnectorServer server =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    76
                JMXConnectorServerFactory.newJMXConnectorServer(url, null, cd);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    77
        server.start();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    78
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    79
        final JMXConnector jc = JMXConnectorFactory.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    80
                connect(server.getAddress(),null);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    81
        final MBeanServerConnection mbsc = jc.getMBeanServerConnection();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    82
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    83
        if (!mbsc.queryNames(new ObjectName("b*:*"),null).contains(wname)) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    84
            throw new RuntimeException("3: Wombat not found: "+wname);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    85
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    86
        System.out.println("Found a Wombat in my backyard.");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    87
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    88
        final String deepThoughts = "I want to leave this backyard!";
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    89
        final WombatMBean w = JMX.newMBeanProxy(mbsc, wname, WombatMBean.class);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    90
        w.setCaption(deepThoughts);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    91
        if (!deepThoughts.equals(w.getCaption()))
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    92
                throw new RuntimeException("4: Wombat is not thinking right: "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    93
                        w.getCaption());
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    94
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    95
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    96
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    97
    public static void main(String... args) throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    98
        testExport();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    99
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   100
}