@Test
public void testExecuteScheduledAlerts_Scenario1() {

    UserService userService = system.getServiceFactory().getUserService();
    final AtomicInteger notificationCount = new AtomicInteger(0);
    final AtomicInteger clearCount = new AtomicInteger(0);
    Metric metric1 = new Metric("scope1", "metric");
    Map<Long, String> dps1 = new HashMap<Long, String>();
    dps1.put(1000L, "11");
    dps1.put(2000L, "20");
    dps1.put(3000L, "30");
    metric1.setDatapoints(_convertDatapoints(dps1));
    Metric metric2 = new Metric("scope2", "metric");
    Map<Long, String> dps2 = new HashMap<Long, String>();
    dps2.put(4000L, "1");
    dps2.put(5000L, "2");
    dps2.put(6000L, "3");
    metric2.setDatapoints(_convertDatapoints(dps2));
    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>(), 300000);
    _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(metric1, metric2), alert, notification, false);
    assertEquals(new Integer(1), spyAlertService.executeScheduledAlerts(10, 1000));
    assertEquals(1, notificationCount.get());
    assertEquals(1, notification.getCooldownExpirationMap().size());
    assertEquals(1, notification.getActiveStatusMap().size());
    notificationCount.set(0);
    clearCount.set(0);
    metric1 = new Metric("scope1", "metric");
    dps1 = new HashMap<Long, String>();
    dps1.put(1000L, "1");
    dps1.put(2000L, "2");
    dps1.put(3000L, "3");
    metric1.setDatapoints(_convertDatapoints(dps1));
    metric2 = new Metric("scope2", "metric");
    dps2 = new HashMap<Long, String>();
    dps2.put(4000L, "11");
    dps2.put(5000L, "21");
    dps2.put(6000L, "31");
    metric2.setDatapoints(_convertDatapoints(dps2));
    spyAlertService = _initializeSpyAlertServiceWithStubs(notificationCount, clearCount, Arrays.asList(metric1, metric2),
            alert, notification, false);
    assertEquals(new Integer(1), spyAlertService.executeScheduledAlerts(10, 1000));
    assertEquals(1, notificationCount.get());
    assertEquals(1, clearCount.get());
    assertEquals(2, notification.getCooldownExpirationMap().size());
    assertEquals(1, _getActiveSize(notification.getActiveStatusMap()));
}