use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class KeeperSingleDcWaitForOffset method testMakeBackupActive.
@Test
public void testMakeBackupActive() throws Exception {
RedisKeeperServer redisKeeperServer = getRedisKeeperServer(backupKeeper);
Assert.assertEquals(PARTIAL_STATE.FULL, redisKeeperServer.getRedisMaster().partialState());
logger.info(remarkableMessage("make keeper active to wrong addr{}"), backupKeeper);
String ip = "localhost";
int port = randomPort();
setKeeperState(backupKeeper, KeeperState.ACTIVE, ip, port);
sleep(2000);
// make sure redis has more log
sendMessageToMaster(redisMaster, 1);
xslaveof(backupKeeper.getIp(), backupKeeper.getPort(), getRedisSlaves());
sleep(2000);
setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
sleep(2000);
Set<RedisSlave> slaves = redisKeeperServer.slaves();
Assert.assertEquals(PARTIAL_STATE.PARTIAL, redisKeeperServer.getRedisMaster().partialState());
slaves.forEach(redisSlave -> Assert.assertEquals(PARTIAL_STATE.PARTIAL, redisSlave.partialState()));
Assert.assertEquals(slaves.size(), redisKeeperServer.getKeeperMonitor().getKeeperStats().getWaitOffsetSucceed());
Assert.assertEquals(0, redisKeeperServer.getKeeperMonitor().getKeeperStats().getWaitOffsetFail());
sendMessageToMasterAndTestSlaveRedis();
}
use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class OneKeeper method statePreActive.
@Test
public void statePreActive() throws IOException {
try {
sendMessageToMaster(redisMaster, 10);
RedisKeeperServer redisKeeperServer = getRedisKeeperServer(activeKeeper);
logger.info(remarkableMessage("[statePreActive][stop dispose]"));
redisKeeperServer.stop();
redisKeeperServer.dispose();
sleep(100);
logger.info(remarkableMessage("[statePreActive][initialize start]"));
redisKeeperServer.initialize();
redisKeeperServer.start();
} catch (Throwable e) {
logger.error("[startTest]", e);
}
waitForAnyKeyToExit();
}
use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class BadKeeperWrongCommands method giveWrongCommands.
@SuppressWarnings("unused")
@Test
public void giveWrongCommands() throws IOException {
String[] commands = createCommands();
RedisKeeperServer active = getRedisKeeperServer(activeKeeper);
RedisKeeperServer backup = getRedisKeeperServer(backupKeeper);
replicationStore = active.getReplicationStore();
Set<RedisSlave> slaves = active.slaves();
replicationStore.appendCommands(Unpooled.wrappedBuffer("*3\r\n$3\r\nset\r\n$1\r\na\r\n$5\r\n12 34\r\n\r\n".getBytes()));
logger.info(remarkableMessage("stop redis master"));
waitForAnyKey();
stopRedisMaster();
printSlaves(slaves);
logger.info(remarkableMessage("give part commands:" + commands[0].length()));
waitForAnyKey();
replicationStore.appendCommands(Unpooled.wrappedBuffer(commands[0].getBytes()));
logger.info(remarkableMessage("close client connection"));
waitForAnyKey();
for (RedisSlave slave : active.slaves()) {
slave.close();
}
System.out.println("give other commands");
waitForAnyKey();
for (int i = 1; i < commands.length; i++) {
replicationStore.appendCommands(Unpooled.wrappedBuffer(commands[i].getBytes()));
}
waitForAnyKeyToExit();
}
use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class AbstractIntegratedTestTemplate method failOverTestTemplate.
@SuppressWarnings("unused")
protected void failOverTestTemplate() throws Exception {
RedisMeta redisMaster = getRedisMaster();
stopServerListeningPort(redisMaster.getPort());
RedisKeeperServer redisKeeperServer = getRedisKeeperServerActive(activeDc().getId());
RedisMeta slave = getRedisSlaves(activeDc().getId()).get(0);
SERVER_ROLE role = getRedisServerRole(slave);
Assert.assertEquals(SERVER_ROLE.SLAVE, role);
logger.info(remarkableMessage("[testRedisFailover][promote]{}:{})"), slave.getIp(), slave.getPort());
String clusterId = redisMaster.parent().parent().getId();
String shardId = redisMaster.parent().getId();
DefaultMetaServer metaServer = getDcInfos().get(activeDc().getId()).getApplicationContext().getBean(DefaultMetaServer.class);
// metaServer.promoteRedisMaster(clusterId, shardId, slave.getIp(), slave.getPort());
sleep(6000);
role = getRedisServerRole(slave);
Assert.assertEquals(SERVER_ROLE.MASTER, role);
Assert.assertEquals(PARTIAL_STATE.PARTIAL, redisKeeperServer.getRedisMaster().partialState());
changeRedisMaster(redisMaster, slave);
sendMessageToMasterAndTestSlaveRedis();
}
use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class KeeperFailoverTest method testKeeperFailOver.
@Test
public void testKeeperFailOver() throws Exception {
RedisKeeperServer activeRedisKeeperServer = getRedisKeeperServerActive();
logger.info("[testKeeperFailOver][active]{}", activeRedisKeeperServer);
sleep(6000);
logger.info(remarkableMessage("[testKeeperFailOver][stop activeKeeper]"), activeRedisKeeperServer);
remove(activeRedisKeeperServer);
sleep(6000);
RedisKeeperServer activeNow = getRedisKeeperServerActive();
logger.info("[testKeeperFailOver][active new]{}", activeNow);
Assert.assertNotNull(activeNow);
Assert.assertNotEquals(activeRedisKeeperServer, activeNow);
Assert.assertEquals(PARTIAL_STATE.PARTIAL, activeNow.getRedisMaster().partialState());
for (RedisSlave slave : activeNow.slaves()) {
Assert.assertEquals(PARTIAL_STATE.PARTIAL, slave.partialState());
}
sendMessageToMasterAndTestSlaveRedis();
}
Aggregations