CurrentDcSentinelHelloCollector extends DefaultSentinelHelloCollector { @Override protected HostPort getMaster(RedisInstanceInfo info) throws MasterNotFoundException { String dcId = info.getDcId(); String clusterId = info.getClusterId(); String shardId = info.getShardId(); if (!checkDcClusterShardExist(dcId, clusterId, shardId)) { throw new MasterNotFoundException(clusterId, shardId); } ShardMeta shardMeta = metaCache.getXpipeMeta().getDcs().get(dcId).getClusters().get(clusterId).getShards().get(shardId); Optional<RedisMeta> optional = shardMeta.getRedises().stream().filter(RedisMeta::isMaster).findFirst(); if (!optional.isPresent()) throw new MasterNotFoundException(clusterId, shardId); RedisMeta master = optional.get(); return new HostPort(master.getIp(), master.getPort()); }    }
@Test public void testGetMaster() throws Exception { RedisInstanceInfo info = mockInstanceInfo("127.0.0.1", 6379); HostPort result = collector.getMaster(info); Assert.assertEquals(masterAddr, result); }