jdk/test/javax/management/openmbean/TabularDataOrderTest.java
author iignatyev
Mon, 23 Dec 2013 18:39:47 +0000
changeset 22195 c39aa322d33a
parent 5506 202f599c92aa
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1018
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1018
diff changeset
     2
 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
1018
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
     4
 *
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
     8
 *
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    13
 * accompanied this code).
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    14
 *
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1018
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1018
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1018
diff changeset
    21
 * questions.
1018
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    22
 */
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    23
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    24
/*
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    25
 * @test
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    26
 * @bug 6334663
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    27
 * @summary Test that TabularDataSupport preserves the order elements were added
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    28
 * @author Eamonn McManus
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    29
 */
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    30
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    31
import java.io.ByteArrayInputStream;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    32
import java.io.ByteArrayOutputStream;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    33
import java.io.ObjectInputStream;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    34
import java.io.ObjectOutputStream;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    35
import java.lang.reflect.Field;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    36
import java.lang.reflect.Modifier;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    37
import java.util.ArrayList;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    38
import java.util.HashMap;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    39
import java.util.LinkedHashMap;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    40
import java.util.List;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    41
import java.util.Map;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    42
import javax.management.JMX;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    43
import javax.management.MBeanServer;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    44
import javax.management.MBeanServerFactory;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    45
import javax.management.ObjectName;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    46
import javax.management.openmbean.CompositeData;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    47
import javax.management.openmbean.CompositeDataSupport;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    48
import javax.management.openmbean.CompositeType;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    49
import javax.management.openmbean.OpenDataException;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    50
import javax.management.openmbean.OpenType;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    51
import javax.management.openmbean.SimpleType;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    52
import javax.management.openmbean.TabularData;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    53
import javax.management.openmbean.TabularDataSupport;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    54
import javax.management.openmbean.TabularType;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    55
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    56
public class TabularDataOrderTest {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    57
    private static String failure;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    58
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    59
    private static final String COMPAT_PROP_NAME = "jmx.tabular.data.hash.map";
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    60
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    61
    private static final String[] intNames = {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    62
        "unus", "duo", "tres", "quatuor", "quinque", "sex", "septem",
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    63
        "octo", "novem", "decim",
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    64
    };
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    65
    private static final Map<String, Integer> stringToValue =
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    66
            new LinkedHashMap<String, Integer>();
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    67
    static {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    68
        for (int i = 0; i < intNames.length; i++)
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    69
            stringToValue.put(intNames[i], i + 1);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    70
    }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    71
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    72
    public static interface TestMXBean {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    73
        public Map<String, Integer> getMap();
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    74
    }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    75
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    76
    public static class TestImpl implements TestMXBean {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    77
        public Map<String, Integer> getMap() {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    78
            return stringToValue;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    79
        }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    80
    }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    81
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    82
    private static final CompositeType ct;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    83
    private static final TabularType tt;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    84
    static {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    85
        try {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    86
            ct = new CompositeType(
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    87
                    "a.b.c", "name and int",
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    88
                    new String[] {"name", "int"},
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    89
                    new String[] {"name of integer", "value of integer"},
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    90
                    new OpenType<?>[] {SimpleType.STRING, SimpleType.INTEGER});
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    91
            tt = new TabularType(
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    92
                    "d.e.f", "name and int indexed by name", ct,
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    93
                    new String[] {"name"});
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    94
        } catch (OpenDataException e) {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    95
            throw new AssertionError(e);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    96
        }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    97
    }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    98
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
    99
    private static TabularData makeTable() throws OpenDataException {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   100
        TabularData td = new TabularDataSupport(tt);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   101
        for (Map.Entry<String, Integer> entry : stringToValue.entrySet()) {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   102
            CompositeData cd = new CompositeDataSupport(
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   103
                    ct,
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   104
                    new String[] {"name", "int"},
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   105
                    new Object[] {entry.getKey(), entry.getValue()});
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   106
            td.put(cd);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   107
        }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   108
        return td;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   109
    }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   110
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   111
    public static void main(String[] args) throws Exception {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   112
        System.out.println("Testing standard behaviour");
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   113
        TabularData td = makeTable();
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   114
        System.out.println(td);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   115
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   116
        // Test that a default TabularData has the order keys were added in
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   117
        int last = 0;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   118
        boolean ordered = true;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   119
        for (Object x : td.values()) {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   120
            CompositeData cd = (CompositeData) x;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   121
            String name = (String) cd.get("name");
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   122
            int value = (Integer) cd.get("int");
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   123
            System.out.println(name + " = " + value);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   124
            if (last + 1 != value)
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   125
                ordered = false;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   126
            last = value;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   127
        }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   128
        if (!ordered)
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   129
            fail("Order not preserved");
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   130
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   131
        // Now test the undocumented property that causes HashMap to be used
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   132
        // instead of LinkedHashMap, in case serializing to a 1.3 client.
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   133
        // We serialize and deserialize in case the implementation handles
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   134
        // this at serialization time.  Then we look at object fields; that's
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   135
        // not guaranteed to work but at worst it will fail spuriously and
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   136
        // we'll have to update the test.
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   137
        System.out.println("Testing compatible behaviour");
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   138
        System.setProperty(COMPAT_PROP_NAME, "true");
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   139
        td = makeTable();
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   140
        System.out.println(td);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   141
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   142
        ObjectOutputStream oout = new ObjectOutputStream(bout);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   143
        oout.writeObject(td);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   144
        oout.close();
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   145
        byte[] bytes = bout.toByteArray();
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   146
        ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   147
        ObjectInputStream oin = new ObjectInputStream(bin);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   148
        td = (TabularData) oin.readObject();
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   149
        boolean found = false;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   150
        for (Field f : td.getClass().getDeclaredFields()) {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   151
            if (Modifier.isStatic(f.getModifiers()))
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   152
                continue;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   153
            f.setAccessible(true);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   154
            Object x = f.get(td);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   155
            if (x != null && x.getClass() == HashMap.class) {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   156
                found = true;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   157
                System.out.println(
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   158
                        x.getClass().getName() + " TabularDataSupport." +
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   159
                        f.getName() + " = " + x);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   160
                break;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   161
            }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   162
        }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   163
        if (!found) {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   164
            fail("TabularDataSupport does not contain HashMap though " +
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   165
                    COMPAT_PROP_NAME + "=true");
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   166
        }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   167
        System.clearProperty(COMPAT_PROP_NAME);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   168
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   169
        System.out.println("Testing MXBean behaviour");
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   170
        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   171
        ObjectName name = new ObjectName("a:b=c");
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   172
        mbs.registerMBean(new TestImpl(), name);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   173
        TestMXBean proxy = JMX.newMXBeanProxy(mbs, name, TestMXBean.class);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   174
        Map<String, Integer> map = proxy.getMap();
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   175
        List<String> origNames = new ArrayList<String>(stringToValue.keySet());
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   176
        List<String> proxyNames = new ArrayList<String>(map.keySet());
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   177
        if (!origNames.equals(proxyNames))
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   178
            fail("Order mangled after passage through MXBean: " + proxyNames);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   179
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   180
        if (failure == null)
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   181
            System.out.println("TEST PASSED");
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   182
        else
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   183
            throw new Exception("TEST FAILED: " + failure);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   184
    }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   185
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   186
    private static void fail(String why) {
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   187
        System.out.println("FAILED: " + why);
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   188
        failure = why;
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   189
    }
9f07e65e9653 6334663: TabularDataSupport should be able to return values in the insertion order
emcmanus
parents:
diff changeset
   190
}