SentinelServiceImpl extends AbstractConsoleService<SetinelTblDao> implements SentinelService { @VisibleForTesting protected void removeSentinelMonitorByShard(String activeIdc, String clusterName, ClusterType clusterType, DcClusterShardTbl dcClusterShard) { ShardTbl shardTbl = shardService.find(dcClusterShard.getShardId()); RemoveShardSentinelMonitorEvent shardEvent = new RemoveShardSentinelMonitorEvent(clusterName, shardTbl.getShardName(), MoreExecutors.directExecutor()); shardEvent.setClusterType(clusterType); shardEvent.setShardSentinels(find(dcClusterShard.getSetinelId()).getSetinelAddress()); shardEvent.setShardMonitorName(SentinelUtil.getSentinelMonitorName(clusterName, shardTbl.getSetinelMonitorName(), activeIdc)); sentinelManager.removeShardSentinelMonitors(shardEvent); }  @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 testRemoveSentinelMonitorByShard() { String dc = "SHAJQ", cluster = "cluster-test", shard = "shard1"; DcClusterShardTbl dcClusterShardTbl = new DcClusterShardTbl().setShardId(1L).setSetinelId(2L); sentinelService = spy(sentinelService); when(sentinelService.find(anyLong())).thenReturn(new SetinelTbl().setSetinelAddress("10.0.0.1:5555,10.0.0.2:5555")); when(shardService.find(anyLong())).thenReturn(new ShardTbl().setShardName(shard).setSetinelMonitorName(shard)); doNothing().when(sentinelManager).removeShardSentinelMonitors(any(ShardEvent.class)); sentinelService.removeSentinelMonitorByShard(dc, cluster, ClusterType.ONE_WAY, dcClusterShardTbl); verify(sentinelManager, times(1)).removeShardSentinelMonitors(any(ShardEvent.class)); }