DefaultCurrentMetaManager extends AbstractLifecycleObservable implements CurrentMetaManager, Observer { protected Pair<Set<Integer>, Set<Integer>> getAddAndRemove(Set<Integer> future, Set<Integer> current) { Set<Integer> added = new HashSet<>(future); added.removeAll(current); if(added.size() > 0){ logger.info("[checkAddOrRemoveSlots][to add]{}", added); } Set<Integer> toRemove = new HashSet<>(current); toRemove.removeAll(future); if(toRemove.size() > 0){ logger.info("[checkAddOrRemoveSlots][toRemove]{}", toRemove); } return new Pair<>(added, toRemove); } DefaultCurrentMetaManager(); @Override synchronized void addObserver(Observer observer); @Override Set<String> allClusters(); @Override void deleteSlot(int slotId); @Override void addSlot(int slotId); @Override void exportSlot(int slotId); @Override void importSlot(int slotId); @Override void update(Object args, Observable observable); @Override boolean hasCluster(String clusterId); @Override boolean hasShard(String clusterId, String shardId); @Override RedisMeta getRedisMaster(String clusterId, String shardId); @Override ClusterMeta getClusterMeta(String clusterId); @Override RouteMeta randomRoute(String clusterId); @Override Pair<String, Integer> getKeeperMaster(String clusterId, String shardId); @Override List<KeeperMeta> getSurviveKeepers(String clusterId, String shardId); @Override KeeperMeta getKeeperActive(String clusterId, String shardId); @Override String getCurrentMetaDesc(); @Override boolean updateKeeperActive(String clusterId, String shardId, KeeperMeta activeKeeper); @Override void addResource(String clusterId, String shardId, Releasable releasable); @Override void setSurviveKeepers(String clusterId, String shardId, List<KeeperMeta> surviceKeepers, KeeperMeta activeKeeper); @Override void setKeeperMaster(String clusterId, String shardId, String ip, int port); @Override void setKeeperMaster(String clusterId, String shardId, String addr); @Override boolean watchIfNotWatched(String clusterId, String shardId); @Override void setCurrentCRDTMaster(String clusterId, String shardId, long gid, String ip, int port); @Override RedisMeta getCurrentCRDTMaster(String clusterId, String shardId); @Override RedisMeta getCurrentMaster(String clusterId, String shardId); @Override void setPeerMaster(String dcId, String clusterId, String shardId, long gid, String ip, int port); @Override RedisMeta getPeerMaster(String dcId, String clusterId, String shardId); @Override Set<String> getUpstreamPeerDcs(String clusterId, String shardId); List<RedisMeta> getAllPeerMasters(String clusterId, String shardId); @Override void removePeerMaster(String dcId, String clusterId, String shardId); void setSlotManager(SlotManager slotManager); void setDcMetaCache(DcMetaCache dcMetaCache);  }
@Test public void testAddOrRemove() { Set<Integer> future = new HashSet<>(); future.add(1); future.add(2); future.add(3); Set<Integer> current = new HashSet<>(); current.add(1); current.add(2); current.add(4); Pair<Set<Integer>, Set<Integer>> result = currentMetaServerMetaManager.getAddAndRemove(future, current); Assert.assertEquals(3, future.size()); Assert.assertEquals(3, current.size()); Assert.assertEquals(1, result.getKey().size()); Assert.assertEquals(3, result.getKey().toArray()[0]); Assert.assertEquals(1, result.getValue().size()); Assert.assertEquals(4, result.getValue().toArray()[0]); }