SlaveOfCommandHandler extends AbstractCommandHandler { @Override protected void doHandle(String[] args, RedisClient redisClient) { if (validateArgs(args)) { if(args.length == 2){ handleSlaveOf(args, redisClient); }else if(args.length == 4){ handleForwarding(args, redisClient); }else { redisClient.sendMessage(new RedisErrorParser("wrong format").format()); } return; } redisClient.sendMessage(new RedisErrorParser("wrong format").format()); }  @Override String[] getCommands();  }
@Test public void testSlaveOf(){ String []args = new String[]{"127.0.0.1", "0"}; when(redisKeeperServer.getRedisKeeperServerState()).thenReturn(new RedisKeeperServerStateActive(redisKeeperServer)); slaveOfCommandHandler.doHandle(args, redisClient); verify(redisKeeperServer).reconnectMaster(); reset(redisKeeperServer); when(redisKeeperServer.getRedisKeeperServerState()).thenReturn(new RedisKeeperServerStateBackup(redisKeeperServer)); slaveOfCommandHandler.doHandle(args, redisClient); verify(redisKeeperServer, never()).reconnectMaster(); }