@Test
public void testExecuteScheduledAlerts_OnCooldown() {

    ServiceFactory sFactory = system.getServiceFactory();
    UserService userService = sFactory.getUserService();
    final AtomicInteger notificationCount = new AtomicInteger(0);
    final AtomicInteger clearCount = new AtomicInteger(0);
    Metric metric = new Metric("scope", "metric");
    Map<Long, String> dps = new HashMap<Long, String>();
    dps.put(1000L, "11");
    dps.put(2000L, "21");
    dps.put(3000L, "31");
    metric.setDatapoints(_convertDatapoints(dps));
    Alert alert = new Alert(userService.findAdminUser(), userService.findAdminUser(), "testAlert", "-1h:scope:metric:avg", "* * * * *");
    _setAlertId(alert, "100001");
    Trigger trigger = new Trigger(alert, TriggerType.GREATER_THAN_OR_EQ, "testTrigger", 10, 0);
    _setTriggerId(trigger, "100002");
    Notification notification = new Notification("testNotification", alert, AuditNotifier.class.getName(), new ArrayList<String>(),
            600000);
    _setNotificationId(notification, "100003");
    alert.setTriggers(Arrays.asList(new Trigger[] { trigger }));
    alert.setNotifications(Arrays.asList(new Notification[] { notification }));
    notification.setTriggers(alert.getTriggers());
    alert.setEnabled(true);
    DefaultAlertService spyAlertService = _initializeSpyAlertServiceWithStubs(notificationCount, clearCount,
            Arrays.asList(metric), alert, notification, false);
    //This will set the notification on cooldown for the given metric and trigger.
    assertEquals(new Integer(1), spyAlertService.executeScheduledAlerts(1, 1000));
    //This evaluation should not send notification. Hence notificationCount count would still be 1.
    assertEquals(new Integer(1), spyAlertService.executeScheduledAlerts(1, 1000));
    assertEquals(1, notificationCount.get());
    assertEquals(1, notification.getCooldownExpirationMap().size());
}