SentinelConfigCheck extends AbstractCrossDcIntervalCheck { protected void doCheck() { XpipeMeta xpipeMeta = metaCache.getXpipeMeta(); if (null == xpipeMeta) return; for (DcMeta dc: xpipeMeta.getDcs().values()) { List<DcClusterShard> clusterShards = findUnsafeClusterShardInDc(dc); alertForSentinelMissing(dc.getId(), clusterShards); } }    }
@Test public void testDoCheckWithOneWayCluster() { Mockito.doAnswer(invocationOnMock -> { String dc = invocationOnMock.getArgumentAt(0, String.class); String cluster = invocationOnMock.getArgumentAt(1, String.class); String shard = invocationOnMock.getArgumentAt(2, String.class); Assert.assertTrue(expectedUnsafeClusters.get(dc).contains(cluster)); Assert.assertTrue(mockShards.contains(shard)); return null; }).when(alertManager).alert(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any()); sentinelConfigCheck.doCheck(); Mockito.verify(alertManager, Mockito.times(6)) .alert(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyString()); }
@Test public void testDoCheckWithBiDirectionCluster() { this.mockClusterType = ClusterType.BI_DIRECTION; Mockito.when(metaCache.getXpipeMeta()).thenReturn(mockXpipeMeta()); sentinelConfigCheck.doCheck(); Mockito.verify(alertManager, Mockito.times(12)) .alert(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyString()); }
@Test public void testCheckWithSentinelCheckWhitelist() { Mockito.when(consoleDbConfig.sentinelCheckWhiteList(Mockito.anyBoolean())).thenReturn(new HashSet<>(mockClusters)); sentinelConfigCheck.doCheck(); Mockito.verify(alertManager, Mockito.never()) .alert(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyString()); }