DefaultRedisMasterActionListener implements RedisMasterActionListener, OneWaySupport, BiDirectionSupport { @Override public void onAction(RedisMasterActionContext redisMasterActionContext) { Server.SERVER_ROLE redisRole = redisMasterActionContext.getResult(); RedisHealthCheckInstance instance = redisMasterActionContext.instance(); if(redisRole.equals(Server.SERVER_ROLE.UNKNOWN)) { handleUnknownRole(instance); return; } boolean actualMaster = redisRole.equals(Server.SERVER_ROLE.MASTER); RedisRoleState state = RedisRoleState.getFrom(instance.getRedisInstanceInfo().isMaster(), actualMaster); if(state.shouldBeCorrect()) { updateRedisRoleInDB(instance, state); } } @Autowired  DefaultRedisMasterActionListener(RedisService redisService, MetaCache metaCache,
                                            MetaServerConsoleServiceManagerWrapper metaServerConsoleServiceManagerWrapper); @Override void onAction(RedisMasterActionContext redisMasterActionContext);  }
@Test public void testUnknownAndMasterButMetaServerTakeTheOther() { redisTbls.get(1).setMaster(true); instance.getRedisInstanceInfo().isMaster(true); Mockito.when(metaServerConsoleService.getCurrentMaster(Mockito.anyString(), Mockito.anyString())) .thenReturn(new RedisMeta().setIp("127.0.0.1").setPort(6479)); listener.onAction(new RedisMasterActionContext(instance, Server.SERVER_ROLE.UNKNOWN)); sleep(30); Mockito.verify(redisService, Mockito.times(1)).updateBatchMaster(Mockito.anyList()); Assert.assertFalse(instance.getRedisInstanceInfo().isMaster()); Assert.assertEquals(new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(6379).setMaster(false).toString(), updatedRedisTbls.get(0).toString()); }