DefaultSentinelHelloCollector implements SentinelHelloCollector { @VisibleForTesting protected boolean isKeeperOrDead(HostPort hostPort) { CountDownLatch latch = new CountDownLatch(1); AtomicReference<Object> role = new AtomicReference<>(); try { RedisSession redisSession = sessionManager.findOrCreateSession(hostPort); redisSession.role(new RedisSession.RollCallback() { @Override public void role(String roleDesc) { role.set(roleDesc); latch.countDown(); } @Override public void fail(Throwable e) { logger.error("[isKeeperOrDead][fail]" + hostPort, e); role.set(e); latch.countDown(); } }); } catch (Exception e) { role.set(e); logger.error("[isKeeperOrDead]" + hostPort, e); } try { latch.await(2, TimeUnit.SECONDS); } catch (InterruptedException e) { logger.error("[isKeeperOrDead]latch await error: {}", e); } if (role.get() instanceof String && Server.SERVER_ROLE.KEEPER.sameRole((String) role.get())) { return true; } if (role.get() instanceof CommandExecutionException || role.get() instanceof CommandTimeoutException || role.get() instanceof SocketException) { return true; } logger.info("[isKeeperOrDead] role: {}", role.get()); return false; }  @PostConstruct void postConstruct(); @PreDestroy void preDestroy(); @Override void onAction(SentinelActionContext context); @Override void stopWatch(HealthCheckAction action); @Override boolean worksfor(ActionContext t); @VisibleForTesting void setSessionManager(DefaultRedisSessionManager sessionManager); @VisibleForTesting void setAlertManager(AlertManager alertManager);  }
@Test public void testIsKeeperOrDead() { AbstractRedisCommand.DEFAULT_REDIS_COMMAND_TIME_OUT_MILLI = 10; boolean result = sentinelCollector.isKeeperOrDead(localHostport(0)); logger.info("{}", result); Assert.assertTrue(result); }