Search in sources :

Example 6 with RedisKeeperServer

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();
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave) Test(org.junit.Test)

Example 7 with RedisKeeperServer

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();
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) Test(org.junit.Test)

Example 8 with RedisKeeperServer

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();
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave) Test(org.junit.Test)

Example 9 with RedisKeeperServer

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();
}
Also used : DefaultMetaServer(com.ctrip.xpipe.redis.meta.server.impl.DefaultMetaServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) SERVER_ROLE(com.ctrip.xpipe.api.server.Server.SERVER_ROLE)

Example 10 with RedisKeeperServer

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();
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave) Test(org.junit.Test)

Aggregations

RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)44 Test (org.junit.Test)23 DefaultRedisKeeperServer (com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer)13 RedisSlave (com.ctrip.xpipe.redis.keeper.RedisSlave)6 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)5 ErrorMessage (com.ctrip.xpipe.exception.ErrorMessage)4 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)4 RedisKeeperRuntimeException (com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException)4 DefaultReplicationStore (com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStore)4 InMemoryPsync (com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync)3 RedisErrorParser (com.ctrip.xpipe.redis.core.protocal.protocal.RedisErrorParser)3 LinkedList (java.util.LinkedList)3 ReplicationStore (com.ctrip.xpipe.redis.core.store.ReplicationStore)2 XSlaveofJob (com.ctrip.xpipe.redis.meta.server.job.XSlaveofJob)2 IOException (java.io.IOException)2 Endpoint (com.ctrip.xpipe.api.endpoint.Endpoint)1 PARTIAL_STATE (com.ctrip.xpipe.api.server.PARTIAL_STATE)1 SERVER_ROLE (com.ctrip.xpipe.api.server.Server.SERVER_ROLE)1 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)1 NoMasterlinkRedisError (com.ctrip.xpipe.redis.core.protocal.error.NoMasterlinkRedisError)1