test/jdk/javax/management/Introspector/AnnotationTest.java
author kbarrett
Wed, 13 Nov 2019 18:00:30 -0500
changeset 59067 f080b08daace
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232588: G1 concurrent System.gc can return early or late 8233279: G1: GCLocker GC with +GCLockerInvokesConcurrent spins while cycle in progress Summary: Refactor G1CH::try_collect and fix bugs with concurrent collections. Reviewed-by: tschatzl, sjohanss
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) 2005, 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
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6221321 6295867
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that annotations in Standard MBean interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * correctly produce Descriptor entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Eamonn McManus
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    30
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run clean AnnotationTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run build AnnotationTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @run main AnnotationTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    36
import java.lang.annotation.Retention;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    37
import java.lang.annotation.RetentionPolicy;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    38
import javax.management.Descriptor;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    39
import javax.management.DescriptorRead;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    40
import javax.management.DescriptorKey;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    41
import javax.management.ImmutableDescriptor;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    42
import javax.management.MBeanAttributeInfo;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    43
import javax.management.MBeanConstructorInfo;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    44
import javax.management.MBeanInfo;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    45
import javax.management.MBeanOperationInfo;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    46
import javax.management.MBeanServer;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    47
import javax.management.ObjectName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  This test checks that annotations produce Descriptor entries as
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    51
  specified in javax.management.DescriptorKey.  It does two things:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  - An annotation consisting of an int and a String, each with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    appropriate @DescriptorKey annotation, is placed on every program
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    element where it can map to a Descriptor, namely:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    . on an MBean interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    . on a getter for a read-only attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    . on a setter for a write-only attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    . on the getter but not the setter for a read/write attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    . on the setter but not the getter for a read/write attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    . on both the getter and the setter for a read/write attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    . on an operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    . on each parameter of an operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    . on a public constructor with no parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    . on a public constructor with a parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    . on the parameter of that public constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    . on all of the above for an MXBean instead of an MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    The test checks that in each case the corresponding Descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    appears in the appropriate place inside the MBean's MBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  - An annotation consisting of enough other types to ensure coverage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    is placed on a getter.  The test checks that the generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    MBeanAttributeInfo contains the corresponding Descriptor.  The tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    types are the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    . Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    . an enumeration type (java.lang.annotation.RetentionPolicy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    . boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    . String[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    . Class[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    . int[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    . an array of enumeration type (RetentionPolicy[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    . boolean[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
public class AnnotationTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static String failed = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    @Retention(RetentionPolicy.RUNTIME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public static @interface Pair {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        @DescriptorKey("x")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        int x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        @DescriptorKey("y")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        String y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    @Retention(RetentionPolicy.RUNTIME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public static @interface Full {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        @DescriptorKey("class")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        Class classValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        @DescriptorKey("enum")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        RetentionPolicy enumValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        @DescriptorKey("boolean")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        boolean booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        @DescriptorKey("stringArray")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        String[] stringArrayValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        @DescriptorKey("classArray")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        Class[] classArrayValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        @DescriptorKey("intArray")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        int[] intArrayValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        @DescriptorKey("enumArray")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        RetentionPolicy[] enumArrayValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        @DescriptorKey("booleanArray")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        boolean[] booleanArrayValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   118
    /* We use the annotation @Pair(x = 3, y = "foo") everywhere, and this is
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   119
       the Descriptor that it should produce: */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private static Descriptor expectedDescriptor =
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   121
        new ImmutableDescriptor(new String[] {"x", "y"},
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   122
                                new Object[] {3, "foo"});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private static Descriptor expectedFullDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        new ImmutableDescriptor(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                    "class", "enum", "boolean", "stringArray",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                    "classArray", "intArray", "enumArray",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                    "booleanArray",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                    Full.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                    RetentionPolicy.RUNTIME.name(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                    false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                    new String[] {"foo", "bar"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                    new String[] {Full.class.getName()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                    new int[] {1, 2},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                    new String[] {RetentionPolicy.RUNTIME.name()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                    new boolean[] {false, true},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public static interface ThingMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        @Full(classValue=Full.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
              enumValue=RetentionPolicy.RUNTIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
              booleanValue=false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
              stringArrayValue={"foo", "bar"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
              classArrayValue={Full.class},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
              intArrayValue={1, 2},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
              enumArrayValue={RetentionPolicy.RUNTIME},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
              booleanArrayValue={false, true})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        int getReadOnly();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        void setWriteOnly(int x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        int getReadWrite1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        void setReadWrite1(int x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        int getReadWrite2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        void setReadWrite2(int x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        int getReadWrite3();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        void setReadWrite3(int x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        @Pair(x = 3, y = "foo")
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   171
        int operation(@Pair(x = 3, y = "foo") int p1,
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   172
                      @Pair(x = 3, y = "foo") int p2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public static class Thing implements ThingMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        public Thing() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        @Pair(x = 3, y = "foo")
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   180
        public Thing(@Pair(x = 3, y = "foo") int p1) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        public int getReadOnly() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        public void setWriteOnly(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        public int getReadWrite1() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        public void setReadWrite1(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        public int getReadWrite2() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        public void setReadWrite2(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        public int getReadWrite3() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        public void setReadWrite3(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        public int operation(int p1, int p2) {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public static interface ThingMXBean extends ThingMBean {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public static class ThingImpl implements ThingMXBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        public ThingImpl() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        @Pair(x = 3, y = "foo")
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   206
        public ThingImpl(@Pair(x = 3, y = "foo") int p1) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        public int getReadOnly() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        public void setWriteOnly(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        public int getReadWrite1() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        public void setReadWrite1(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        public int getReadWrite2() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        public void setReadWrite2(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        public int getReadWrite3() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        public void setReadWrite3(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        public int operation(int p1, int p2) {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        System.out.println("Testing that annotations are correctly " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                           "reflected in Descriptor entries");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        MBeanServer mbs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            java.lang.management.ManagementFactory.getPlatformMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        ObjectName on = new ObjectName("a:b=c");
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   231
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Thing thing = new Thing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        mbs.registerMBean(thing, on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        check(mbs, on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        mbs.unregisterMBean(on);
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   236
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        ThingImpl thingImpl = new ThingImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        mbs.registerMBean(thingImpl, on);
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   239
        Descriptor d = mbs.getMBeanInfo(on).getDescriptor();
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   240
        if (!d.getFieldValue("mxbean").equals("true")) {
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   241
            System.out.println("NOT OK: expected MXBean");
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   242
            failed = "Expected MXBean";
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   243
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        check(mbs, on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (failed == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            System.out.println("Test passed");
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   248
        else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            throw new Exception("TEST FAILED: " + failed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    private static void check(MBeanServer mbs, ObjectName on) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        MBeanInfo mbi = mbs.getMBeanInfo(on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        // check the MBean itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        check(mbi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        // check attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        MBeanAttributeInfo[] attrs = mbi.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        for (MBeanAttributeInfo attr : attrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            check(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            if (attr.getName().equals("ReadOnly"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                check("@Full", attr.getDescriptor(), expectedFullDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // check operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        MBeanOperationInfo[] ops = mbi.getOperations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        for (MBeanOperationInfo op : ops) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            check(op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            check(op.getSignature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        MBeanConstructorInfo[] constrs = mbi.getConstructors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        for (MBeanConstructorInfo constr : constrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            check(constr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            check(constr.getSignature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    private static void check(DescriptorRead x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        check(x, x.getDescriptor(), expectedDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private static void check(Object x, Descriptor d, Descriptor expect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        String fail = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            Descriptor u = ImmutableDescriptor.union(d, expect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            if (!u.equals(d))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                fail = "should contain " + expect + "; is " + d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            fail = e.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (fail == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            System.out.println("OK: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            failed = "NOT OK: Incorrect descriptor for: " + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            System.out.println(failed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            System.out.println("..." + fail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    private static void check(DescriptorRead[] xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        for (DescriptorRead x : xx)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            check(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
}