Search in sources :

Example 1 with RedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.

the class KeeperSingleDc method testMakeActiveBackup.

@Test
public void testMakeActiveBackup() throws Exception {
    logger.info(remarkableMessage("make keeper active{}"), backupKeeper);
    setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
    RedisKeeperServer redisKeeperServer = getRedisKeeperServer(activeKeeper);
    Assert.assertEquals(PARTIAL_STATE.FULL, redisKeeperServer.getRedisMaster().partialState());
    logger.info(remarkableMessage("[testMakeActiveBackup]{}"), activeKeeper);
    setKeeperState(activeKeeper, KeeperState.BACKUP, backupKeeper.getIp(), backupKeeper.getPort());
    sleep(2000);
    Assert.assertEquals(PARTIAL_STATE.PARTIAL, redisKeeperServer.getRedisMaster().partialState());
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) Test(org.junit.Test)

Example 2 with RedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.

the class KeeperSingleDc 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{}"), backupKeeper);
    setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
    sleep(2000);
    Assert.assertEquals(PARTIAL_STATE.PARTIAL, redisKeeperServer.getRedisMaster().partialState());
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) Test(org.junit.Test)

Example 3 with RedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.

the class KeeperSingleDcRestart method testActiveRestart.

@Test
public void testActiveRestart() throws Exception {
    RedisKeeperServer redisKeeperServer = getRedisKeeperServer(activeKeeper);
    remove(redisKeeperServer);
    // make backup active
    logger.info(remarkableMessage("[make backup active]{}"), backupKeeper);
    RedisKeeperServer rawBackupServer = getRedisKeeperServer(backupKeeper);
    Assert.assertEquals(KeeperState.BACKUP, rawBackupServer.getRedisKeeperServerState().keeperState());
    setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
    sleep(2000);
    Assert.assertEquals(KeeperState.ACTIVE, rawBackupServer.getRedisKeeperServerState().keeperState());
    Assert.assertEquals(PARTIAL_STATE.PARTIAL, rawBackupServer.getRedisMaster().partialState());
    // start active again
    startKeeper(activeKeeper);
    RedisKeeperServer newRedisKeeperServer = getRedisKeeperServer(activeKeeper);
    Assert.assertNotEquals(newRedisKeeperServer, redisKeeperServer);
    Assert.assertEquals(KeeperState.PRE_ACTIVE, newRedisKeeperServer.getRedisKeeperServerState().keeperState());
    // make new keeper backup
    logger.info(remarkableMessage("[make old active backup]{}"), activeKeeper);
    setKeeperState(activeKeeper, KeeperState.BACKUP, backupKeeper.getIp(), backupKeeper.getPort());
    sleep(2000);
    Assert.assertEquals(KeeperState.BACKUP, newRedisKeeperServer.getRedisKeeperServerState().keeperState());
    Assert.assertEquals(PARTIAL_STATE.PARTIAL, newRedisKeeperServer.getRedisMaster().partialState());
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) Test(org.junit.Test)

Example 4 with RedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.

the class KeeperSingleDcRestart method testBackupRestart.

@Test
public void testBackupRestart() throws Exception {
    RedisKeeperServer redisKeeperServer = getRedisKeeperServer(backupKeeper);
    remove(redisKeeperServer);
    startKeeper(backupKeeper);
    RedisKeeperServer newRedisKeeperServer = getRedisKeeperServer(backupKeeper);
    Assert.assertNotEquals(newRedisKeeperServer, redisKeeperServer);
    Assert.assertEquals(KeeperState.PRE_BACKUP, newRedisKeeperServer.getRedisKeeperServerState().keeperState());
    setKeeperState(backupKeeper, KeeperState.BACKUP, activeKeeper.getIp(), activeKeeper.getPort());
    sleep(2000);
    Assert.assertEquals(KeeperState.BACKUP, newRedisKeeperServer.getRedisKeeperServerState().keeperState());
    Assert.assertEquals(PARTIAL_STATE.PARTIAL, newRedisKeeperServer.getRedisMaster().partialState());
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) Test(org.junit.Test)

Example 5 with RedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.

the class KeeperPsync2Continue method testExchangeMasterSlave.

@Test
public void testExchangeMasterSlave() throws Exception {
    RedisKeeperServer redisKeeperServer = getRedisKeeperServer(activeKeeper);
    int slaveChosen = 0;
    long fullSyncCount = redisKeeperServer.getKeeperMonitor().getKeeperStats().getFullSyncCount();
    for (int i = 0; i < testRound; i++) {
        logger.info(remarkableMessage("round:{}"), i);
        RedisMeta slaveToPromote = slaves.get(0);
        xslaveof(activeKeeper.getIp(), activeKeeper.getPort(), redisMaster);
        xslaveof(null, 0, slaveToPromote);
        setKeeperState(activeKeeper, KeeperState.ACTIVE, slaveToPromote.getIp(), slaveToPromote.getPort());
        sleep(3000);
        Assert.assertEquals(fullSyncCount, redisKeeperServer.getKeeperMonitor().getKeeperStats().getFullSyncCount());
        RedisMeta tmpRedisMaster = redisMaster;
        redisMaster = slaveToPromote;
        slaves.remove(slaveChosen);
        slaves.add(0, tmpRedisMaster);
    }
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) 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