Search in sources :

Example 1 with ShardModel

use of com.ctrip.xpipe.redis.console.model.ShardModel in project x-pipe by ctripcorp.

the class RedisServiceImplTest method testUpdateRedises.

@Test
public void testUpdateRedises() throws IOException, ResourceNotFoundException {
    List<RedisTbl> allByDcClusterShard = redisService.findAllByDcClusterShard(dcName, clusterName, shardName);
    checkAllInstances(allByDcClusterShard);
    boolean firstSlave = true;
    RedisTbl newMaster = null;
    for (RedisTbl redisTbl : allByDcClusterShard) {
        if (redisTbl.getRedisRole().equals(XPipeConsoleConstant.ROLE_REDIS)) {
            if (redisTbl.isMaster()) {
                redisTbl.setMaster(false);
            } else if (!redisTbl.isMaster() && firstSlave) {
                redisTbl.setMaster(true);
                newMaster = redisTbl;
                firstSlave = false;
            }
        }
    }
    checkAllInstances(allByDcClusterShard);
    ShardModel shardModel = new ShardModel(allByDcClusterShard);
    redisService.updateRedises(dcName, clusterName, shardName, shardModel);
    allByDcClusterShard = redisService.findAllByDcClusterShard(dcName, clusterName, shardName);
    checkAllInstances(allByDcClusterShard);
    Stream<RedisTbl> redisTblStream = allByDcClusterShard.stream().filter(instance -> instance.isMaster());
    RedisTbl currentMaster = redisTblStream.findFirst().get();
    Assert.assertEquals(newMaster.getId(), currentMaster.getId());
}
Also used : ShardModel(com.ctrip.xpipe.redis.console.model.ShardModel) RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) Test(org.junit.Test)

Aggregations

RedisTbl (com.ctrip.xpipe.redis.console.model.RedisTbl)1 ShardModel (com.ctrip.xpipe.redis.console.model.ShardModel)1 Test (org.junit.Test)1