DefaultGroupEmailReceiver extends AbstractEmailReceiver implements GroupEmailReceiver { @Override public Map<EmailReceiverModel, Map<ALERT_TYPE, Set<AlertEntity>>> getGroupedEmailReceiver(AlertEntityHolderManager alerts) { Map<EmailReceiverModel, Map<ALERT_TYPE, Set<AlertEntity>>> result = Maps.newHashMap(); if(!isAlertSystemOn()) { EmailReceiverModel receivers = new EmailReceiverModel(getXPipeAdminEmails(), null); result.put(receivers, Maps.newHashMap(alerts.convertToMap())); return result; } EmailReceiverModel dbaAsReceivers = new EmailReceiverModel(getDbaEmails(), getXPipeAdminEmails()); EmailReceiverModel xpipeAdminAsReceivers = new EmailReceiverModel(getXPipeAdminEmails(), null); result.put(dbaAsReceivers, dbaAsReceiverAlerts(alerts.convertToMap())); result.put(xpipeAdminAsReceivers, xpipeAdminAsReceiverAlerts(alerts.convertToMap())); return result; } DefaultGroupEmailReceiver(ConsoleConfig consoleConfig, ConfigService configService, ClusterService clusterService); @Override Map<EmailReceiverModel, Map<ALERT_TYPE, Set<AlertEntity>>> getGroupedEmailReceiver(AlertEntityHolderManager alerts); @Override EmailReceiverModel receivers(AlertEntity alert);  }
@Test public void getGroupedEmailReceiver() throws DalException { HostPort hostPort = new HostPort("192.168.1.10", 6379); Map<ALERT_TYPE, Set<AlertEntity>> alerts = new HashMap<>(); alerts.put(ALERT_TYPE.CLIENT_INCONSIS, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.CLIENT_INCONSIS ))); alerts.put(ALERT_TYPE.XREDIS_VERSION_NOT_VALID, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.XREDIS_VERSION_NOT_VALID ))); alerts.put(ALERT_TYPE.QUORUM_DOWN_FAIL, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.QUORUM_DOWN_FAIL ))); alerts.put(ALERT_TYPE.SENTINEL_RESET, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.SENTINEL_RESET ))); alerts.put(ALERT_TYPE.REDIS_CONF_REWRITE_FAILURE, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.REDIS_CONF_REWRITE_FAILURE ))); alerts.put(ALERT_TYPE.REDIS_REPL_DISKLESS_SYNC_ERROR, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.REDIS_REPL_DISKLESS_SYNC_ERROR ))); alerts.put(ALERT_TYPE.MIGRATION_MANY_UNFINISHED, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.MIGRATION_MANY_UNFINISHED ))); Map<EmailReceiverModel, Map<ALERT_TYPE, Set<AlertEntity>>> expect = Maps.newHashMap(); Map<ALERT_TYPE, Set<AlertEntity>> dbaMap = Maps.newHashMap(); dbaMap.put(ALERT_TYPE.CLIENT_INCONSIS, alerts.get(ALERT_TYPE.CLIENT_INCONSIS)); dbaMap.put(ALERT_TYPE.XREDIS_VERSION_NOT_VALID, alerts.get(ALERT_TYPE.XREDIS_VERSION_NOT_VALID)); dbaMap.put(ALERT_TYPE.REDIS_CONF_REWRITE_FAILURE, alerts.get(ALERT_TYPE.REDIS_CONF_REWRITE_FAILURE)); dbaMap.put(ALERT_TYPE.REDIS_REPL_DISKLESS_SYNC_ERROR, alerts.get(ALERT_TYPE.REDIS_REPL_DISKLESS_SYNC_ERROR)); Map<ALERT_TYPE, Set<AlertEntity>> xpipeAdminMap = Maps.newHashMap(); xpipeAdminMap.put(ALERT_TYPE.QUORUM_DOWN_FAIL, alerts.get(ALERT_TYPE.QUORUM_DOWN_FAIL)); xpipeAdminMap.put(ALERT_TYPE.SENTINEL_RESET, alerts.get(ALERT_TYPE.SENTINEL_RESET)); xpipeAdminMap.put(ALERT_TYPE.MIGRATION_MANY_UNFINISHED, alerts.get(ALERT_TYPE.MIGRATION_MANY_UNFINISHED)); expect.put(new EmailReceiverModel(Lists.newArrayList(consoleConfig.getDBAEmails()), Lists.newArrayList(consoleConfig.getXPipeAdminEmails())), dbaMap); expect.put(new EmailReceiverModel(Lists.newArrayList(consoleConfig.getXPipeAdminEmails()), null), xpipeAdminMap); Assert.assertEquals(expect, groupEmailReceiver.getGroupedEmailReceiver(convertToHolderManager(alerts))); configService.stopAlertSystem(new ConfigModel(), 1); expect.clear(); expect.put(new EmailReceiverModel(Lists.newArrayList(consoleConfig.getXPipeAdminEmails()), null), alerts); Assert.assertEquals(expect, groupEmailReceiver.getGroupedEmailReceiver(convertToHolderManager(alerts))); }
@Test public void getGroupedEmailReceiver2() throws DalException { HostPort hostPort = new HostPort("192.168.1.10", 6379); Map<ALERT_TYPE, Set<AlertEntity>> alerts = new HashMap<>(); alerts.put(ALERT_TYPE.CLIENT_INCONSIS, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.CLIENT_INCONSIS ))); alerts.put(ALERT_TYPE.XREDIS_VERSION_NOT_VALID, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.XREDIS_VERSION_NOT_VALID ))); alerts.put(ALERT_TYPE.REDIS_CONF_REWRITE_FAILURE, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.REDIS_CONF_REWRITE_FAILURE ))); alerts.put(ALERT_TYPE.REDIS_REPL_DISKLESS_SYNC_ERROR, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.REDIS_REPL_DISKLESS_SYNC_ERROR ))); Map<EmailReceiverModel, Map<ALERT_TYPE, Set<AlertEntity>>> expect = Maps.newHashMap(); Map<ALERT_TYPE, Set<AlertEntity>> dbaMap = Maps.newHashMap(); dbaMap.put(ALERT_TYPE.CLIENT_INCONSIS, alerts.get(ALERT_TYPE.CLIENT_INCONSIS)); dbaMap.put(ALERT_TYPE.XREDIS_VERSION_NOT_VALID, alerts.get(ALERT_TYPE.XREDIS_VERSION_NOT_VALID)); dbaMap.put(ALERT_TYPE.REDIS_CONF_REWRITE_FAILURE, alerts.get(ALERT_TYPE.REDIS_CONF_REWRITE_FAILURE)); dbaMap.put(ALERT_TYPE.REDIS_REPL_DISKLESS_SYNC_ERROR, alerts.get(ALERT_TYPE.REDIS_REPL_DISKLESS_SYNC_ERROR)); Map<ALERT_TYPE, Set<AlertEntity>> emptyMap = Maps.newHashMap(); expect.put(new EmailReceiverModel(Lists.newArrayList(consoleConfig.getDBAEmails()), Lists.newArrayList(consoleConfig.getXPipeAdminEmails())), dbaMap); expect.put(new EmailReceiverModel(Lists.newArrayList(consoleConfig.getXPipeAdminEmails()), null), emptyMap); Assert.assertEquals(expect, groupEmailReceiver.getGroupedEmailReceiver(convertToHolderManager(alerts))); configService.stopAlertSystem(new ConfigModel(), 1); expect.clear(); expect.put(new EmailReceiverModel(Lists.newArrayList(consoleConfig.getXPipeAdminEmails()), null), alerts); Assert.assertEquals(expect, groupEmailReceiver.getGroupedEmailReceiver(convertToHolderManager(alerts))); }
@Test public void getGroupedEmailReceiver3() throws DalException { HostPort hostPort = new HostPort("192.168.1.10", 6379); Map<ALERT_TYPE, Set<AlertEntity>> alerts = new HashMap<>(); alerts.put(ALERT_TYPE.QUORUM_DOWN_FAIL, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.QUORUM_DOWN_FAIL ))); alerts.put(ALERT_TYPE.SENTINEL_RESET, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.SENTINEL_RESET ))); alerts.put(ALERT_TYPE.MIGRATION_MANY_UNFINISHED, Collections.singleton( new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.MIGRATION_MANY_UNFINISHED ))); Map<EmailReceiverModel, Map<ALERT_TYPE, Set<AlertEntity>>> expect = Maps.newHashMap(); Map<ALERT_TYPE, Set<AlertEntity>> emptyMap = Maps.newHashMap(); Map<ALERT_TYPE, Set<AlertEntity>> xpipeAdminMap = Maps.newHashMap(); xpipeAdminMap.put(ALERT_TYPE.QUORUM_DOWN_FAIL, alerts.get(ALERT_TYPE.QUORUM_DOWN_FAIL)); xpipeAdminMap.put(ALERT_TYPE.SENTINEL_RESET, alerts.get(ALERT_TYPE.SENTINEL_RESET)); xpipeAdminMap.put(ALERT_TYPE.MIGRATION_MANY_UNFINISHED, alerts.get(ALERT_TYPE.MIGRATION_MANY_UNFINISHED)); expect.put(new EmailReceiverModel(Lists.newArrayList(consoleConfig.getDBAEmails()), Lists.newArrayList(consoleConfig.getXPipeAdminEmails())), emptyMap); expect.put(new EmailReceiverModel(Lists.newArrayList(consoleConfig.getXPipeAdminEmails()), null), xpipeAdminMap); Assert.assertEquals(expect, groupEmailReceiver.getGroupedEmailReceiver(convertToHolderManager(alerts))); configService.stopAlertSystem(new ConfigModel(), 1); expect.clear(); expect.put(new EmailReceiverModel(Lists.newArrayList(consoleConfig.getXPipeAdminEmails()), null), alerts); Assert.assertEquals(expect, groupEmailReceiver.getGroupedEmailReceiver(convertToHolderManager(alerts))); }