SingleGroupAddressHolder extends AddressHolder { @Override public void updateAllProviders(List<ProviderGroup> providerGroups) { ConcurrentHashSet<ProviderInfo> tmpDirectUrl = new ConcurrentHashSet<ProviderInfo>(); ConcurrentHashSet<ProviderInfo> tmpRegistry = new ConcurrentHashSet<ProviderInfo>(); for (ProviderGroup providerGroup : providerGroups) { if (!ProviderHelper.isEmpty(providerGroup)) { if (RpcConstants.ADDRESS_DIRECT_GROUP.equals(providerGroup.getName())) { tmpDirectUrl.addAll(providerGroup.getProviderInfos()); } else { tmpRegistry.addAll(providerGroup.getProviderInfos()); } } } wLock.lock(); try { this.directUrlGroup.setProviderInfos(new ArrayList<ProviderInfo>(tmpDirectUrl)); this.registryGroup.setProviderInfos(new ArrayList<ProviderInfo>(tmpRegistry)); } finally { wLock.unlock(); } } protected  SingleGroupAddressHolder(ConsumerBootstrap consumerBootstrap); @Override List<ProviderInfo> getProviderInfos(String groupName); @Override ProviderGroup getProviderGroup(String groupName); @Override List<ProviderGroup> getProviderGroups(); @Override int getAllProviderSize(); @Override void addProvider(ProviderGroup providerGroup); @Override void removeProvider(ProviderGroup providerGroup); @Override void updateProviders(ProviderGroup providerGroup); @Override void updateAllProviders(List<ProviderGroup> providerGroups);  }
@Test public void updateAllProviders() throws Exception { SingleGroupAddressHolder addressHolder = new SingleGroupAddressHolder(null); List<ProviderGroup> current; List<ProviderGroup> ps0 = new ArrayList<ProviderGroup>(); ps0.add(new ProviderGroup("xx", Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1:12200"), ProviderHelper.toProviderInfo("127.0.0.1:12201")))); ps0.add(new ProviderGroup(ADDRESS_DIRECT_GROUP, Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1:12203")))); addressHolder.updateAllProviders(ps0); current = addressHolder.getProviderGroups(); Assert.assertTrue(current.size() == 2); Assert.assertTrue(current.get(0).size() == 2); Assert.assertTrue(addressHolder.getProviderGroup("xxx").size() == 2); Assert.assertTrue(addressHolder.getProviderGroup(ADDRESS_DIRECT_GROUP).size() == 1); Assert.assertTrue(addressHolder.getAllProviderSize() == 3); List<ProviderGroup> ps1 = new ArrayList<ProviderGroup>(); ps1.add(new ProviderGroup("xx", Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1:12200"), ProviderHelper.toProviderInfo("127.0.0.1:12201")))); ps1.add(new ProviderGroup("yy", Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1:12202"), ProviderHelper.toProviderInfo("127.0.0.1:12203")))); addressHolder.updateAllProviders(ps1); current = addressHolder.getProviderGroups(); Assert.assertTrue(current.size() == 2); Assert.assertTrue(current.get(0).size() == 4); Assert.assertTrue(addressHolder.getProviderGroup("xxx").size() == 4); Assert.assertTrue(addressHolder.getAllProviderSize() == 4); List<ProviderGroup> ps2 = new ArrayList<ProviderGroup>(); addressHolder.updateAllProviders(ps2); current = addressHolder.getProviderGroups(); Assert.assertTrue(current.size() == 2); Assert.assertTrue(current.get(0).size() == 0); Assert.assertTrue(addressHolder.getProviderGroup("xxx").size() == 0); Assert.assertTrue(addressHolder.getAllProviderSize() == 0); List<ProviderGroup> ps3 = new ArrayList<ProviderGroup>(); ps3.add(new ProviderGroup("xx", Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1:12200"), ProviderHelper.toProviderInfo("127.0.0.1:12201")))); ps3.add(new ProviderGroup("yy", Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1:12201"), ProviderHelper.toProviderInfo("127.0.0.1:12202")))); addressHolder.updateAllProviders(ps3); current = addressHolder.getProviderGroups(); Assert.assertTrue(current.size() == 2); Assert.assertTrue(current.get(0).size() == 3); Assert.assertTrue(addressHolder.getProviderGroup("xxx").size() == 3); Assert.assertTrue(addressHolder.getAllProviderSize() == 3); List<ProviderGroup> ps4 = new ArrayList<ProviderGroup>(); ps4.add(new ProviderGroup("yy", Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1:12203"), ProviderHelper.toProviderInfo("127.0.0.1:12204")))); addressHolder.updateAllProviders(ps4); current = addressHolder.getProviderGroups(); Assert.assertTrue(current.size() == 2); Assert.assertTrue(current.get(0).size() == 2); Assert.assertTrue(addressHolder.getProviderGroup("xxx").size() == 2); Assert.assertTrue(addressHolder.getAllProviderSize() == 2); }