// No modulus
counter.setIntegerCounter(initThreshold.intValue() - 1);
final MutableInteger times = new MutableInteger(0);
final MutableObject holder = new MutableObject(null);
monitor.addNotificationListener(new NotificationListener()
{
public void handleNotification(Notification notification, Object handback)
{
times.set(times.get() + 1);
holder.set(notification);
}
}, null, null);
monitor.start();
try
{
// Below threshold, no notifications should be sent
sleep(period * 3);
assertEquals(times.get(), 0);
assertNull(holder.get());
// Above threshold, just one notification should be sent
counter.setIntegerCounter(initThreshold.intValue() + 1);
sleep(period * 3);
assertEquals(times.get(), 1);
MonitorNotification notification = (MonitorNotification)holder.get();
assertEquals(notification.getType(), MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
// The threshold should have offset
Number threshold = monitor.getThreshold(counterName);
assertEquals(threshold.intValue(), monitor.getInitThreshold().intValue() + offset.intValue());
times.set(0);
holder.set(null);
sleep(period * 3);
assertEquals(times.get(), 0);
// Above threshold by more than 1 offset
counter.setIntegerCounter(initThreshold.intValue() + offset.intValue() * 2 + 1);
sleep(period * 3);
assertEquals(times.get(), 1);
notification = (MonitorNotification)holder.get();
assertEquals(notification.getType(), MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
// The threshold should have offset correctly
threshold = monitor.getThreshold(counterName);
assertEquals(threshold.intValue(), monitor.getInitThreshold().intValue() + offset.intValue() * 3);
times.set(0);
holder.set(null);
sleep(period * 3);
assertEquals(times.get(), 0);
}
finally
{