jdk/test/javax/management/monitor/DerivedGaugeMonitorTest.java
author ykantser
Thu, 07 May 2015 09:11:49 +0200
changeset 30376 2ccf2cf7ea48
parent 5506 202f599c92aa
child 44423 306c020eb154
permissions -rw-r--r--
8078896: Add @modules as needed to the jdk_svc tests Reviewed-by: alanb, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1581
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
     2
 * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
1581
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
     4
 *
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
     8
 *
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    14
 *
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1581
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1581
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1581
diff changeset
    21
 * questions.
1581
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    22
 */
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    23
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    24
/*
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    25
 * @test
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    26
 * @bug 6683213
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    27
 * @summary Test that the initial derived gauge is (Integer)0
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    28
 * @author Daniel Fuchs
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
    29
 * @modules java.management
1581
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    30
 * @run clean DerivedGaugeMonitorTest
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    31
 * @run build DerivedGaugeMonitorTest
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    32
 * @run main DerivedGaugeMonitorTest
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    33
 */
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    34
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    35
import java.io.Serializable;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    36
import java.util.concurrent.CountDownLatch;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    37
import java.util.concurrent.TimeUnit;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    38
import javax.management.MBeanServer;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    39
import javax.management.MBeanServerFactory;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    40
import javax.management.ObjectName;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    41
import javax.management.monitor.CounterMonitor;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    42
import javax.management.monitor.GaugeMonitor;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    43
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    44
public class DerivedGaugeMonitorTest {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    45
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    46
    public static interface Things {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    47
        public long getALong();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    48
        public int getAnInt();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    49
        public double getADouble();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    50
        public short getAShort();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    51
        public byte getAByte();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    52
        public float getAFloat();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    53
    }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    54
    public static interface MyMBean extends Things {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    55
        public Things getAThing();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    56
    }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    57
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    58
    public static class MyThings implements Things, Serializable {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    59
        private static final long serialVersionUID = -4333982919572564126L;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    60
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    61
        private volatile long along = 0;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    62
        private volatile int anint = 0;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    63
        private volatile short ashort = 0;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    64
        private volatile byte abyte = 0;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    65
        private volatile float afloat = 0;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    66
        private volatile double adouble = 0;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    67
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    68
        private volatile transient boolean mutable;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    69
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    70
        public MyThings() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    71
            this(false);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    72
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    73
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    74
        protected MyThings(boolean mutable) {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    75
            this.mutable=mutable;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    76
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    77
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    78
        public long getALong() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    79
            return mutable?along++:along;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    80
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    81
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    82
        public int getAnInt() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    83
            return mutable?anint++:anint;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    84
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    85
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    86
        public double getADouble() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    87
            return mutable?adouble++:adouble;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    88
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    89
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    90
        public short getAShort() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    91
            return mutable?ashort++:ashort;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    92
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    93
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    94
        public byte getAByte() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    95
            return mutable?abyte++:abyte;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    96
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    97
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    98
        public float getAFloat() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
    99
            return mutable?afloat++:afloat;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   100
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   101
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   102
        @Override
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   103
        public Object clone() throws CloneNotSupportedException {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   104
            final MyThings other = (MyThings)super.clone();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   105
            other.mutable=false;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   106
            return other;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   107
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   108
    }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   109
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   110
    public static class My implements MyMBean {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   111
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   112
        public final CountDownLatch cdl = new CountDownLatch(6);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   113
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   114
        private final MyThings things = new MyThings(true);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   115
        private volatile int count = 0;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   116
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   117
        public Things getAThing() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   118
            count++;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   119
            cdl.countDown();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   120
            try {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   121
                return (Things) things.clone();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   122
            } catch (CloneNotSupportedException ex) {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   123
                return null;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   124
            }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   125
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   126
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   127
        public long getALong() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   128
            count++;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   129
            cdl.countDown();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   130
            return things.getALong();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   131
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   132
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   133
        public int getAnInt() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   134
            count++;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   135
            cdl.countDown();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   136
            return things.getAnInt();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   137
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   138
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   139
        public double getADouble() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   140
            count++;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   141
            cdl.countDown();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   142
            return things.getADouble();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   143
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   144
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   145
        public short getAShort() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   146
            count++;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   147
            cdl.countDown();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   148
            return things.getAShort();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   149
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   150
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   151
        public byte getAByte() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   152
            count++;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   153
            cdl.countDown();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   154
            return things.getAByte();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   155
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   156
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   157
        public float getAFloat() {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   158
            count++;
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   159
            cdl.countDown();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   160
            return things.getAFloat();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   161
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   162
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   163
    }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   164
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   165
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   166
    public static String[] attributes = {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   167
        "AByte","AShort","AnInt","ALong","AFloat","ADouble"
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   168
    };
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   169
    public static String[] things = {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   170
        "AThing.AByte","AThing.AShort","AThing.AnInt","AThing.ALong",
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   171
        "AThing.AFloat","AThing.ADouble"
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   172
    };
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   173
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   174
    public static void check(String attr, MBeanServer server, ObjectName mon,
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   175
            ObjectName mbean) throws Exception {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   176
        final Object obj = server.getAttribute(mon, "DerivedGauge");
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   177
        check(attr,server,mon,mbean,obj);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   178
    }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   179
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   180
    public static void check(String attr, MBeanServer server, ObjectName mon,
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   181
            ObjectName mbean, Object obj) throws Exception  {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   182
        if (obj == null)
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   183
            throw new Exception("Derived gauge for: " + attr +
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   184
                    " ["+mon+", "+mbean+"] is null!");
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   185
        if (!Integer.valueOf(0).equals(obj))
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   186
            throw new Exception("Derived gauge for: " + attr +
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   187
                    " ["+mon+", "+mbean+"] is "+obj);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   188
    }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   189
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   190
    public static void check(String attr, MBeanServer server, ObjectName mon,
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   191
            ObjectName mbean, long start) throws Exception {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   192
        final Object obj = server.getAttribute(mon, "DerivedGauge");
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   193
        final long now = System.currentTimeMillis();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   194
        final long gran = (Long)server.getAttribute(mon, "GranularityPeriod");
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   195
        if (now > start +2*gran) {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   196
            throw new Exception(attr+": Can't verify test case: " +
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   197
                    "granularity period expired!");
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   198
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   199
        check(attr,server,mon,mbean,obj);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   200
    }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   201
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   202
    public static void test(String attr) throws Exception {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   203
        System.err.println("Testing "+ attr);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   204
        final MBeanServer server = MBeanServerFactory.createMBeanServer();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   205
        final ObjectName mbean = new ObjectName("ugly:type=cr.p");
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   206
        final My my = new My();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   207
        final GaugeMonitor mon2 = new GaugeMonitor();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   208
        final ObjectName mon2n = new ObjectName("mon1:type=GaugeMonitor");
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   209
        final CounterMonitor mon1 = new CounterMonitor();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   210
        final ObjectName mon1n = new ObjectName("mon2:type=CounterMonitor");
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   211
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   212
        server.registerMBean(my, mbean);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   213
        server.registerMBean(mon1, mon1n);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   214
        server.registerMBean(mon2, mon2n);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   215
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   216
        mon1.addObservedObject(mbean);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   217
        mon1.setGranularityPeriod(60000); // 60 sec...
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   218
        mon1.setObservedAttribute(attr);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   219
        mon1.setDifferenceMode(true);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   220
        check(attr,server,mon1n,mbean);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   221
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   222
        mon2.addObservedObject(mbean);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   223
        mon2.setGranularityPeriod(60000); // 60 sec...
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   224
        mon2.setObservedAttribute(attr);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   225
        mon2.setDifferenceMode(true);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   226
        check(attr,server,mon2n,mbean);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   227
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   228
        final long approxStart = System.currentTimeMillis();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   229
        mon1.start();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   230
        mon2.start();
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   231
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   232
        try {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   233
            check(attr,server,mon1n,mbean,approxStart);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   234
            check(attr,server,mon2n,mbean,approxStart);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   235
            check(attr,server,mon1n,mbean,approxStart);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   236
            check(attr,server,mon2n,mbean,approxStart);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   237
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   238
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   239
            mon1.setGranularityPeriod(5);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   240
            mon2.setGranularityPeriod(5);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   241
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   242
            my.cdl.await(1000, TimeUnit.MILLISECONDS);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   243
            if (my.cdl.getCount() > 0)
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   244
                throw new Exception(attr+": Count down not reached!");
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   245
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   246
            // just check that we don't get an exception now...
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   247
            System.err.println(attr+": [" + mon1n+
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   248
                    "] DerivedGauge is now "+
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   249
                    server.getAttribute(mon1n, "DerivedGauge"));
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   250
            System.err.println(attr+": [" + mon2n+
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   251
                    "] DerivedGauge is now "+
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   252
                    server.getAttribute(mon2n, "DerivedGauge"));
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   253
        } finally {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   254
           try {mon1.stop();} catch (Exception x) {}
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   255
           try {mon2.stop();} catch (Exception x) {}
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   256
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   257
    }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   258
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   259
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   260
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   261
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   262
    public static void main(String[] args) throws Exception {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   263
        for (String attr:attributes) {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   264
            test(attr);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   265
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   266
        for (String attr:things) {
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   267
            test(attr);
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   268
        }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   269
    }
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   270
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff changeset
   271
}