8065764: javax/management/monitor/CounterMonitorTest.java hangs
Reviewed-by: jbachorik, dfuchs
This commit is contained in:
parent
792bc020b9
commit
31af33c0e2
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -26,7 +26,7 @@
|
|||||||
* @bug 4981829
|
* @bug 4981829
|
||||||
* @summary Test that the counter monitor, when running in difference mode,
|
* @summary Test that the counter monitor, when running in difference mode,
|
||||||
* emits a notification every time the threshold is exceeded.
|
* emits a notification every time the threshold is exceeded.
|
||||||
* @author Luis-Miguel Alventosa
|
* @author Luis-Miguel Alventosa, Shanliang JIANG
|
||||||
* @run clean CounterMonitorTest
|
* @run clean CounterMonitorTest
|
||||||
* @run build CounterMonitorTest
|
* @run build CounterMonitorTest
|
||||||
* @run main CounterMonitorTest
|
* @run main CounterMonitorTest
|
||||||
@ -50,23 +50,31 @@ public class CounterMonitorTest implements NotificationListener {
|
|||||||
private boolean notifyFlag = true;
|
private boolean notifyFlag = true;
|
||||||
|
|
||||||
// granularity period
|
// granularity period
|
||||||
private int granularityperiod = 500;
|
private int granularityperiod = 10;
|
||||||
|
|
||||||
// counter values
|
// derived gauge
|
||||||
private int[] values = new int[] {4, 6, 9, 11};
|
private volatile int derivedGauge = 2;
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
|
private volatile Object observedValue = null;
|
||||||
|
|
||||||
// MBean class
|
// MBean class
|
||||||
public class StdObservedObject implements StdObservedObjectMBean {
|
public class StdObservedObject implements StdObservedObjectMBean {
|
||||||
public Object getNbObjects() {
|
public Object getNbObjects() {
|
||||||
|
echo(">>> StdObservedObject.getNbObjects: " + count);
|
||||||
|
synchronized(CounterMonitorTest.class) {
|
||||||
|
observedValue = count;
|
||||||
|
CounterMonitorTest.class.notifyAll();
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
public void setNbObjects(Object n) {
|
public void setNbObjects(Object n) {
|
||||||
|
echo(">>> StdObservedObject.setNbObjects: " + n);
|
||||||
count = n;
|
count = n;
|
||||||
}
|
}
|
||||||
private Object count= null;
|
private volatile Object count= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MBean interface
|
// MBean interface
|
||||||
@ -166,18 +174,18 @@ public class CounterMonitorTest implements NotificationListener {
|
|||||||
Attribute attrib = new Attribute("NbObjects", data);
|
Attribute attrib = new Attribute("NbObjects", data);
|
||||||
server.setAttribute(stdObsObjName, attrib);
|
server.setAttribute(stdObsObjName, attrib);
|
||||||
|
|
||||||
// Wait for granularity period (multiplied by 2 for sure)
|
waitObservation(data);
|
||||||
//
|
|
||||||
Thread.sleep(granularityperiod * 2);
|
|
||||||
|
|
||||||
// Loop through the values
|
// Loop through the values
|
||||||
//
|
//
|
||||||
for (int i = 0; i < values.length; i++) {
|
while (derivedGauge++ < 10) {
|
||||||
data = new Integer(values[i]);
|
System.out.print(">>> Set data from " + data.intValue());
|
||||||
echo(">>> Set data = " + data.intValue());
|
data = new Integer(data.intValue() + derivedGauge);
|
||||||
|
echo(" to " + data.intValue());
|
||||||
|
|
||||||
attrib = new Attribute("NbObjects", data);
|
attrib = new Attribute("NbObjects", data);
|
||||||
server.setAttribute(stdObsObjName, attrib);
|
server.setAttribute(stdObsObjName, attrib);
|
||||||
|
waitObservation(data);
|
||||||
|
|
||||||
echo("\tdoWait in Counter Monitor");
|
echo("\tdoWait in Counter Monitor");
|
||||||
doWait();
|
doWait();
|
||||||
@ -214,6 +222,20 @@ public class CounterMonitorTest implements NotificationListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void waitObservation(Object value) {
|
||||||
|
synchronized (CounterMonitorTest.class) {
|
||||||
|
while (value != observedValue) {
|
||||||
|
try {
|
||||||
|
CounterMonitorTest.class.wait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
System.err.println("Got unexpected exception: " + e);
|
||||||
|
e.printStackTrace();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print message
|
* Print message
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user