AlertPolicyManager { public EmailReceiverModel queryEmailReceivers(AlertEntity alert) { return emailReceiver.receivers(alert); }  @PostConstruct void initPolicies(); List<AlertChannel> queryChannels(AlertEntity alert); long queryRecoverMilli(AlertEntity alert); long querySuspendMilli(AlertEntity alert); EmailReceiverModel queryEmailReceivers(AlertEntity alert); void markCheckInterval(ALERT_TYPE alertType, LongSupplier checkInterval); Map<EmailReceiverModel, Map<ALERT_TYPE, Set<AlertEntity>>> queryGroupedEmailReceivers(
            AlertEntityHolderManager alerts);  }
@Test public void queryRecepients() throws Exception { alert = new AlertEntity(new HostPort("192.168.1.10", 6379), dcNames[0], "clusterId", "shardId", "test message", ALERT_TYPE.QUORUM_DOWN_FAIL); EmailReceiverModel receivers = policyManager.queryEmailReceivers(alert); EmailReceiverModel expect = new EmailReceiverModel(Lists.newArrayList(consoleConfig.getXPipeAdminEmails()), null); Assert.assertEquals(expect, receivers); configService.stopAlertSystem(new ConfigModel(), 1); alert = new AlertEntity(new HostPort("192.168.1.10", 6379), dcNames[0], "clusterId", "shardId", "test message", ALERT_TYPE.MARK_INSTANCE_UP); EmailReceiverModel receivers2 = policyManager.queryEmailReceivers(alert); EmailReceiverModel expect2 = new EmailReceiverModel(Lists.newArrayList(consoleConfig.getXPipeAdminEmails()), null); Assert.assertEquals(expect2, receivers2); configService.stopAlertSystem(new ConfigModel(), 1); alert = new AlertEntity(new HostPort("192.168.1.10", 6379), dcNames[0], "clusterId", "shardId", "test message", ALERT_TYPE.CLIENT_INCONSIS); EmailReceiverModel receivers3 = policyManager.queryEmailReceivers(alert); EmailReceiverModel expect3 = new EmailReceiverModel(Lists.newArrayList(consoleConfig.getXPipeAdminEmails()), null); Assert.assertEquals(expect3, receivers3); configService.stopAlertSystem(new ConfigModel(), 1); alert = new AlertEntity(new HostPort("192.168.1.10", 6379), dcNames[0], "clusterId", "shardId", "test message", ALERT_TYPE.ALERT_SYSTEM_OFF); EmailReceiverModel receivers4 = policyManager.queryEmailReceivers(alert); List<String> expectedReceivers = Lists.newArrayList(consoleConfig.getDBAEmails(), consoleConfig.getXPipeAdminEmails()); EmailReceiverModel expect4 = new EmailReceiverModel(expectedReceivers, null); Collections.sort(expect4.getRecipients()); Collections.sort(receivers4.getRecipients()); Assert.assertEquals(expect4, receivers4); }
@Test public void testEmptyQueryRecipients() throws Exception { configService.stopAlertSystem(new ConfigModel(), 1); alert.setAlertType(ALERT_TYPE.MARK_INSTANCE_UP); EmailReceiverModel result = policyManager.queryEmailReceivers(alert); logger.info("[recipients] {}", result); Assert.assertFalse(result.getRecipients().isEmpty()); alert.setAlertType(ALERT_TYPE.ALERT_SYSTEM_OFF); result = policyManager.queryEmailReceivers(alert); logger.info("[recipients] {}", result); Assert.assertFalse(result.getRecipients().isEmpty()); alert.setAlertType(ALERT_TYPE.SENTINEL_MONITOR_REDUNDANT_REDIS); result = policyManager.queryEmailReceivers(alert); logger.info("[recipients] {}", result); Assert.assertFalse(result.getRecipients().isEmpty()); alert.setAlertType(ALERT_TYPE.CLIENT_INCONSIS); result = policyManager.queryEmailReceivers(alert); logger.info("[recipients] {}", result); Assert.assertFalse(result.getRecipients().isEmpty()); }