@Test public void toUrl() throws Exception { { String src = "10.15.233.114:12200"; ProviderInfo providerInfo = ProviderHelper.toProviderInfo(src); Assert.assertEquals(providerInfo.getHost(), "10.15.233.114"); Assert.assertEquals(providerInfo.getPort(), 12200); Assert.assertEquals(providerInfo.getPath(), StringUtils.EMPTY); Assert.assertEquals(ProviderHelper.toUrl(providerInfo), providerInfo.getProtocolType() + ": } { String src = "10.15.233.114:12200/"; ProviderInfo providerInfo = ProviderHelper.toProviderInfo(src); Assert.assertEquals(providerInfo.getHost(), "10.15.233.114"); Assert.assertEquals(providerInfo.getPort(), 12200); Assert.assertEquals(providerInfo.getPath(), StringUtils.CONTEXT_SEP); Assert.assertEquals(ProviderHelper.toUrl(providerInfo), providerInfo.getProtocolType() + ": } { String src = "bolt: ProviderInfo providerInfo = ProviderHelper.toProviderInfo(src); Assert.assertEquals(providerInfo.getProtocolType(), "bolt"); Assert.assertEquals(providerInfo.getHost(), "10.15.233.114"); Assert.assertEquals(providerInfo.getPort(), 12200); Assert.assertEquals(providerInfo.getPath(), StringUtils.EMPTY); Assert.assertEquals(ProviderHelper.toUrl(providerInfo), src); } { String src = "bolt: ProviderInfo providerInfo = ProviderHelper.toProviderInfo(src); Assert.assertEquals(providerInfo.getProtocolType(), "bolt"); Assert.assertEquals(providerInfo.getHost(), "10.15.233.114"); Assert.assertEquals(providerInfo.getPort(), 12200); Assert.assertEquals(providerInfo.getPath(), StringUtils.CONTEXT_SEP); Assert.assertEquals(ProviderHelper.toUrl(providerInfo), src); } { String src = "bolt: ProviderInfo providerInfo = ProviderHelper.toProviderInfo(src); Assert.assertEquals(providerInfo.getProtocolType(), "bolt"); Assert.assertEquals(providerInfo.getHost(), "10.15.233.114"); Assert.assertEquals(providerInfo.getPort(), 12200); Assert.assertEquals(providerInfo.getPath(), StringUtils.EMPTY); Assert.assertEquals(providerInfo.getWeight(), 222); Assert.assertEquals(providerInfo.getSerializationType(), "hessian2"); Assert.assertEquals(ProviderHelper.toProviderInfo(ProviderHelper.toUrl(providerInfo)), providerInfo); } { String src = "bolt: ProviderInfo providerInfo = ProviderHelper.toProviderInfo(src); Assert.assertEquals(providerInfo.getProtocolType(), "bolt"); Assert.assertEquals(providerInfo.getHost(), "10.15.233.114"); Assert.assertEquals(providerInfo.getPort(), 12200); Assert.assertEquals(providerInfo.getPath(), StringUtils.CONTEXT_SEP); Assert.assertEquals(providerInfo.getWeight(), 222); Assert.assertEquals(providerInfo.getSerializationType(), "hessian2"); Assert.assertEquals(ProviderHelper.toProviderInfo(ProviderHelper.toUrl(providerInfo)), providerInfo); } }
public static String toUrl(ProviderInfo providerInfo) { String uri = providerInfo.getProtocolType() + ": uri += StringUtils.trimToEmpty(providerInfo.getPath()); StringBuilder sb = new StringBuilder(); if (providerInfo.getRpcVersion() > 0) { sb.append("&").append(ProviderInfoAttrs.ATTR_RPC_VERSION).append("=").append(providerInfo.getRpcVersion()); } if (providerInfo.getSerializationType() != null) { sb.append("&").append(ProviderInfoAttrs.ATTR_SERIALIZATION).append("=") .append(providerInfo.getSerializationType()); } for (Map.Entry<String, String> entry : providerInfo.getStaticAttrs().entrySet()) { sb.append("&").append(entry.getKey()).append("=").append(entry.getValue()); } if (sb.length() > 0) { uri += sb.replace(0, 1, "?").toString(); } return uri; }
ProviderHelper { public static String toUrl(ProviderInfo providerInfo) { String uri = providerInfo.getProtocolType() + ": uri += StringUtils.trimToEmpty(providerInfo.getPath()); StringBuilder sb = new StringBuilder(); if (providerInfo.getRpcVersion() > 0) { sb.append("&").append(ProviderInfoAttrs.ATTR_RPC_VERSION).append("=").append(providerInfo.getRpcVersion()); } if (providerInfo.getSerializationType() != null) { sb.append("&").append(ProviderInfoAttrs.ATTR_SERIALIZATION).append("=") .append(providerInfo.getSerializationType()); } for (Map.Entry<String, String> entry : providerInfo.getStaticAttrs().entrySet()) { sb.append("&").append(entry.getKey()).append("=").append(entry.getValue()); } if (sb.length() > 0) { uri += sb.replace(0, 1, "?").toString(); } return uri; } }
ProviderHelper { public static String toUrl(ProviderInfo providerInfo) { String uri = providerInfo.getProtocolType() + ": uri += StringUtils.trimToEmpty(providerInfo.getPath()); StringBuilder sb = new StringBuilder(); if (providerInfo.getRpcVersion() > 0) { sb.append("&").append(ProviderInfoAttrs.ATTR_RPC_VERSION).append("=").append(providerInfo.getRpcVersion()); } if (providerInfo.getSerializationType() != null) { sb.append("&").append(ProviderInfoAttrs.ATTR_SERIALIZATION).append("=") .append(providerInfo.getSerializationType()); } for (Map.Entry<String, String> entry : providerInfo.getStaticAttrs().entrySet()) { sb.append("&").append(entry.getKey()).append("=").append(entry.getValue()); } if (sb.length() > 0) { uri += sb.replace(0, 1, "?").toString(); } return uri; }  }
ProviderHelper { public static String toUrl(ProviderInfo providerInfo) { String uri = providerInfo.getProtocolType() + ": uri += StringUtils.trimToEmpty(providerInfo.getPath()); StringBuilder sb = new StringBuilder(); if (providerInfo.getRpcVersion() > 0) { sb.append("&").append(ProviderInfoAttrs.ATTR_RPC_VERSION).append("=").append(providerInfo.getRpcVersion()); } if (providerInfo.getSerializationType() != null) { sb.append("&").append(ProviderInfoAttrs.ATTR_SERIALIZATION).append("=") .append(providerInfo.getSerializationType()); } for (Map.Entry<String, String> entry : providerInfo.getStaticAttrs().entrySet()) { sb.append("&").append(entry.getKey()).append("=").append(entry.getValue()); } if (sb.length() > 0) { uri += sb.replace(0, 1, "?").toString(); } return uri; }  static void compareGroup(ProviderGroup oldGroup, ProviderGroup newGroup,
                                    List<ProviderInfo> add, List<ProviderInfo> remove); static void compareProviders(List<ProviderInfo> oldList, List<ProviderInfo> newList,
                                        List<ProviderInfo> add, List<ProviderInfo> remove); static void compareGroups(List<ProviderGroup> oldGroups, List<ProviderGroup> newGroups,
                                     List<ProviderInfo> add,
                                     List<ProviderInfo> remove); static boolean isEmpty(ProviderGroup group); static String toUrl(ProviderInfo providerInfo); static ProviderInfo toProviderInfo(String url); }
ProviderHelper { public static String toUrl(ProviderInfo providerInfo) { String uri = providerInfo.getProtocolType() + ": uri += StringUtils.trimToEmpty(providerInfo.getPath()); StringBuilder sb = new StringBuilder(); if (providerInfo.getRpcVersion() > 0) { sb.append("&").append(ProviderInfoAttrs.ATTR_RPC_VERSION).append("=").append(providerInfo.getRpcVersion()); } if (providerInfo.getSerializationType() != null) { sb.append("&").append(ProviderInfoAttrs.ATTR_SERIALIZATION).append("=") .append(providerInfo.getSerializationType()); } for (Map.Entry<String, String> entry : providerInfo.getStaticAttrs().entrySet()) { sb.append("&").append(entry.getKey()).append("=").append(entry.getValue()); } if (sb.length() > 0) { uri += sb.replace(0, 1, "?").toString(); } return uri; }  static void compareGroup(ProviderGroup oldGroup, ProviderGroup newGroup,
                                    List<ProviderInfo> add, List<ProviderInfo> remove); static void compareProviders(List<ProviderInfo> oldList, List<ProviderInfo> newList,
                                        List<ProviderInfo> add, List<ProviderInfo> remove); static void compareGroups(List<ProviderGroup> oldGroups, List<ProviderGroup> newGroups,
                                     List<ProviderInfo> add,
                                     List<ProviderInfo> remove); static boolean isEmpty(ProviderGroup group); static String toUrl(ProviderInfo providerInfo); static ProviderInfo toProviderInfo(String url);  }