@Test
public void parseProviderInfo() throws Exception {

    String defaultProtocol = RpcConfigs.getStringValue(RpcOptions.DEFAULT_PROTOCOL);
    // 10.244.22.1:8080?zone=GZ00A&self_app_name=icardcenter&app_name=icardcenter&_TIMEOUT=3000
    // 11.166.0.239:12200?_TIMEOUT=3000&p=1&_SERIALIZETYPE=hessian2&app_name=iptcore&zone=GZ00A&_IDLETIMEOUT=27&_MAXREADIDLETIME=30&v=4.0
    // 10.209.76.82:12200?_TIMEOUT=3000&p=1&_SERIALIZETYPE=hessian2&app_name=ipayprocess&zone=GZ00A&_IDLETIMEOUT=27&_MAXREADIDLETIME=30&v=4.0
    // 10.15.232.229:55555?_CONNECTIONNUM=1&v=4.0&_SERIALIZETYPE=4&app_name=test&p=1&_TIMEOUT=4000
    // 10.15.232.229:12222?_TIMEOUT=3333&p=1&_SERIALIZETYPE=4&_CONNECTIONNUM=1&_WARMUPTIME=60000&_WARMUPWEIGHT=5&app_name=test-server&v=4.0&_WEIGHT=2000&[cd]=[clientTimeout#5555]&[echoStr]=[timeout#4444]
    // [xxxx]=[clientTimeout#2000@retries#2]
    // [xxxx]=[_AUTORECONNECT#false@_TIMEOUT#2000]
    String url = "10.244.22.1:8080?zone=GZ00A&self_app_name=icardcenter&app_name=icardcenter&_TIMEOUT=3000";
    ProviderInfo provider = SofaRegistryHelper.parseProviderInfo(url);
    Assert.assertTrue(defaultProtocol.equals(provider.getProtocolType()));
    Assert.assertTrue("10.244.22.1".equals(provider.getHost()));
    Assert.assertTrue(provider.getPort() == 8080);
    Assert.assertTrue("GZ00A".equals(provider.getAttr("zone")));
    Assert.assertTrue("icardcenter".equals(provider.getAttr(ProviderInfoAttrs.ATTR_APP_NAME)));
    Assert.assertTrue((Integer) provider.getDynamicAttr(ProviderInfoAttrs.ATTR_TIMEOUT) == 3000);
    url = "11.166.0.239:12200?_TIMEOUT=3000&p=1&_SERIALIZETYPE=hessian2&app_name=iptcore&zone=GZ00B&_IDLETIMEOUT=27&_MAXREADIDLETIME=30&v=4.0";
    provider = SofaRegistryHelper.parseProviderInfo(url);
    Assert.assertTrue(RpcConstants.PROTOCOL_TYPE_BOLT.equals(provider.getProtocolType()));
    Assert.assertTrue(RpcConstants.SERIALIZE_HESSIAN2.equals(provider.getSerializationType()));
    Assert.assertTrue("11.166.0.239".equals(provider.getHost()));
    Assert.assertTrue(provider.getPort() == 12200);
    Assert.assertTrue("GZ00B".equals(provider.getAttr("zone")));
    Assert.assertTrue("iptcore".equals(provider.getAttr(ProviderInfoAttrs.ATTR_APP_NAME)));
    Assert.assertTrue("27".equals(provider.getAttr("_IDLETIMEOUT")));
    Assert.assertTrue("30".equals(provider.getAttr("_MAXREADIDLETIME")));
    Assert.assertTrue("4.0".equals(provider.getAttr("v")));
    Assert.assertTrue("1".equals(provider.getAttr("p")));
    url = "10.209.80.104:12200?zone=GZ00A&self_app_name=icif&_SERIALIZETYPE=java&app_name=icif&_TIMEOUT=3000";
    provider = SofaRegistryHelper.parseProviderInfo(url);
    Assert.assertTrue(defaultProtocol.equals(provider.getProtocolType()));
    Assert.assertTrue(RpcConstants.SERIALIZE_JAVA.equals(provider.getSerializationType()));
    Assert.assertTrue("10.209.80.104".equals(provider.getHost()));
    Assert.assertTrue(provider.getPort() == 12200);
    Assert.assertTrue("GZ00A".equals(provider.getAttr("zone")));
    Assert.assertTrue("icif".equals(provider.getAttr(ProviderInfoAttrs.ATTR_APP_NAME)));
    Assert.assertTrue((Integer) provider.getDynamicAttr(ProviderInfoAttrs.ATTR_TIMEOUT) == 3000);
    Assert.assertTrue(provider.getAttr("v") == null);
    Assert.assertTrue(provider.getAttr("p") == null);
    url = "10.209.76.82:12200?_TIMEOUT=3000&p=13&_SERIALIZETYPE=11&app_name=ipayprocess&zone=GZ00A&_IDLETIMEOUT=27&_MAXREADIDLETIME=30&v=4.0&[xx]=[_AUTORECONNECT#false@_TIMEOUT#2000]";
    provider = SofaRegistryHelper.parseProviderInfo(url);
    Assert.assertTrue(RpcConstants.PROTOCOL_TYPE_TR.equals(provider.getProtocolType()));
    Assert.assertTrue(RpcConstants.SERIALIZE_PROTOBUF.equals(provider.getSerializationType()));
    Assert.assertTrue("10.209.76.82".equals(provider.getHost()));
    Assert.assertTrue(provider.getPort() == 12200);
    Assert.assertTrue("GZ00A".equals(provider.getAttr("zone")));
    Assert.assertTrue("ipayprocess".equals(provider.getAttr(ProviderInfoAttrs.ATTR_APP_NAME)));
    Assert.assertTrue((Integer) provider.getDynamicAttr(ProviderInfoAttrs.ATTR_TIMEOUT) == 3000);
    Assert.assertTrue("27".equals(provider.getAttr("_IDLETIMEOUT")));
    Assert.assertTrue("30".equals(provider.getAttr("_MAXREADIDLETIME")));
    Assert.assertTrue("4.0".equals(provider.getAttr("v")));
    Assert.assertTrue("13".equals(provider.getAttr("p")));
    Assert.assertTrue((Integer) provider.getDynamicAttr(".xx.timeout") == 2000);
    Assert.assertTrue("false".equals(provider.getAttr(".xx._AUTORECONNECT")));
    url = "tri://10.15.232.229:55555?_CONNECTIONNUM=1&v=4.0&_SERIALIZETYPE=11&app_name=test&p=1&_TIMEOUT=4000";
    provider = SofaRegistryHelper.parseProviderInfo(url);
    Assert.assertTrue(RpcConstants.PROTOCOL_TYPE_TRIPLE.equals(provider.getProtocolType()));
    Assert.assertTrue(RpcConstants.SERIALIZE_PROTOBUF.equals(provider.getSerializationType()));
    Assert.assertTrue("10.15.232.229".equals(provider.getHost()));
    Assert.assertTrue(provider.getPort() == 55555);
    Assert.assertTrue("test".equals(provider.getAttr(ProviderInfoAttrs.ATTR_APP_NAME)));
    Assert.assertTrue("1".equals(provider.getAttr(ProviderInfoAttrs.ATTR_CONNECTIONS)));
    Assert.assertTrue((Integer) provider.getDynamicAttr(ProviderInfoAttrs.ATTR_TIMEOUT) == 4000);
    Assert.assertTrue("4.0".equals(provider.getAttr("v")));
    Assert.assertTrue("1".equals(provider.getAttr("p")));
    url = "10.15.232.229:12222?_TIMEOUT=3333&p=1&_SERIALIZETYPE=4&_CONNECTIONNUM=1&_WARMUPTIME=6&_WARMUPWEIGHT=5&app_name=test-server&v=4.0&_WEIGHT=2000&[cd]=[]&[echoStr]=[clientTimeout#4444]";
    provider = SofaRegistryHelper.parseProviderInfo(url);
    Assert.assertTrue(RpcConstants.PROTOCOL_TYPE_BOLT.equals(provider.getProtocolType()));
    Assert.assertTrue(RpcConstants.SERIALIZE_HESSIAN2.equals(provider.getSerializationType()));
    Assert.assertTrue("10.15.232.229".equals(provider.getHost()));
    Assert.assertTrue(provider.getPort() == 12222);
    Assert.assertTrue("test-server".equals(provider.getAttr(ProviderInfoAttrs.ATTR_APP_NAME)));
    Assert.assertTrue("1".equals(provider.getAttr(ProviderInfoAttrs.ATTR_CONNECTIONS)));
    Assert.assertTrue((Integer) provider.getDynamicAttr(ProviderInfoAttrs.ATTR_TIMEOUT) == 3333);
    Assert.assertTrue((Integer) provider.getDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT) == 5);
    Assert.assertTrue(provider.getDynamicAttr(ProviderInfoAttrs.ATTR_WARM_UP_END_TIME) != null);
    Assert.assertEquals(provider.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT), "5");
    Assert.assertEquals(provider.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_TIME), "6");
    Assert.assertTrue(provider.getWeight() == 5);
    Assert.assertTrue(provider.getStatus() == ProviderStatus.WARMING_UP);
    try {
        Thread.sleep(10);
    } catch (Exception e) {
    }
    Assert.assertTrue(provider.getWeight() == 2000);
    Assert.assertTrue(provider.getStatus() == ProviderStatus.AVAILABLE);
    Assert.assertTrue(provider.getDynamicAttr(ProviderInfoAttrs.ATTR_WARM_UP_END_TIME) == null);
    Assert.assertTrue("4.0".equals(provider.getAttr("v")));
    Assert.assertTrue("1".equals(provider.getAttr("p")));
    Assert.assertTrue(provider.getAttr(".cd.timeout") == null);
    Assert.assertTrue((Integer) provider.getDynamicAttr(".echoStr.timeout") == 4444);
    url = "10.15.232.229:12222?_TIMEOUT=3333&p=1&_SERIALIZETYPE=4&_CONNECTIONNUM=1&_WARMUPTIME=6&_WARMUPWEIGHT=5&startTime=123456";
    provider = SofaRegistryHelper.parseProviderInfo(url);
    Assert.assertTrue((Integer) provider.getDynamicAttr(ProviderInfoAttrs.ATTR_TIMEOUT) == 3333);
    Assert.assertTrue((Integer) provider.getDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT) == 5);
    Assert.assertTrue(provider.getDynamicAttr(ProviderInfoAttrs.ATTR_WARM_UP_END_TIME) != null);
    Assert.assertEquals(provider.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT), "5");
    Assert.assertEquals(provider.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_TIME), "6");
    Assert.assertTrue(provider.getWeight() == 100);
    Assert.assertTrue(provider.getStatus() == ProviderStatus.AVAILABLE);
    url = "bolt://10.244.22.1:8080?zone=GZ00A&appName=icardcenter&timeout=3000&serialization=hessian2";
    provider = SofaRegistryHelper.parseProviderInfo(url);
    Assert.assertTrue(RpcConstants.PROTOCOL_TYPE_BOLT.equals(provider.getProtocolType()));
    Assert.assertTrue(RpcConstants.SERIALIZE_HESSIAN2.equals(provider.getSerializationType()));
    Assert.assertTrue("10.244.22.1".equals(provider.getHost()));
    Assert.assertTrue(provider.getPort() == 8080);
    Assert.assertTrue("GZ00A".equals(provider.getAttr("zone")));
    Assert.assertTrue("icardcenter".equals(provider.getAttr(ProviderInfoAttrs.ATTR_APP_NAME)));
    Assert.assertTrue((Integer) provider.getDynamicAttr(ProviderInfoAttrs.ATTR_TIMEOUT) == 3000);
}