RedisServiceImpl extends AbstractConsoleService<RedisTblDao> implements RedisService { @Override public synchronized int insertKeepers(String dcId, String clusterId, String shardId, List<KeeperBasicInfo> keepers) throws DalException, ResourceNotFoundException { logger.info("[insertKeepers]{}, {}, {}, {}", dcId, clusterId, shardId, keepers); DcClusterShardTbl dcClusterShardTbl = dcClusterShardService.find(dcId, clusterId, shardId); if (dcClusterShardTbl == null) { throw new ResourceNotFoundException(dcId, clusterId, shardId); } List<RedisTbl> insertKeepers = new LinkedList<>(); keepers.forEach(keeperBasicInfo -> { RedisTbl keeper = createRedisTbl(new Pair<>(keeperBasicInfo.getHost(), keeperBasicInfo.getPort()), XPipeConsoleConstant.ROLE_KEEPER); keeper.setKeepercontainerId(keeperBasicInfo.getKeeperContainerId()); keeper.setDcClusterShardId(dcClusterShardTbl.getDcClusterShardId()); insertKeepers.add(keeper); }); validateKeepers(insertKeepers); int[] insert = insert(insertKeepers); notifyClusterUpdate(dcId, clusterId); return MathUtil.sum(insert); }  @Override RedisTbl find(final long id); @Override List<RedisTbl> findAllRedisWithSameIP(String ip); @Override List<RedisTbl> findAllByDcClusterShard(final long dcClusterShardId); @Override List<RedisTbl> findAllRedisesByDcClusterName(String dcId, String clusterId); @Override List<RedisTbl> findAllByDcClusterShard(String dcId, String clusterId, String shardId); @Override List<RedisTbl> findRedisesByDcClusterShard(String dcId, String clusterId, String shardId); @Override List<RedisTbl> findKeepersByDcClusterShard(String dcId, String clusterId, String shardId); @Override synchronized void insertRedises(String dcId, String clusterId, String shardId,
                                           List<Pair<String, Integer>> redisAddresses); @Override synchronized int insertKeepers(String dcId, String clusterId, String shardId,
                                          List<KeeperBasicInfo> keepers); @Override List<RedisTbl> deleteKeepers(String dcId, String clusterId, String shardId); @Override void deleteRedises(String dcId, String clusterId, String shardId, List<Pair<String, Integer>> redisAddresses); @Override void updateByPK(final RedisTbl redis); @Override void updateBatchMaster(List<RedisTbl> redises); @Override void updateBatchKeeperActive(List<RedisTbl> redises); @Override void updateRedises(String dcName, String clusterName, String shardName, ShardModel shardModel); @Override List<RedisTbl> findAllKeeperContainerCountInfo(); @Override List<Long> findClusterIdsByKeeperContainer(long keeperContainerId); void insertInstancesToDb(long dcClusterShardId, String role, Pair<String, Integer>... addrs);  }
@Test public void testInsertKeepers() throws ResourceNotFoundException, DalException { redisService.deleteKeepers(dcName, clusterName, shardName); List<KeeperBasicInfo> newKeepers = keeperAdvancedService.findBestKeepers(dcName, clusterName); Assert.assertEquals(2, newKeepers.size()); redisService.insertKeepers(dcName, clusterName, shardName, newKeepers); List<RedisTbl> result = redisService.findKeepersByDcClusterShard(dcName, clusterName, shardName); result.forEach(redisTbl -> Assert.assertTrue(redisTbl.getKeepercontainerId() != 0)); Assert.assertEquals(newKeepers.size(), result.size()); }