SentinelServiceImpl extends AbstractConsoleService<SetinelTblDao> implements SentinelService { @Override public Map<Long, List<SetinelTbl>> allSentinelsByDc() { Map<Long, List<SetinelTbl>> result = new HashMap<>(); List<SetinelTbl> setinelTbls = queryHandler.handleQuery(new DalQuery<List<SetinelTbl>>() { @Override public List<SetinelTbl> doQuery() throws DalException { return dao.findAll(SetinelTblEntity.READSET_FULL); } }); setinelTbls.forEach( setinelTbl -> { List<SetinelTbl> setinels = MapUtils.getOrCreate(result, setinelTbl.getDcId(), new ObjectFactory<List<SetinelTbl>>() { @Override public List<SetinelTbl> create() { return new LinkedList<>(); } }); setinels.add(setinelTbl); }); return result; }  @Override List<SetinelTbl> findAllByDcName(final String dcName); @Override Map<Long, List<SetinelTbl>> allSentinelsByDc(); @Override Map<Long, SetinelTbl> eachRandomSentinelByDc(); @Override SetinelTbl find(final long id); @Override Map<Long, SetinelTbl> findByShard(long shardId); @Override SetinelTbl insert(SetinelTbl setinelTbl); @Override Map<String, SentinelUsageModel> getAllSentinelsUsage(); @Override SentinelModel updateSentinelTblAddr(SentinelModel sentinel); @Override RetMessage removeSentinelMonitor(String clusterName); @Override void delete(long id); @Override void reheal(long id);  }
@Test public void testAllSentinelsByDc() { int dcCount = 5; int sentinelsEachDc = 5; for (int i = 0; i < dcCount; i++) { for (int j = 0; j < sentinelsEachDc; j++) { sentinelService.insert(new SetinelTbl().setDcId(i).setSetinelAddress("desc").setSetinelDescription(getTestName())); } } Map<Long, List<SetinelTbl>> allSentinelsByDc = sentinelService.allSentinelsByDc(); Assert.assertEquals(dcCount, allSentinelsByDc.size()); allSentinelsByDc.forEach((dcId, sentinels) -> { Assert.assertTrue(sentinels.size() >= sentinelsEachDc); }); }