DcServiceImpl extends AbstractConsoleService<DcTblDao> implements DcService { @Override public List<DcListDcModel> findAllDcsRichInfo(){ try { List<DcTbl> dcTbls = findAllDcs(); if (dcTbls == null || dcTbls.size() == 0) return Collections.emptyList(); List<DcListDcModel> result = new LinkedList<>(); dcTbls.forEach(dcTbl -> { DcMeta dcMeta = dcMetaService.getDcMeta(dcTbl.getDcName()); DcListDcModel dcModel = new DcListDcModel(); int countRedisNums = 0, countKeeperNums = 0, countClusterInActiveDc = 0; dcModel.setDcId(dcTbl.getId()); dcModel.setClusterCount(dcMeta.getClusters().values().size()); dcModel.setDcName(dcMeta.getId()); dcModel.setKeeperContainerCount(dcMeta.getKeeperContainers().size()); for (ClusterMeta clusterMeta: dcMeta.getClusters().values()){ if (dcTbl.getDcName().equals(clusterMeta.getActiveDc())) countClusterInActiveDc++; for (ShardMeta shardMeta: clusterMeta.getShards().values()){ if (-countRedisNums <= Integer.MIN_VALUE || -countRedisNums - shardMeta.getRedises().size() <= Integer.MIN_VALUE){ throw new XpipeRuntimeException(String.format("redis numbers overflow: %d", countRedisNums)); }else if (-countKeeperNums <= Integer.MIN_VALUE || -countKeeperNums - shardMeta.getKeepers().size() <= Integer.MIN_VALUE){ throw new XpipeRuntimeException(String.format("keeper numbers overflow: %d", countKeeperNums)); }else{ countRedisNums += shardMeta.getRedises().size(); countKeeperNums += shardMeta.getKeepers().size(); } } } dcModel.setRedisCount(countRedisNums); dcModel.setKeeperCount(countKeeperNums); dcModel.setClusterInActiveDcCount(countClusterInActiveDc); result.add(dcModel); }); return result; } catch (Exception e) { return Collections.emptyList(); } }  @Override DcTbl find(final String dcName); @Override DcTbl find(final long dcId); @Override String getDcName(long dcId); @Override List<DcTbl> findAllDcs(); @Override List<DcTbl> findAllDcNames(); @Override List<DcTbl> findAllDcBasic(); @Override List<DcTbl> findClusterRelatedDc(final String clusterName); @Override DcTbl findByDcName(final String dcName); @Override Map<Long, String> dcNameMap(); @Override List<DcListDcModel> findAllDcsRichInfo(); @Override synchronized void insertWithPartField(long zoneId, String dcName, String description);  }
@Test public void testFindAllDcsRichinfo(){ dcService = spy(dcService); Mockito.doReturn(toBuildTbl()).when(dcService).findAllDcs(); List<DcListDcModel> result = dcService.findAllDcsRichInfo(); Assert.assertEquals(2, result.size()); result.forEach(dcListDcModel -> { if (dcListDcModel.getDcName() == "jq"){ Assert.assertEquals(2, (long)dcListDcModel.getRedisCount()); Assert.assertEquals(2, (long)dcListDcModel.getClusterCount()); }else if (dcListDcModel.getDcName() == "oy"){ Assert.assertEquals(2, (long)dcListDcModel.getRedisCount()); Assert.assertEquals(2, (long)dcListDcModel.getClusterCount()); } }); }