IspnAlertsServiceImpl implements AlertsService { @Override public Page<Event> getEvents(String tenantId, EventsCriteria criteria, Pager pager) throws Exception { return getEvents(Collections.singleton(tenantId), criteria, pager); }  void init(); void setAlertsEngine(AlertsEngine alertsEngine); void setDefinitionsService(DefinitionsService definitionsService); void setActionsService(ActionsService actionsService); void setIncomingDataManager(IncomingDataManager incomingDataManager); void setProperties(PropertiesService properties); @Override void ackAlerts(String tenantId, Collection<String> alertIds, String ackBy, String ackNotes); @Override void addAlerts(Collection<Alert> alerts); @Override void addAlertTags(String tenantId, Collection<String> alertIds, Map<String, String> tags); @Override void addEvents(Collection<Event> events); @Override void addEventTags(String tenantId, Collection<String> eventIds, Map<String, String> tags); @Override void persistEvents(Collection<Event> events); @Override void addNote(String tenantId, String alertId, String user, String text); @Override int deleteAlerts(String tenantId, AlertsCriteria criteria); @Override int deleteEvents(String tenantId, EventsCriteria criteria); @Override Alert getAlert(String tenantId, String alertId, boolean thin); @Override Page<Alert> getAlerts(String tenantId, AlertsCriteria criteria, Pager pager); @Override Page<Alert> getAlerts(Set<String> tenantIds, AlertsCriteria criteria, Pager pager); @Override Event getEvent(String tenantId, String eventId, boolean thin); @Override Page<Event> getEvents(String tenantId, EventsCriteria criteria, Pager pager); @Override Page<Event> getEvents(Set<String> tenantIds, EventsCriteria criteria, Pager pager); @Override void removeAlertTags(String tenantId, Collection<String> alertIds, Collection<String> tags); @Override void removeEventTags(String tenantId, Collection<String> eventIds, Collection<String> tags); @Override void resolveAlerts(String tenantId, Collection<String> alertIds, String resolvedBy, String resolvedNotes, List<Set<ConditionEval>> resolvedEvalSets); @Override void resolveAlertsForTrigger(String tenantId, String triggerId, String resolvedBy, String resolvedNotes, List<Set<ConditionEval>> resolvedEvalSets); @Override void sendData(Collection<Data> data); @Override void sendData(Collection<Data> data, boolean ignoreFiltering); @Override void sendEvents(Collection<Event> events); @Override void sendEvents(Collection<Event> events, boolean ignoreFiltering);  }
@Test public void queryEventsByTriggerId() throws Exception { int numTenants = 2; int numTriggers = 5; int numEvents = 5; createTestEvents(numTenants, numTriggers, numEvents); Set<String> tenantIds = new HashSet<>(); tenantIds.add("tenant0"); tenantIds.add("tenant1"); EventsCriteria criteria = new EventsCriteria(); criteria.setTriggerId("trigger0"); List<Event> trigger0Events = alerts.getEvents(tenantIds, criteria, null); assertEquals(10, trigger0Events.size()); criteria.setTriggerIds(Arrays.asList("trigger0", "trigger1", "trigger2")); List<Event> trigger012Events = alerts.getEvents(tenantIds, criteria, null); assertEquals(30, trigger012Events.size()); deleteTestEvents(numTenants); }
@Test public void queryEventsByCTime() throws Exception { int numTenants = 1; int numTriggers = 5; int numEvents = 5; createTestEvents(numTenants, numTriggers, numEvents); Set<String> tenantIds = new HashSet<>(); tenantIds.add("tenant0"); EventsCriteria criteria = new EventsCriteria(); criteria.setStartTime(2L); criteria.setEndTime(2L); List<Event> ctime2Events = alerts.getEvents(tenantIds, criteria, null); assertEquals(5, ctime2Events.size()); criteria.setEndTime(null); List<Event> ctimeGTE2Events = alerts.getEvents(tenantIds, criteria, null); assertEquals(5 * 4, ctimeGTE2Events.size()); deleteTestEvents(numTenants); }
@Test public void queryEventsByCategory() throws Exception { int numTenants = 1; int numTriggers = 5; int numEvents = 5; createTestEvents(numTenants, numTriggers, numEvents); Set<String> tenantIds = new HashSet<>(); tenantIds.add("tenant0"); EventsCriteria criteria = new EventsCriteria(); criteria.setCategory("category0"); List<Event> category0Events = alerts.getEvents(tenantIds, criteria, null); assertEquals(15, category0Events.size()); criteria.setCategories(Arrays.asList("category0", "category1")); List<Event> category01Events = alerts.getEvents(tenantIds, criteria, null); assertEquals(5 * 5, category01Events.size()); deleteTestEvents(numTenants); }