DefaultRedisKeeperServer extends AbstractRedisServer implements RedisKeeperServer { @Override public synchronized boolean compareAndDo(RedisKeeperServerState expected, Runnable action) { if(this.redisKeeperServerState == expected){ action.run(); return true; } return false; } DefaultRedisKeeperServer(KeeperMeta currentKeeperMeta, KeeperConfig keeperConfig, File baseDir,
									LeaderElectorManager leaderElectorManager,
									KeepersMonitorManager keepersMonitorManager, KeeperResourceManager resourceManager); @Override synchronized void reconnectMaster(); @Override RedisClient clientConnected(Channel channel); @Override void clientDisConnected(Channel channel); @Override String toString(); @Override String getKeeperRunid(); @Override KeeperRepl getKeeperRepl(); @Override Set<RedisClient> allClients(); @Override SERVER_ROLE role(); @Override String info(); @Override Set<RedisSlave> slaves(); ReplicationStore getReplicationStore(); @Override int getListeningPort(); @Override void beginWriteRdb(EofType eofType, long offset); @Override void endWriteRdb(); @Override void reFullSync(); @Override void onFullSync(); @Override void onContinue(String requestReplId, String responseReplId); @Override String getClusterId(); @Override String getShardId(); @Override synchronized void setRedisKeeperServerState(final RedisKeeperServerState redisKeeperServerState); @Override synchronized boolean compareAndDo(RedisKeeperServerState expected, Runnable action); @Override KeeperMeta getCurrentKeeperMeta(); @Override void stopAndDisposeMaster(); @Override RedisKeeperServerState getRedisKeeperServerState(); @Override RedisMaster getRedisMaster(); @Override void promoteSlave(String ip, int port); @Override void fullSyncToSlave(final RedisSlave redisSlave); void setRdbDumper(RdbDumper rdbDumper); @Override KeeperInstanceMeta getKeeperInstanceMeta(); KeeperConfig getKeeperConfig(); @Override void destroy(); @Override void setRdbDumper(RdbDumper newDumper, boolean force); @Override void clearRdbDumper(RdbDumper oldDumper); int getRdbDumpTryCount(); synchronized void initReplicationStore(ReplicationStore replicationStore); @Override KeeperMonitor getKeeperMonitor(); @Override void processCommandSequentially(Runnable runnable); @Override RdbDumper rdbDumper(); static String KEY_DEFAULT_KEEPER_WORKER_GROUP_THREAD_COUNT; static int DEFAULT_KEEPER_WORKER_GROUP_THREAD_COUNT; }
@Test public void testCompareAndDo() throws Exception { RedisKeeperServer redisKeeperServer = createRedisKeeperServer(); RedisClient redisClient = Mockito.mock(RedisClient.class); RedisKeeperServerStateBackup backup = new RedisKeeperServerStateBackup(redisKeeperServer); redisKeeperServer.setRedisKeeperServerState(backup); Assert.assertFalse(backup.psync(redisClient, new String[] {})); ; redisKeeperServer.setRedisKeeperServerState(new RedisKeeperServerStateActive(redisKeeperServer)); Assert.assertTrue(backup.psync(redisClient, new String[] {})); }