提交 3035acf6 编写于 作者: S sjiang

8042205: javax/management/monitor/*: some tests didn't get all the notifications

Reviewed-by: dfuchs
上级 74136751
...@@ -58,9 +58,9 @@ import javax.management.openmbean.SimpleType; ...@@ -58,9 +58,9 @@ import javax.management.openmbean.SimpleType;
public class AttributeArbitraryDataTypeTest implements NotificationListener { public class AttributeArbitraryDataTypeTest implements NotificationListener {
// Flag to notify that a message has been received // Flag to notify that a message has been received
private boolean counterMessageReceived = false; private volatile boolean counterMessageReceived = false;
private boolean gaugeMessageReceived = false; private volatile boolean gaugeMessageReceived = false;
private boolean stringMessageReceived = false; private volatile boolean stringMessageReceived = false;
// Match enum // Match enum
public enum Match { do_not_match_0, public enum Match { do_not_match_0,
...@@ -195,21 +195,33 @@ public class AttributeArbitraryDataTypeTest implements NotificationListener { ...@@ -195,21 +195,33 @@ public class AttributeArbitraryDataTypeTest implements NotificationListener {
" has reached or exceeded the threshold"); " has reached or exceeded the threshold");
echo("\t\tDerived Gauge = " + n.getDerivedGauge()); echo("\t\tDerived Gauge = " + n.getDerivedGauge());
echo("\t\tTrigger = " + n.getTrigger()); echo("\t\tTrigger = " + n.getTrigger());
synchronized (this) {
counterMessageReceived = true; counterMessageReceived = true;
notifyAll();
}
} else if (type.equals(MonitorNotification. } else if (type.equals(MonitorNotification.
THRESHOLD_HIGH_VALUE_EXCEEDED)) { THRESHOLD_HIGH_VALUE_EXCEEDED)) {
echo("\t\t" + n.getObservedAttribute() + echo("\t\t" + n.getObservedAttribute() +
" has reached or exceeded the high threshold"); " has reached or exceeded the high threshold");
echo("\t\tDerived Gauge = " + n.getDerivedGauge()); echo("\t\tDerived Gauge = " + n.getDerivedGauge());
echo("\t\tTrigger = " + n.getTrigger()); echo("\t\tTrigger = " + n.getTrigger());
synchronized (this) {
gaugeMessageReceived = true; gaugeMessageReceived = true;
notifyAll();
}
} else if (type.equals(MonitorNotification. } else if (type.equals(MonitorNotification.
STRING_TO_COMPARE_VALUE_MATCHED)) { STRING_TO_COMPARE_VALUE_MATCHED)) {
echo("\t\t" + n.getObservedAttribute() + echo("\t\t" + n.getObservedAttribute() +
" matches the string-to-compare value"); " matches the string-to-compare value");
echo("\t\tDerived Gauge = " + n.getDerivedGauge()); echo("\t\tDerived Gauge = " + n.getDerivedGauge());
echo("\t\tTrigger = " + n.getTrigger()); echo("\t\tTrigger = " + n.getTrigger());
synchronized (this) {
stringMessageReceived = true; stringMessageReceived = true;
notifyAll();
}
} else { } else {
echo("\t\tSkipping notification of type: " + type); echo("\t\tSkipping notification of type: " + type);
} }
...@@ -358,6 +370,17 @@ public class AttributeArbitraryDataTypeTest implements NotificationListener { ...@@ -358,6 +370,17 @@ public class AttributeArbitraryDataTypeTest implements NotificationListener {
// Check if notification was received // Check if notification was received
// //
synchronized (this) {
while (!counterMessageReceived) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("Got unexpected exception: " + e);
e.printStackTrace();
break;
}
}
}
if (counterMessageReceived) { if (counterMessageReceived) {
echo("\tOK: CounterMonitor notification received"); echo("\tOK: CounterMonitor notification received");
} else { } else {
...@@ -525,6 +548,17 @@ public class AttributeArbitraryDataTypeTest implements NotificationListener { ...@@ -525,6 +548,17 @@ public class AttributeArbitraryDataTypeTest implements NotificationListener {
// Check if notification was received // Check if notification was received
// //
synchronized (this) {
while (!gaugeMessageReceived) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("Got unexpected exception: " + e);
e.printStackTrace();
break;
}
}
}
if (gaugeMessageReceived) { if (gaugeMessageReceived) {
echo("\tOK: GaugeMonitor notification received"); echo("\tOK: GaugeMonitor notification received");
} else { } else {
...@@ -680,6 +714,17 @@ public class AttributeArbitraryDataTypeTest implements NotificationListener { ...@@ -680,6 +714,17 @@ public class AttributeArbitraryDataTypeTest implements NotificationListener {
// Check if notification was received // Check if notification was received
// //
synchronized (this) {
while (!stringMessageReceived) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("Got unexpected exception: " + e);
e.printStackTrace();
break;
}
}
}
if (stringMessageReceived) { if (stringMessageReceived) {
echo("\tOK: StringMonitor notification received"); echo("\tOK: StringMonitor notification received");
} else { } else {
......
...@@ -43,9 +43,6 @@ public class CounterMonitorTest implements NotificationListener { ...@@ -43,9 +43,6 @@ public class CounterMonitorTest implements NotificationListener {
// modulus number // modulus number
private Number modulus = new Integer(7); private Number modulus = new Integer(7);
// offset number
private int offset = 0;
// difference mode flag // difference mode flag
private boolean differenceModeFlag = true; private boolean differenceModeFlag = true;
...@@ -58,9 +55,6 @@ public class CounterMonitorTest implements NotificationListener { ...@@ -58,9 +55,6 @@ public class CounterMonitorTest implements NotificationListener {
// counter values // counter values
private int[] values = new int[] {4, 6, 9, 11}; private int[] values = new int[] {4, 6, 9, 11};
// time to wait for notification (in seconds)
private int timeout = 5;
// flag to notify that a message has been received // flag to notify that a message has been received
private volatile boolean messageReceived = false; private volatile boolean messageReceived = false;
...@@ -92,8 +86,9 @@ public class CounterMonitorTest implements NotificationListener { ...@@ -92,8 +86,9 @@ public class CounterMonitorTest implements NotificationListener {
echo("\t\t" + n.getObservedAttribute() + echo("\t\t" + n.getObservedAttribute() +
" has reached or exceeded the threshold"); " has reached or exceeded the threshold");
echo("\t\tDerived Gauge = " + n.getDerivedGauge()); echo("\t\tDerived Gauge = " + n.getDerivedGauge());
messageReceived = true;
synchronized (this) { synchronized (this) {
messageReceived = true;
notifyAll(); notifyAll();
} }
} else { } else {
...@@ -205,21 +200,16 @@ public class CounterMonitorTest implements NotificationListener { ...@@ -205,21 +200,16 @@ public class CounterMonitorTest implements NotificationListener {
} }
/* /*
* Wait until timeout reached * Wait messageReceived to be true
*/ */
void doWait() { synchronized void doWait() {
for (int i = 0; i < timeout; i++) { while (!messageReceived) {
echo("\tdoWait: Waiting for " + timeout + " seconds. " +
"i = " + i + ", messageReceived = " + messageReceived);
if (messageReceived) {
break;
}
try { try {
synchronized (this) { wait();
wait(1000);
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
// OK: Ignore... System.err.println("Got unexpected exception: " + e);
e.printStackTrace();
break;
} }
} }
} }
......
...@@ -39,7 +39,7 @@ import javax.management.monitor.*; ...@@ -39,7 +39,7 @@ import javax.management.monitor.*;
public class NonComparableAttributeValueTest implements NotificationListener { public class NonComparableAttributeValueTest implements NotificationListener {
// Flag to notify that a message has been received // Flag to notify that a message has been received
private boolean messageReceived = false; private volatile boolean messageReceived = false;
// MBean class // MBean class
public class ObservedObject implements ObservedObjectMBean { public class ObservedObject implements ObservedObjectMBean {
...@@ -69,7 +69,11 @@ public class NonComparableAttributeValueTest implements NotificationListener { ...@@ -69,7 +69,11 @@ public class NonComparableAttributeValueTest implements NotificationListener {
echo("\t\t" + n.getObservedAttribute() + " is null"); echo("\t\t" + n.getObservedAttribute() + " is null");
echo("\t\tDerived Gauge = " + n.getDerivedGauge()); echo("\t\tDerived Gauge = " + n.getDerivedGauge());
echo("\t\tTrigger = " + n.getTrigger()); echo("\t\tTrigger = " + n.getTrigger());
synchronized (this) {
messageReceived = true; messageReceived = true;
notifyAll();
}
} else { } else {
echo("\t\tSkipping notification of type: " + type); echo("\t\tSkipping notification of type: " + type);
} }
...@@ -134,12 +138,9 @@ public class NonComparableAttributeValueTest implements NotificationListener { ...@@ -134,12 +138,9 @@ public class NonComparableAttributeValueTest implements NotificationListener {
echo(">>> START the CounterMonitor"); echo(">>> START the CounterMonitor");
counterMonitor.start(); counterMonitor.start();
// Wait for granularity period (multiplied by 2 for sure)
//
Thread.sleep(granularityperiod * 2);
// Check if notification was received // Check if notification was received
// //
doWait();
if (messageReceived) { if (messageReceived) {
echo("\tOK: CounterMonitor notification received"); echo("\tOK: CounterMonitor notification received");
} else { } else {
...@@ -212,12 +213,9 @@ public class NonComparableAttributeValueTest implements NotificationListener { ...@@ -212,12 +213,9 @@ public class NonComparableAttributeValueTest implements NotificationListener {
echo(">>> START the GaugeMonitor"); echo(">>> START the GaugeMonitor");
gaugeMonitor.start(); gaugeMonitor.start();
// Wait for granularity period (multiplied by 2 for sure)
//
Thread.sleep(granularityperiod * 2);
// Check if notification was received // Check if notification was received
// //
doWait();
if (messageReceived) { if (messageReceived) {
echo("\tOK: GaugeMonitor notification received"); echo("\tOK: GaugeMonitor notification received");
} else { } else {
...@@ -289,12 +287,9 @@ public class NonComparableAttributeValueTest implements NotificationListener { ...@@ -289,12 +287,9 @@ public class NonComparableAttributeValueTest implements NotificationListener {
echo(">>> START the StringMonitor"); echo(">>> START the StringMonitor");
stringMonitor.start(); stringMonitor.start();
// Wait for granularity period (multiplied by 2 for sure)
//
Thread.sleep(granularityperiod * 2);
// Check if notification was received // Check if notification was received
// //
doWait();
if (messageReceived) { if (messageReceived) {
echo("\tOK: StringMonitor notification received"); echo("\tOK: StringMonitor notification received");
} else { } else {
...@@ -333,6 +328,21 @@ public class NonComparableAttributeValueTest implements NotificationListener { ...@@ -333,6 +328,21 @@ public class NonComparableAttributeValueTest implements NotificationListener {
System.out.println(message); System.out.println(message);
} }
/*
* Wait messageReceived to be true
*/
synchronized void doWait() {
while (!messageReceived) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("Got unexpected exception: " + e);
e.printStackTrace();
break;
}
}
}
/* /*
* Standalone entry point. * Standalone entry point.
* *
......
...@@ -87,7 +87,11 @@ public class ReflectionExceptionTest implements NotificationListener { ...@@ -87,7 +87,11 @@ public class ReflectionExceptionTest implements NotificationListener {
echo("\tObservedAttribute: " + mn.getObservedAttribute()); echo("\tObservedAttribute: " + mn.getObservedAttribute());
echo("\tDerivedGauge: " + mn.getDerivedGauge()); echo("\tDerivedGauge: " + mn.getDerivedGauge());
echo("\tTrigger: " + mn.getTrigger()); echo("\tTrigger: " + mn.getTrigger());
synchronized (this) {
messageReceived = true; messageReceived = true;
notifyAll();
}
} }
} }
} }
...@@ -135,12 +139,9 @@ public class ReflectionExceptionTest implements NotificationListener { ...@@ -135,12 +139,9 @@ public class ReflectionExceptionTest implements NotificationListener {
echo(">>> START the CounterMonitor"); echo(">>> START the CounterMonitor");
counterMonitor.start(); counterMonitor.start();
// Wait for granularity period (multiplied by 2 for sure)
//
Thread.sleep(granularityperiod * 2);
// Check if notification was received // Check if notification was received
// //
doWait();
if (messageReceived) { if (messageReceived) {
echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!"); echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
} else { } else {
...@@ -203,12 +204,9 @@ public class ReflectionExceptionTest implements NotificationListener { ...@@ -203,12 +204,9 @@ public class ReflectionExceptionTest implements NotificationListener {
echo(">>> START the GaugeMonitor"); echo(">>> START the GaugeMonitor");
gaugeMonitor.start(); gaugeMonitor.start();
// Wait for granularity period (multiplied by 2 for sure)
//
Thread.sleep(granularityperiod * 2);
// Check if notification was received // Check if notification was received
// //
doWait();
if (messageReceived) { if (messageReceived) {
echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!"); echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
} else { } else {
...@@ -270,12 +268,9 @@ public class ReflectionExceptionTest implements NotificationListener { ...@@ -270,12 +268,9 @@ public class ReflectionExceptionTest implements NotificationListener {
echo(">>> START the StringMonitor"); echo(">>> START the StringMonitor");
stringMonitor.start(); stringMonitor.start();
// Wait for granularity period (multiplied by 2 for sure)
//
Thread.sleep(granularityperiod * 2);
// Check if notification was received // Check if notification was received
// //
doWait();
if (messageReceived) { if (messageReceived) {
echo("\tOK: StringMonitor got RUNTIME_ERROR notification!"); echo("\tOK: StringMonitor got RUNTIME_ERROR notification!");
} else { } else {
...@@ -349,8 +344,23 @@ public class ReflectionExceptionTest implements NotificationListener { ...@@ -349,8 +344,23 @@ public class ReflectionExceptionTest implements NotificationListener {
} }
} }
/*
* Wait messageReceived to be true
*/
synchronized void doWait() {
while (!messageReceived) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("Got unexpected exception: " + e);
e.printStackTrace();
break;
}
}
}
// Flag to notify that a message has been received // Flag to notify that a message has been received
private boolean messageReceived = false; private volatile boolean messageReceived = false;
private MBeanServer server; private MBeanServer server;
private ObjectName obsObjName; private ObjectName obsObjName;
......
...@@ -86,7 +86,11 @@ public class RuntimeExceptionTest implements NotificationListener { ...@@ -86,7 +86,11 @@ public class RuntimeExceptionTest implements NotificationListener {
echo("\tObservedAttribute: " + mn.getObservedAttribute()); echo("\tObservedAttribute: " + mn.getObservedAttribute());
echo("\tDerivedGauge: " + mn.getDerivedGauge()); echo("\tDerivedGauge: " + mn.getDerivedGauge());
echo("\tTrigger: " + mn.getTrigger()); echo("\tTrigger: " + mn.getTrigger());
synchronized (this) {
messageReceived = true; messageReceived = true;
notifyAll();
}
} }
} }
} }
...@@ -134,12 +138,9 @@ public class RuntimeExceptionTest implements NotificationListener { ...@@ -134,12 +138,9 @@ public class RuntimeExceptionTest implements NotificationListener {
echo(">>> START the CounterMonitor"); echo(">>> START the CounterMonitor");
counterMonitor.start(); counterMonitor.start();
// Wait for granularity period (multiplied by 2 for sure)
//
Thread.sleep(granularityperiod * 2);
// Check if notification was received // Check if notification was received
// //
doWait();
if (messageReceived) { if (messageReceived) {
echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!"); echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
} else { } else {
...@@ -202,12 +203,9 @@ public class RuntimeExceptionTest implements NotificationListener { ...@@ -202,12 +203,9 @@ public class RuntimeExceptionTest implements NotificationListener {
echo(">>> START the GaugeMonitor"); echo(">>> START the GaugeMonitor");
gaugeMonitor.start(); gaugeMonitor.start();
// Wait for granularity period (multiplied by 2 for sure)
//
Thread.sleep(granularityperiod * 2);
// Check if notification was received // Check if notification was received
// //
doWait();
if (messageReceived) { if (messageReceived) {
echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!"); echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
} else { } else {
...@@ -269,12 +267,9 @@ public class RuntimeExceptionTest implements NotificationListener { ...@@ -269,12 +267,9 @@ public class RuntimeExceptionTest implements NotificationListener {
echo(">>> START the StringMonitor"); echo(">>> START the StringMonitor");
stringMonitor.start(); stringMonitor.start();
// Wait for granularity period (multiplied by 2 for sure)
//
Thread.sleep(granularityperiod * 2);
// Check if notification was received // Check if notification was received
// //
doWait();
if (messageReceived) { if (messageReceived) {
echo("\tOK: StringMonitor got RUNTIME_ERROR notification!"); echo("\tOK: StringMonitor got RUNTIME_ERROR notification!");
} else { } else {
...@@ -347,8 +342,23 @@ public class RuntimeExceptionTest implements NotificationListener { ...@@ -347,8 +342,23 @@ public class RuntimeExceptionTest implements NotificationListener {
} }
} }
/*
* Wait messageReceived to be true
*/
synchronized void doWait() {
while (!messageReceived) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("Got unexpected exception: " + e);
e.printStackTrace();
break;
}
}
}
// Flag to notify that a message has been received // Flag to notify that a message has been received
private boolean messageReceived = false; private volatile boolean messageReceived = false;
private MBeanServer server; private MBeanServer server;
private ObjectName obsObjName; private ObjectName obsObjName;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册