CurrentDcSentinelHelloAggregationCollector extends AbstractAggregationCollector<CurrentDcSentinelHelloCollector> implements BiDirectionSupport { @Override public void onAction(SentinelActionContext context) { RedisInstanceInfo info = context.instance().getRedisInstanceInfo(); if (!info.getClusterId().equalsIgnoreCase(clusterId) || !info.getShardId().equalsIgnoreCase(shardId)) return; collectHello(context); if (checkFinishedInstance.size() >= getRedisCntInCurrentDc() - 1) { if (checkFinishedInstance.size() == checkFailInstance.size()) { logger.info("[{}-{}][onAction] sentinel hello all fail, skip sentinel adjust", clusterId, shardId); resetCheckResult(); return; } logger.debug("[{}-{}][onAction] sentinel hello collect finish", clusterId, shardId); handleAllHello(context.instance()); } } CurrentDcSentinelHelloAggregationCollector(MetaCache metaCache, CurrentDcSentinelHelloCollector sentinelHelloCollector,
                                                      String clusterId, String shardId); @Override void onAction(SentinelActionContext context);  }
@Test public void testOnAction() { SentinelActionContext context = new SentinelActionContext(instance, Collections.singleton(new SentinelHello(sentinel, masterAddr, ""))); Mockito.doAnswer(invocation -> { SentinelActionContext paramContext = invocation.getArgumentAt(0, SentinelActionContext.class); Assert.assertEquals(Collections.singleton(new SentinelHello(sentinel, masterAddr, "")), paramContext.getResult()); Assert.assertEquals(instance, paramContext.instance()); return null; }).when(sentinelHelloCollector).onAction(Mockito.any()); collector.onAction(context); Mockito.verify(sentinelHelloCollector, Mockito.times(1)).onAction(Mockito.any()); }
@Test public void testOnActionWithException() { SentinelActionContext context = new SentinelActionContext(instance, new Exception()); collector.onAction(context); Mockito.verify(sentinelHelloCollector, Mockito.never()).onAction(Mockito.any()); }