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));
}
}
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);
}
}
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());
}
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));
}
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));
}
Aggregations