@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);
}