author | ohair |
Tue, 25 May 2010 15:58:33 -0700 | |
changeset 5506 | 202f599c92aa |
parent 1581 | 81388748f694 |
child 30376 | 2ccf2cf7ea48 |
permissions | -rw-r--r-- |
1581
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2008, 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 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
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 |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
29 |
* @run clean DerivedGaugeMonitorTest |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
30 |
* @run build DerivedGaugeMonitorTest |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
31 |
* @run main DerivedGaugeMonitorTest |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
32 |
*/ |
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 |
import java.io.Serializable; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
35 |
import java.util.concurrent.CountDownLatch; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
36 |
import java.util.concurrent.TimeUnit; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
37 |
import javax.management.MBeanServer; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
38 |
import javax.management.MBeanServerFactory; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
39 |
import javax.management.ObjectName; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
40 |
import javax.management.monitor.CounterMonitor; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
41 |
import javax.management.monitor.GaugeMonitor; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
42 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
43 |
public class DerivedGaugeMonitorTest { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
44 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
45 |
public static interface Things { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
46 |
public long getALong(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
47 |
public int getAnInt(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
48 |
public double getADouble(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
49 |
public short getAShort(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
50 |
public byte getAByte(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
51 |
public float getAFloat(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
52 |
} |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
53 |
public static interface MyMBean extends Things { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
54 |
public Things getAThing(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
55 |
} |
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 |
public static class MyThings implements Things, Serializable { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
58 |
private static final long serialVersionUID = -4333982919572564126L; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
59 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
60 |
private volatile long along = 0; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
61 |
private volatile int anint = 0; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
62 |
private volatile short ashort = 0; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
63 |
private volatile byte abyte = 0; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
64 |
private volatile float afloat = 0; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
65 |
private volatile double adouble = 0; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
66 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
67 |
private volatile transient boolean mutable; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
68 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
69 |
public MyThings() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
70 |
this(false); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
71 |
} |
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 |
protected MyThings(boolean mutable) { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
74 |
this.mutable=mutable; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
75 |
} |
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 |
public long getALong() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
78 |
return mutable?along++:along; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
79 |
} |
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 |
public int getAnInt() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
82 |
return mutable?anint++:anint; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
83 |
} |
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 |
public double getADouble() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
86 |
return mutable?adouble++:adouble; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
87 |
} |
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 |
public short getAShort() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
90 |
return mutable?ashort++:ashort; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
91 |
} |
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 |
public byte getAByte() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
94 |
return mutable?abyte++:abyte; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
95 |
} |
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 |
public float getAFloat() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
98 |
return mutable?afloat++:afloat; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
99 |
} |
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 |
@Override |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
102 |
public Object clone() throws CloneNotSupportedException { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
103 |
final MyThings other = (MyThings)super.clone(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
104 |
other.mutable=false; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
105 |
return other; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
106 |
} |
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 |
public static class My implements MyMBean { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
110 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
111 |
public final CountDownLatch cdl = new CountDownLatch(6); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
112 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
113 |
private final MyThings things = new MyThings(true); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
114 |
private volatile int count = 0; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
115 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
116 |
public Things getAThing() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
117 |
count++; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
118 |
cdl.countDown(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
119 |
try { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
120 |
return (Things) things.clone(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
121 |
} catch (CloneNotSupportedException ex) { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
122 |
return null; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
123 |
} |
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 |
public long getALong() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
127 |
count++; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
128 |
cdl.countDown(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
129 |
return things.getALong(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
130 |
} |
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 |
public int getAnInt() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
133 |
count++; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
134 |
cdl.countDown(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
135 |
return things.getAnInt(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
136 |
} |
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 |
public double getADouble() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
139 |
count++; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
140 |
cdl.countDown(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
141 |
return things.getADouble(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
142 |
} |
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 |
public short getAShort() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
145 |
count++; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
146 |
cdl.countDown(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
147 |
return things.getAShort(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
148 |
} |
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 |
public byte getAByte() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
151 |
count++; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
152 |
cdl.countDown(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
153 |
return things.getAByte(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
154 |
} |
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 |
public float getAFloat() { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
157 |
count++; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
158 |
cdl.countDown(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
159 |
return things.getAFloat(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
160 |
} |
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 |
public static String[] attributes = { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
166 |
"AByte","AShort","AnInt","ALong","AFloat","ADouble" |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
167 |
}; |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
168 |
public static String[] things = { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
169 |
"AThing.AByte","AThing.AShort","AThing.AnInt","AThing.ALong", |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
170 |
"AThing.AFloat","AThing.ADouble" |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
171 |
}; |
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 |
public static void check(String attr, MBeanServer server, ObjectName mon, |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
174 |
ObjectName mbean) throws Exception { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
175 |
final Object obj = server.getAttribute(mon, "DerivedGauge"); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
176 |
check(attr,server,mon,mbean,obj); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
177 |
} |
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 |
public static void check(String attr, MBeanServer server, ObjectName mon, |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
180 |
ObjectName mbean, Object obj) throws Exception { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
181 |
if (obj == null) |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
182 |
throw new Exception("Derived gauge for: " + attr + |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
183 |
" ["+mon+", "+mbean+"] is null!"); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
184 |
if (!Integer.valueOf(0).equals(obj)) |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
185 |
throw new Exception("Derived gauge for: " + attr + |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
186 |
" ["+mon+", "+mbean+"] is "+obj); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
187 |
} |
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 |
public static void check(String attr, MBeanServer server, ObjectName mon, |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
190 |
ObjectName mbean, long start) throws Exception { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
191 |
final Object obj = server.getAttribute(mon, "DerivedGauge"); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
192 |
final long now = System.currentTimeMillis(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
193 |
final long gran = (Long)server.getAttribute(mon, "GranularityPeriod"); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
194 |
if (now > start +2*gran) { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
195 |
throw new Exception(attr+": Can't verify test case: " + |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
196 |
"granularity period expired!"); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
197 |
} |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
198 |
check(attr,server,mon,mbean,obj); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
199 |
} |
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 |
public static void test(String attr) throws Exception { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
202 |
System.err.println("Testing "+ attr); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
203 |
final MBeanServer server = MBeanServerFactory.createMBeanServer(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
204 |
final ObjectName mbean = new ObjectName("ugly:type=cr.p"); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
205 |
final My my = new My(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
206 |
final GaugeMonitor mon2 = new GaugeMonitor(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
207 |
final ObjectName mon2n = new ObjectName("mon1:type=GaugeMonitor"); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
208 |
final CounterMonitor mon1 = new CounterMonitor(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
209 |
final ObjectName mon1n = new ObjectName("mon2:type=CounterMonitor"); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
210 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
211 |
server.registerMBean(my, mbean); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
212 |
server.registerMBean(mon1, mon1n); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
213 |
server.registerMBean(mon2, mon2n); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
214 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
215 |
mon1.addObservedObject(mbean); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
216 |
mon1.setGranularityPeriod(60000); // 60 sec... |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
217 |
mon1.setObservedAttribute(attr); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
218 |
mon1.setDifferenceMode(true); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
219 |
check(attr,server,mon1n,mbean); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
220 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
221 |
mon2.addObservedObject(mbean); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
222 |
mon2.setGranularityPeriod(60000); // 60 sec... |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
223 |
mon2.setObservedAttribute(attr); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
224 |
mon2.setDifferenceMode(true); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
225 |
check(attr,server,mon2n,mbean); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
226 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
227 |
final long approxStart = System.currentTimeMillis(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
228 |
mon1.start(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
229 |
mon2.start(); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
230 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
231 |
try { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
232 |
check(attr,server,mon1n,mbean,approxStart); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
233 |
check(attr,server,mon2n,mbean,approxStart); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
234 |
check(attr,server,mon1n,mbean,approxStart); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
235 |
check(attr,server,mon2n,mbean,approxStart); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
236 |
|
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 |
mon1.setGranularityPeriod(5); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
239 |
mon2.setGranularityPeriod(5); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
240 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
241 |
my.cdl.await(1000, TimeUnit.MILLISECONDS); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
242 |
if (my.cdl.getCount() > 0) |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
243 |
throw new Exception(attr+": Count down not reached!"); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
244 |
|
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
245 |
// just check that we don't get an exception now... |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
246 |
System.err.println(attr+": [" + mon1n+ |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
247 |
"] DerivedGauge is now "+ |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
248 |
server.getAttribute(mon1n, "DerivedGauge")); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
249 |
System.err.println(attr+": [" + mon2n+ |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
250 |
"] DerivedGauge is now "+ |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
251 |
server.getAttribute(mon2n, "DerivedGauge")); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
252 |
} finally { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
253 |
try {mon1.stop();} catch (Exception x) {} |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
254 |
try {mon2.stop();} catch (Exception x) {} |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
255 |
} |
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 |
public static void main(String[] args) throws Exception { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
262 |
for (String attr:attributes) { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
263 |
test(attr); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
264 |
} |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
265 |
for (String attr:things) { |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
266 |
test(attr); |
81388748f694
6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents:
diff
changeset
|
267 |
} |
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 |
} |