Search in sources :

Example 61 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class DefaultDelayMonitor method sampleDelay.

private void sampleDelay(final DelaySamplePlan samplePlan) {
    if (samplePlan.getHostPort2SampleResult().isEmpty()) {
        return;
    }
    for (final HostPort hostPort : samplePlan.getHostPort2SampleResult().keySet()) {
        RedisSession session = findRedisSession(hostPort.getHost(), hostPort.getPort());
        session.subscribeIfAbsent(CHECK_CHANNEL, new RedisSession.SubscribeCallback() {

            @Override
            public void message(String channel, String message) {
                log.debug("[sampleDelay][message]{}, {}", hostPort, message);
                addInstanceSuccess(Long.parseLong(message, 16), hostPort.getHost(), hostPort.getPort(), null);
            }

            @Override
            public void fail(Throwable e) {
            // nothing to do
            }
        });
    }
    RedisSession masterSession = null;
    if (samplePlan.getMasterHost() != null) {
        masterSession = findRedisSession(samplePlan.getMasterHost(), samplePlan.getMasterPort());
    }
    long startNanoTime = recordSample(samplePlan);
    log.debug("[sampleDelay][publish]{}:{}", samplePlan.getMasterHost(), samplePlan.getMasterPort());
    if (masterSession != null) {
        masterSession.publish(CHECK_CHANNEL, Long.toHexString(startNanoTime));
    }
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort)

Example 62 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class SentinelCommandTest method testSentinelMaster.

@Test
public void testSentinelMaster() throws InterruptedException, ExecutionException {
    try {
        String addResult = new SentinelAdd(clientPool, masterName, "127.0.0.1", 6379, 3, scheduled).execute().get();
        logger.info("{}", addResult);
    } catch (Exception ignore) {
    }
    try {
        HostPort master = new AbstractSentinelCommand.SentinelMaster(clientPool, scheduled, masterName).execute().get();
        logger.info("[master]{}", master);
        Assert.assertEquals("127.0.0.1", master.getHost());
        Assert.assertEquals(6379, master.getPort());
    } catch (Exception e) {
        logger.error("[testSentinelMaster]", e);
    }
    try {
        new SentinelRemove(clientPool, masterName, scheduled).execute().get();
    } catch (Exception e) {
        logger.error("[testRemove]", e);
    }
}
Also used : SentinelRemove(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelRemove) HostPort(com.ctrip.xpipe.endpoint.HostPort) SentinelAdd(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelAdd) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 63 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class DefaultSentinelManagerTest method testAdd.

@Test
public void testAdd() {
    sentinelManager.addSentinel(getClusterId(), getShardId(), new HostPort(redisMaster.getIp(), redisMaster.getPort()), executionLog);
    logger.info("{}", executionLog.getLog());
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 64 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class DefaultOffsetwaiterTest method testWaitTimeout.

@Test
public void testWaitTimeout() throws Exception {
    String masterReplId = RunidGenerator.DEFAULT.generateRunid();
    Long masterOffset = 10000L;
    MasterInfo masterInfo = new MasterInfo(masterReplId, masterOffset);
    startServer(port, new Callable<String>() {

        private Long offset = masterOffset - 200;

        @Override
        public String call() throws Exception {
            return toRedisProtocalString("# Replication\r\n" + "role:slave\r\n" + "master_host:127.0.0.1\r\n" + "master_port:6379\r\n" + "master_link_status:up\r\n" + "master_last_io_seconds_ago:8\r\n" + "master_sync_in_progress:0\r\n" + "slave_repl_offset:" + offset + "\r\n" + "slave_priority:100\r\n" + "slave_read_only:1\r\n" + "connected_slaves:0\r\n" + "master_replid:" + masterReplId + "\r\n" + "master_replid2:0000000000000000000000000000000000000000\r\n" + "master_repl_offset:" + offset + "\r\n" + "second_repl_offset:-1\r\n" + "repl_backlog_active:1\r\n" + "repl_backlog_size:1048576\r\n" + "repl_backlog_first_byte_offset:1\r\n" + "repl_backlog_histlen:13202");
        }
    });
    Assert.assertFalse(offsetwaiter.tryWaitfor(new HostPort(host, port), masterInfo, executionLog));
}
Also used : MasterInfo(com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo) HostPort(com.ctrip.xpipe.endpoint.HostPort) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 65 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class DefaultOffsetwaiterTest method testWaitAndSucceed2_8_19.

@Test
public void testWaitAndSucceed2_8_19() throws Exception {
    String masterReplId = RunidGenerator.DEFAULT.generateRunid();
    Long masterOffset = 10000L;
    MasterInfo masterInfo = new MasterInfo(masterReplId, masterOffset);
    startServer(port, new Callable<String>() {

        private Long offset = masterOffset - 200;

        @Override
        public String call() throws Exception {
            offset += 100;
            return toRedisProtocalString("# Replication\r\n" + "role:slave\r\n" + "master_host:127.0.0.1\r\n" + "master_port:6379\r\n" + "master_link_status:up\r\n" + "master_last_io_seconds_ago:1\r\n" + "master_sync_in_progress:0\r\n" + "slave_repl_offset:" + offset + "\r\n" + "slave_priority:100\r\n" + "slave_read_only:1\r\n" + "connected_slaves:0\r\n" + "master_repl_offset:0\r\n" + "repl_backlog_active:0\r\n" + "repl_backlog_size:104857600\r\n" + "repl_backlog_first_byte_offset:0\r\n" + "repl_backlog_histlen:0");
        }
    });
    Assert.assertTrue(offsetwaiter.tryWaitfor(new HostPort(host, port), masterInfo, executionLog));
}
Also used : MasterInfo(com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo) HostPort(com.ctrip.xpipe.endpoint.HostPort) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Aggregations

HostPort (com.ctrip.xpipe.endpoint.HostPort)79 Test (org.junit.Test)31 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)7 LinkedList (java.util.LinkedList)7 ALERT_TYPE (com.ctrip.xpipe.redis.console.alert.ALERT_TYPE)6 MasterInfo (com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo)6 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)6 ClusterShardHostPort (com.ctrip.xpipe.endpoint.ClusterShardHostPort)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5 RedisConf (com.ctrip.xpipe.redis.console.health.redisconf.RedisConf)4 MasterNotFoundException (com.ctrip.xpipe.redis.console.resources.MasterNotFoundException)4 XpipeMetaManager (com.ctrip.xpipe.redis.core.meta.XpipeMetaManager)4 Set (java.util.Set)4 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)3 AlertEntity (com.ctrip.xpipe.redis.console.alert.AlertEntity)3 AlertManager (com.ctrip.xpipe.redis.console.alert.AlertManager)3 DefaultRedisSessionManager (com.ctrip.xpipe.redis.console.health.DefaultRedisSessionManager)3 ClusterListClusterModel (com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel)3