@@ -79,7 +79,7 @@ public class ResourceAlertManagerImpl extends ManagerBase implements ResourceAle
7979 @ Inject ConfigurationDao configDao ;
8080
8181 private ScheduledExecutorService executor ;
82- private final ExecutorService emailExecutor = Executors .newCachedThreadPool (r -> {
82+ ExecutorService emailExecutor = Executors .newCachedThreadPool (r -> {
8383 Thread t = new Thread (r , "ResourceAlertEmailSender" );
8484 t .setDaemon (true );
8585 return t ;
@@ -274,11 +274,7 @@ private void fireAlert(ResourceAlertRuleVO rule, Long resourceId, double value)
274274 String subject = buildSubject (rule , resourceId , value );
275275 String body = buildBody (rule , resourceId , value );
276276 long dcId = getDataCenterId (rule .getResourceType (), resourceId );
277- try {
278- AlertGenerator .publishAlertOnEventBus ("RESOURCE.ALERT" , dcId , null , subject , body );
279- } catch (Exception e ) {
280- logger .warn ("Failed to publish resource alert event: {}" , e .getMessage ());
281- }
277+ publishAlertEvent (dcId , subject , body );
282278
283279 if (rule .isEmail ()) {
284280 sendEmail (subject , body );
@@ -359,6 +355,15 @@ private void sendEmail(String subject, String body) {
359355 emailExecutor .execute (() -> mailSender .sendMail (mailProps ));
360356 }
361357
358+ // package-private so tests can stub it without needing a Spring context
359+ void publishAlertEvent (long dcId , String subject , String body ) {
360+ try {
361+ AlertGenerator .publishAlertOnEventBus ("RESOURCE.ALERT" , dcId , null , subject , body );
362+ } catch (Exception e ) {
363+ logger .warn ("Failed to publish resource alert event: {}" , e .getMessage ());
364+ }
365+ }
366+
362367 @ Override
363368 public String getConfigComponentName () {
364369 return ResourceAlertManagerImpl .class .getSimpleName ();
0 commit comments