@Test
    public void compareAddressMap() throws Exception {

        List<ProviderGroup> oldMap = new ArrayList<ProviderGroup>();
        List<ProviderGroup> newMap = new ArrayList<ProviderGroup>();

        List<ProviderInfo> add = new ArrayList<ProviderInfo>();
        List<ProviderInfo> remove = new ArrayList<ProviderInfo>();

        {
            ProviderHelper.compareGroups(oldMap, newMap, add, remove);
            Assert.assertEquals(add.size(), 0);
            Assert.assertEquals(remove.size(), 0);
        }

        {
            oldMap.clear();
            newMap.clear();
            add.clear();
            remove.clear();
            oldMap.add(new ProviderGroup("zone1",
                Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1:12200?p=11&v=4.0"))));
            oldMap.add(new ProviderGroup("zone2", Arrays.asList(
                ProviderHelper.toProviderInfo("127.0.0.2:12200?p=11&v=4.0"),
                ProviderHelper.toProviderInfo("127.0.0.3:12200?p=11&v=4.0"))));
            ProviderHelper.compareGroups(oldMap, newMap, add, remove);
            Assert.assertEquals(add.size(), 0);
            Assert.assertEquals(remove.size(), 3);
        }

        {
            oldMap.clear();
            newMap.clear();
            add.clear();
            remove.clear();
            newMap.add(new ProviderGroup("zone1",
                Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1:12200?p=11&v=4.0"))));
            newMap.add(new ProviderGroup("zone2", Arrays.asList(
                ProviderHelper.toProviderInfo("127.0.0.2:12200?p=11&v=4.0"),
                ProviderHelper.toProviderInfo("127.0.0.3:12200?p=11&v=4.0"))));
            ProviderHelper.compareGroups(oldMap, newMap, add, remove);
            Assert.assertEquals(add.size(), 3);
            Assert.assertEquals(remove.size(), 0);
        }

        {
            oldMap.clear();
            newMap.clear();
            add.clear();
            remove.clear();
            oldMap.add(new ProviderGroup("zone1",
                Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1:12200?p=11&v=4.0"))));
            oldMap.add(new ProviderGroup("zone2", Arrays.asList(
                ProviderHelper.toProviderInfo("127.0.0.2:12200?p=11&v=4.0"),
                ProviderHelper.toProviderInfo("127.0.0.3:12200?p=11&v=4.0"))));
            oldMap.add(new ProviderGroup("zone3", Arrays.asList(
                ProviderHelper.toProviderInfo("127.0.0.4:12200?p=11&v=4.0"),
                ProviderHelper.toProviderInfo("127.0.0.5:12200?p=11&v=4.0"))));
            oldMap.add(new ProviderGroup("zone4", Arrays.asList(
                ProviderHelper.toProviderInfo("127.0.0.6:12200?p=11&v=4.0"),
                ProviderHelper.toProviderInfo("127.0.0.7:12200?p=11&v=4.0"))));
            oldMap.add(new ProviderGroup("zone5", Arrays.asList(
                ProviderHelper.toProviderInfo("127.0.0.8:12200?p=11&v=4.0"),
                ProviderHelper.toProviderInfo("127.0.0.9:12200?p=11&v=4.0"))));

            newMap.add(new ProviderGroup("zone1",
                Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1:12200?p=11&v=4.0"))));
            newMap.add(new ProviderGroup("zone2", Arrays.asList(
                ProviderHelper.toProviderInfo("127.0.0.2:12200?p=11&v=4.0"),
                ProviderHelper.toProviderInfo("127.0.0.3:12200?p=11&v=4.0"),
                ProviderHelper.toProviderInfo("127.0.0.31:12200?p=11&v=4.0")))); // +1
            newMap.add(new ProviderGroup("zone3", Arrays.asList(
                ProviderHelper.toProviderInfo("127.0.0.4:12200?p=11&v=4.0")))); // -1
            newMap.add(new ProviderGroup("zone4", Arrays.asList(
                ProviderHelper.toProviderInfo("127.0.0.61:12200?p=11&v=4.0"),
                ProviderHelper.toProviderInfo("127.0.0.71:12200?p=11&v=4.0")))); // +2 -2
            newMap.add(new ProviderGroup("zone6", Arrays.asList(
                ProviderHelper.toProviderInfo("127.0.0.81:12200?p=11&v=4.0")))); // +1 -2 

            ProviderHelper.compareGroups(oldMap, newMap, add, remove);
            Assert.assertEquals(add.size(), 4);
            Assert.assertEquals(remove.size(), 5);

            Assert.assertTrue(add.contains(ProviderHelper.toProviderInfo("127.0.0.31:12200?p=11&v=4.0")));
            Assert.assertTrue(add.contains(ProviderHelper.toProviderInfo("127.0.0.61:12200?p=11&v=4.0")));
            Assert.assertTrue(add.contains(ProviderHelper.toProviderInfo("127.0.0.71:12200?p=11&v=4.0")));
            Assert.assertTrue(add.contains(ProviderHelper.toProviderInfo("127.0.0.81:12200?p=11&v=4.0")));

            Assert.assertTrue(remove.contains(ProviderHelper.toProviderInfo("127.0.0.5:12200?p=11&v=4.0")));
            Assert.assertTrue(remove.contains(ProviderHelper.toProviderInfo("127.0.0.6:12200?p=11&v=4.0")));
            Assert.assertTrue(remove.contains(ProviderHelper.toProviderInfo("127.0.0.7:12200?p=11&v=4.0")));
            Assert.assertTrue(remove.contains(ProviderHelper.toProviderInfo("127.0.0.8:12200?p=11&v=4.0")));
            Assert.assertTrue(remove.contains(ProviderHelper.toProviderInfo("127.0.0.9:12200?p=11&v=4.0")));
        }
    }
@author <a href="mailto:zhanggeng.zg@antfin.com">GengZhang</a>
core/api/src/test/java/com/alipay/sofa/rpc/client/ProviderHelperTest.java