@Test
    public void testHashCode() throws Exception {
        ProviderInfo p1 = new ProviderInfo();
        ProviderInfo p2 = new ProviderInfo();

        p1.setHost("127.0.0.1");
        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        p2.setHost("127.0.0.2");
        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        p2.setHost("127.0.0.1");
        Assert.assertTrue(p1.hashCode() == p2.hashCode());

        p1.setPort(12200);
        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        p2.setPort(12201);
        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        p2.setPort(12200);
        Assert.assertTrue(p1.hashCode() == p2.hashCode());

        p1.setRpcVersion(4420);
        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        p2.setRpcVersion(4421);
        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        p2.setRpcVersion(4420);
        Assert.assertTrue(p1.hashCode() == p2.hashCode());

        p1.setProtocolType("p1");
        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        p2.setProtocolType("p2");
        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        p2.setProtocolType("p1");
        Assert.assertTrue(p1.hashCode() == p2.hashCode());

        p1.setSerializationType("zzz");
        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        p2.setSerializationType("yyy");
        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        p2.setSerializationType("zzz");
        Assert.assertTrue(p1.hashCode() == p2.hashCode());

        //        p1.setInterfaceId("com.xxx");
        //        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        //        p2.setInterfaceId("com.yyy");
        //        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        //        p2.setInterfaceId("com.xxx");
        //        Assert.assertTrue(p1.hashCode() == p2.hashCode());
        //
        //        p1.setUniqueId("u1");
        //        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        //        p2.setUniqueId("u2");
        //        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        //        p2.setUniqueId("u1");
        //        Assert.assertTrue(p1.hashCode() == p2.hashCode());

        p1.setPath("/aaa");
        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        p2.setPath("/bbb");
        Assert.assertFalse(p1.hashCode() == p2.hashCode());
        p2.setPath("/aaa");
        Assert.assertTrue(p1.hashCode() == p2.hashCode());

        p1.setWeight(200);
        Assert.assertTrue(p1.hashCode() == p2.hashCode());
        p2.setWeight(300);
        Assert.assertTrue(p1.hashCode() == p2.hashCode());
        p2.setWeight(200);
        Assert.assertTrue(p1.hashCode() == p2.hashCode());

        p1.setDynamicAttr("x1", "y1");
        Assert.assertTrue(p1.hashCode() == p2.hashCode());
        p2.setDynamicAttr("x1", "y1");
        Assert.assertTrue(p1.hashCode() == p2.hashCode());
        p2.setDynamicAttr("x2", "y2");
        Assert.assertTrue(p1.hashCode() == p2.hashCode());

        p1.setStaticAttr("x1", "y1");
        Assert.assertTrue(p1.hashCode() == p2.hashCode());
        p2.setStaticAttr("x1", "y1");
        Assert.assertTrue(p1.hashCode() == p2.hashCode());
        p1.setStaticAttr("x2", "y2");
        Assert.assertTrue(p1.hashCode() == p2.hashCode());
        p2.setStaticAttr("x2", "y2");
        Assert.assertTrue(p1.hashCode() == p2.hashCode());

        List<ProviderInfo> ps = new ArrayList<ProviderInfo>();
        ps.add(p1);
        ps.remove(p2);
        Assert.assertEquals(ps.size(), 0);

        Set<ProviderInfo> set = new HashSet<ProviderInfo>();
        set.add(p1);
        set.add(p2);
        Assert.assertEquals(set.size(), 1);
        set.remove(p2);
        Assert.assertEquals(set.size(), 0);

        Map<ProviderInfo, String> map = new HashMap<ProviderInfo, String>();
        map.put(p1, "xx");
        map.put(p2, "yy");
        Assert.assertEquals(map.get(p1), "yy");
        map.remove(p2);
        Assert.assertEquals(map.size(), 0);
    }
@author <a href="mailto:zhanggeng.zg@antfin.com">GengZhang</a>
core/api/src/test/java/com/alipay/sofa/rpc/client/ProviderInfoTest.java