SentinelHelloCheckActionFactory extends AbstractLeaderAwareHealthCheckActionFactory implements OneWaySupport, BiDirectionSupport { @Override public SiteLeaderAwareHealthCheckAction create(RedisHealthCheckInstance instance) { SentinelHelloCheckAction action = new SentinelHelloCheckAction(scheduled, instance, executors, consoleDbConfig, clusterService); ClusterType clusterType = instance.getRedisInstanceInfo().getClusterType(); action.addListeners(collectorsByClusterType.get(clusterType)); action.addControllers(controllersByClusterType.get(clusterType)); return action; } @Autowired  SentinelHelloCheckActionFactory(List<SentinelHelloCollector> collectors, List<SentinelActionController> controllers,
                                           ConsoleDbConfig consoleDbConfig, ClusterService clusterService); @Override SiteLeaderAwareHealthCheckAction create(RedisHealthCheckInstance instance); @Override Class<? extends SiteLeaderAwareHealthCheckAction> support();  }
@Test public void testCreate() throws Exception { collector1 = spy(collector1); collector2 = spy(collector2); SentinelHelloCheckAction action = (SentinelHelloCheckAction) factory .create(newRandomRedisHealthCheckInstance("dc2", randomPort())); Assert.assertTrue(action.getListeners().size() > 0); Assert.assertTrue(action.getControllers().size() > 0); logger.info("[listeners] {}", action.getListeners()); logger.info("[controller] {}", action.getControllers()); Assert.assertTrue(action.getListeners().stream().allMatch(listener -> listener instanceof OneWaySupport)); Assert.assertTrue(action.getControllers().stream().allMatch(controller -> controller instanceof OneWaySupport)); action.processSentinelHellos(); }
@Test public void testCreateForBiDirectionInstance() throws Exception { SentinelHelloCheckAction action = (SentinelHelloCheckAction) factory .create(newRandomRedisHealthCheckInstance("dc1", ClusterType.BI_DIRECTION, randomPort())); Assert.assertTrue(action.getListeners().size() > 0); Assert.assertTrue(action.getControllers().size() > 0); Assert.assertTrue(action.getListeners().stream().allMatch(listener -> listener instanceof BiDirectionSupport)); Assert.assertTrue(action.getControllers().stream().allMatch(controller -> controller instanceof BiDirectionSupport)); action.processSentinelHellos(); }