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());
}
Aggregations