Search in sources :

Example 6 with AlertEntity

use of com.ctrip.xpipe.redis.console.alert.AlertEntity in project x-pipe by ctripcorp.

the class SenderManagerTest method testSenderManager.

@Test
public void testSenderManager() {
    HostPort hostPort = new HostPort("192.168.1.10", 6379);
    Map<ALERT_TYPE, Set<AlertEntity>> alerts = new ConcurrentHashMap<>();
    AlertEntity alert = new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.XREDIS_VERSION_NOT_VALID);
    Set<AlertEntity> set = new ConcurrentSet<>();
    set.add(alert);
    alerts.put(ALERT_TYPE.XREDIS_VERSION_NOT_VALID, set);
    new Thread(new Runnable() {

        @Override
        public void run() {
            alerts.get(ALERT_TYPE.XREDIS_VERSION_NOT_VALID).remove(alert);
        }
    }).start();
    List<Map<ALERT_TYPE, Set<AlertEntity>>> result = senderManager.getGroupedAlerts(alerts);
    logger.info("result: {}", result.get(0));
    if (!result.isEmpty()) {
        Set<AlertEntity> alertEntities = result.get(0).getOrDefault(alert.getAlertType(), null);
        if (alertEntities != null) {
            Assert.assertFalse(alertEntities.isEmpty());
        }
    }
}
Also used : ConcurrentSet(io.netty.util.internal.ConcurrentSet) ConcurrentSet(io.netty.util.internal.ConcurrentSet) HostPort(com.ctrip.xpipe.endpoint.HostPort) AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ALERT_TYPE(com.ctrip.xpipe.redis.console.alert.ALERT_TYPE) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 7 with AlertEntity

use of com.ctrip.xpipe.redis.console.alert.AlertEntity in project x-pipe by ctripcorp.

the class ScheduledAlertMessageDecoratorTest method generateBody.

@Test
public void generateBody() throws Exception {
    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)));
    String body = decorator.generateBody(alerts);
    logger.info("{}", body);
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) HostPort(com.ctrip.xpipe.endpoint.HostPort) AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity) ALERT_TYPE(com.ctrip.xpipe.redis.console.alert.ALERT_TYPE) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 8 with AlertEntity

use of com.ctrip.xpipe.redis.console.alert.AlertEntity in project x-pipe by ctripcorp.

the class NotificationManager method addAlert.

public void addAlert(String dc, String cluster, String shard, HostPort hostPort, ALERT_TYPE type, String message) {
    AlertEntity alert = new AlertEntity(hostPort, dc, cluster, shard, message, type);
    logger.debug("[addAlert] Add Alert Entity: {}", alert);
    alerts.offer(alert);
}
Also used : AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity)

Example 9 with AlertEntity

use of com.ctrip.xpipe.redis.console.alert.AlertEntity in project x-pipe by ctripcorp.

the class AlertPolicyManagerTest method queryRecepients.

@Test
public void queryRecepients() throws Exception {
    AlertPolicy policy = policyManager.alertPolicyMap.get(SendToDBAAlertPolicy.ID);
    List<String> expected = policy.queryRecipients(new AlertEntity(null, null, null, null, null, ALERT_TYPE.MARK_INSTANCE_UP));
    logger.info("[testQueryRecepients] emails: {}", expected);
    Assert.assertEquals(expected, policyManager.queryRecepients(alert));
}
Also used : AlertPolicy(com.ctrip.xpipe.redis.console.alert.policy.AlertPolicy) SendToDBAAlertPolicy(com.ctrip.xpipe.redis.console.alert.policy.SendToDBAAlertPolicy) AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 10 with AlertEntity

use of com.ctrip.xpipe.redis.console.alert.AlertEntity in project x-pipe by ctripcorp.

the class NotificationManagerTest method send.

@Test
@DirtiesContext
public void send() throws Exception {
    AlertEntity alert = new AlertEntity(hostPort, dcNames[0], cluster, shard, message, ALERT_TYPE.CLIENT_INCONSIS);
    Assert.assertTrue(notificationManager.send(alert));
    notificationManager.addAlert(dcNames[0], cluster, shard, hostPort, ALERT_TYPE.CLIENT_INCONSIS, message);
    Assert.assertFalse(notificationManager.send(alert));
}
Also used : AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Aggregations

AlertEntity (com.ctrip.xpipe.redis.console.alert.AlertEntity)10 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)8 Test (org.junit.Test)8 ALERT_TYPE (com.ctrip.xpipe.redis.console.alert.ALERT_TYPE)5 HostPort (com.ctrip.xpipe.endpoint.HostPort)3 DirtiesContext (org.springframework.test.annotation.DirtiesContext)3 ConcurrentSet (io.netty.util.internal.ConcurrentSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AlertPolicy (com.ctrip.xpipe.redis.console.alert.policy.AlertPolicy)1 SendToDBAAlertPolicy (com.ctrip.xpipe.redis.console.alert.policy.SendToDBAAlertPolicy)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1