SentinelServiceImpl extends AbstractConsoleService<SetinelTblDao> implements SentinelService { @Override public RetMessage removeSentinelMonitor(String clusterName) { ClusterTbl clusterTbl = clusterService.find(clusterName); ClusterType clusterType = ClusterType.lookup(clusterTbl.getClusterType()); if (null != clusterType && clusterType.supportMultiActiveDC()) { return RetMessage.createFailMessage("cluster type " + clusterType + " not support remove sentinel"); } long activedcId = clusterService.find(clusterName).getActivedcId(); String dcName = dcService.getDcName(activedcId); List<DcClusterShardTbl> dcClusterShardTbls = dcClusterShardService.findAllByDcCluster(dcName, clusterName); for(DcClusterShardTbl dcClusterShard : dcClusterShardTbls) { try { removeSentinelMonitorByShard(dcName, clusterName, clusterType, dcClusterShard); } catch (Exception e) { return RetMessage.createFailMessage("[stl-id: " + dcClusterShard.getSetinelId() + "]" + e.getMessage()); } } return RetMessage.createSuccessMessage(); }  @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 testRemoveSentinelMonitor() { String dc = "SHAJQ", cluster = "cluster-test"; sentinelService = new SentinelServiceImpl() { @Override protected void removeSentinelMonitorByShard(String activeIdc, String clusterName, ClusterType clusterType, DcClusterShardTbl dcClusterShard) { } }; sentinelService.setClusterService(clusterService); sentinelService.setShardService(shardService); sentinelService.setDcService(dcService); sentinelService.setSentinelManager(sentinelManager); sentinelService.setDcClusterShardService(dcClusterShardService); when(clusterService.find(anyString())).thenReturn(new ClusterTbl().setActivedcId(1).setClusterType(ClusterType.ONE_WAY.toString())); when(dcService.getDcName(anyLong())).thenReturn(dc); when(dcClusterShardService.findAllByDcCluster(dc, cluster)) .thenReturn(Lists.newArrayList(new DcClusterShardTbl().setShardId(1).setDcId(1L))); RetMessage retMessage = sentinelService.removeSentinelMonitor(cluster); Assert.assertEquals(RetMessage.SUCCESS_STATE, retMessage.getState()); }