use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.
the class RoleCommandTest method testSlave.
@Test
public void testSlave() throws Exception {
for (MASTER_STATE masterState : MASTER_STATE.values()) {
Server slave = startServer("*5\r\n" + "$5\r\nslave\r\n" + "$9\r\nlocalhost\r\n" + ":6379\r\n" + "$" + masterState.getDesc().length() + "\r\n" + masterState.getDesc() + "\r\n" + ":477\r\n");
RoleCommand roleCommand = new RoleCommand(getXpipeNettyClientKeyedObjectPool().getKeyPool(localhostInetAddress(slave.getPort())), 2000, false, scheduled);
SlaveRole role = (SlaveRole) roleCommand.execute().get();
Assert.assertEquals(SERVER_ROLE.SLAVE, role.getServerRole());
Assert.assertEquals("localhost", role.getMasterHost());
Assert.assertEquals(6379, role.getMasterPort());
Assert.assertEquals(masterState, role.getMasterState());
Assert.assertEquals(477, role.getMasterOffset());
}
}
use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.
the class RoleCommandTest method test.
@Test
public void test() throws Exception {
SlaveRole role = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0L);
Server server = startServer(ByteBufUtils.readToString(role.format()));
RoleCommand roleCommand = new RoleCommand("localhost", server.getPort(), scheduled);
Role real = roleCommand.execute().get();
logger.info("[test]{}", real);
Assert.assertEquals(role, real);
}
use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.
the class PrimaryDcKeeperMasterChooserAlgorithmTest method testLongConnection.
@Test
public void testLongConnection() throws Exception {
SlaveRole role = new SlaveRole(SERVER_ROLE.MASTER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0L);
RedisMeta chosen = redises.get(0);
Server server = startServer(chosen.getPort(), ByteBufUtils.readToString(role.format()));
Assert.assertEquals(0, server.getConnected());
for (int i = 0; i < 10; i++) {
primaryAlgorithm.choose();
Assert.assertEquals(1, server.getConnected());
}
}
use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.
the class AddKeeperCommandTest method testFailThenSuccess.
@Test
public void testFailThenSuccess() throws Exception {
startServer(keeperPort, new Callable<String>() {
long startTime = System.currentTimeMillis();
@Override
public String call() throws Exception {
SlaveRole slaveRole = null;
if (System.currentTimeMillis() - startTime <= timeoutMilli / 2) {
slaveRole = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0);
} else {
slaveRole = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECTED, 0);
}
return ByteBufUtils.readToString(slaveRole.format());
}
});
SlaveRole keeperRole = addKeeperCommand.execute().get();
Assert.assertEquals(MASTER_STATE.REDIS_REPL_CONNECTED, keeperRole.getMasterState());
}
Aggregations