DefaultCurrentMetaManager extends AbstractLifecycleObservable implements CurrentMetaManager, Observer { protected void checkAddOrRemoveSlots() { Set<Integer> slots = slotManager.getSlotsByServerId(currentClusterServer.getServerId(), false); Pair<Set<Integer>, Set<Integer>> result = getAddAndRemove(slots, currentSlots); for(Integer slotId : result.getKey()){ addSlot(slotId); } for(Integer slotId : result.getValue()){ deleteSlot(slotId); } } 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 testCheckAddOrRemoveSlots(){ Set<Integer> newSlots = new HashSet<>(); for(int i=0;i<10;i++){ newSlots.add(i); } Assert.assertEquals(0, currentMetaServerMetaManager.getCurrentSlots().size()); when(slotManager.getSlotsByServerId(anyInt(), eq(false))).thenReturn(newSlots); currentMetaServerMetaManager.checkAddOrRemoveSlots(); logger.info("[testCheckAddOrRemoveSlots]{}", currentMetaServerMetaManager.getCurrentSlots()); Assert.assertEquals(newSlots, currentMetaServerMetaManager.getCurrentSlots()); for(int i=0;i<5;i++){ newSlots.remove(i); } for(int i=10;i<20;i++){ newSlots.add(i); } currentMetaServerMetaManager.checkAddOrRemoveSlots(); Assert.assertEquals(newSlots, currentMetaServerMetaManager.getCurrentSlots()); }