IspnAlertsServiceImpl implements AlertsService { @Override public void addAlerts(Collection<Alert> alerts) throws Exception { if (alerts == null) { throw new IllegalArgumentException("Alerts must be not null"); } if (alerts.isEmpty()) { return; } log.debugf("Adding %s alerts", alerts.size()); for (Alert alert : alerts) { backend.put(pk(alert), new IspnEvent(alert)); } }  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 addAlerts() throws Exception { int numTenants = 2; int numTriggers = 5; int numAlerts = 100; createTestAlerts(numTenants, numTriggers, numAlerts); Set<String> tenantIds = new HashSet<>(); tenantIds.add("tenant0"); tenantIds.add("tenant1"); assertEquals(2 * 5 * 100, alerts.getAlerts(tenantIds, null, null).size()); tenantIds.remove("tenant0"); assertEquals(1 * 5 * 100, alerts.getAlerts(tenantIds, null, null).size()); List<Alert> testAlerts = alerts.getAlerts(tenantIds, null, null); tenantIds.clear(); Set<String> alertIds = new HashSet<>(); for (int i = 0; i < 3; i++) { Alert alertX = testAlerts.get(i); tenantIds.add(alertX.getTenantId()); alertIds.add(alertX.getAlertId()); } AlertsCriteria criteria = new AlertsCriteria(); criteria.setAlertIds(alertIds); assertEquals(3, alerts.getAlerts(tenantIds, criteria, null).size()); deleteTestAlerts(numTenants); }