try
{
// Inside the thresholds, be sure low notification
sleep(period * 3);
assertEquals(times.get(), 1);
MonitorNotification notification = (MonitorNotification)holder.get();
assertEquals(notification.getType(), MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED);
times.set(0);
holder.set(null);
sleep(period * 3);
assertEquals(times.get(), 0);
// Monitoring takes time, so I disable low notification to be sure to get only the high one
// The monitor is in difference mode, so the first time will get the high notification, but
// the second time will get zero, since the gauge did not change, which will triggers a low notification
monitor.setNotifyLow(false);
// Set gauge above high threshold
value = value + high.intValue() + 1;
target.setInteger(value);
sleep(period * 3);
assertEquals(times.get(), 1);
notification = (MonitorNotification)holder.get();
assertEquals(notification.getType(), MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);
times.set(0);
holder.set(null);
sleep(period * 3);
assertEquals(times.get(), 0);
monitor.setNotifyHigh(false);
monitor.setNotifyLow(true);
// Set gauge above high threshold, so just after goes below low threshold
value = value + high.intValue() + 1;
target.setInteger(value);
sleep(period * 3);
assertEquals(times.get(), 1);
notification = (MonitorNotification)holder.get();
assertEquals(notification.getType(), MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED);
times.set(0);
holder.set(null);
sleep(period * 3);
assertEquals(times.get(), 0);