mx4j/src/test/test/javax/management/monitor CounterMonitorTest.java,1.11,1.12
Simone Bordet <[email protected]> Sun, 15 May 2005 20:17:15 +0000
| Newsgroups | gmane.comp.java.mx4j.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/mx4j/mx4j/src/test/test/javax/management/monitor
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26534/src/test/test/javax/management/monitor
Modified Files:
CounterMonitorTest.java
Log Message:
Added test to check that the monitor thread started by the TimeQueue is shut down when all monitors are stopped
Index: CounterMonitorTest.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/test/test/javax/management/monitor/CounterMonitorTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** CounterMonitorTest.java 13 Feb 2005 17:17:58 -0000 1.11
--- CounterMonitorTest.java 15 May 2005 20:17:12 -0000 1.12
***************
*** 288,291 ****
--- 288,340 ----
}
+ public void testShutDownMonitorThread() throws Exception
+ {
+ MBeanServer server = newMBeanServer();
+ CounterMonitor monitor = (CounterMonitor)createMonitor();
+ server.registerMBean(monitor, ObjectName.getInstance(":service=monitor"));
+
+ Counter counter = new Counter();
+ ObjectName counterName = ObjectName.getInstance(":mbean=counter");
+ server.registerMBean(counter, counterName);
+
+ long period = 1000;
+ monitor.addObservedObject(counterName);
+ monitor.setGranularityPeriod(period);
+ monitor.setObservedAttribute("IntegerCounter");
+ Integer initThreshold = new Integer(3);
+ monitor.setInitThreshold(initThreshold);
+ monitor.setNotify(true);
+ // No modulus, no offset
+
+ counter.setIntegerCounter(initThreshold.intValue() - 1);
+
+ final MutableObject monitorThread = new MutableObject(null);
+ monitor.addNotificationListener(new NotificationListener()
+ {
+ public void handleNotification(Notification notification, Object handback)
+ {
+ monitorThread.set(Thread.currentThread());
+ }
+ }, null, null);
+ monitor.start();
+
+ // Below threshold, no notifications should be sent
+ sleep(period * 3);
+
+ // Above threshold, just one notification should be sent
+ counter.setIntegerCounter(initThreshold.intValue() + 1);
+ sleep(period * 3);
+
+ Thread thread = (Thread)monitorThread.get();
+ assertNotNull(thread);
+ assertNotSame(thread, Thread.currentThread());
+
+ monitor.stop();
+
+ sleep(period * 3);
+
+ assertFalse(thread.isAlive());
+ }
+
public interface CounterMBean
{
-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click