fix(接口测试): 场景导出JMX时host转换增加带端口号域名的解析

场景导出JMX时host转换增加带端口号域名的解析
This commit is contained in:
song-tianyang 2022-05-18 20:24:23 +08:00 committed by f2c-ci-robot[bot]
parent e606f28c1c
commit fb9f992b60
2 changed files with 38 additions and 24 deletions

View File

@ -76,6 +76,8 @@ public class MsDNSCacheManager extends MsTestElement {
String hostDomain = host.getDomain().trim().replace("http://", "").replace("https://", "");
if (StringUtils.equals(hostDomain, domain)) {
dnsMap.put(hostDomain, host.getIp());
}else if(StringUtils.startsWith(hostDomain,domain+":")){
dnsMap.put(domain,StringUtils.replace(hostDomain,domain,host.getIp()));
}
}
});

View File

@ -219,9 +219,21 @@ public class MsHTTPSamplerProxy extends MsTestElement {
Map<String, String> dnsMap = MsDNSCacheManager.getEnvironmentDns(config.getConfig().get(this.getProjectId()), httpConfig);
String domain = sampler.getDomain();
if (dnsMap.containsKey(domain)) {
String address = dnsMap.get(domain);
if (address.contains(":")) {
String[] addressArr = StringUtils.split(address, ":");
if (addressArr.length == 2) {
try {
sampler.setDomain(addressArr[0]);
sampler.setPort(Integer.parseInt(addressArr[1]));
} catch (Exception ignored) {
}
}
} else {
sampler.setDomain(dnsMap.get(domain));
}
}
}
final HashTree httpSamplerTree = tree.add(sampler);
// 注意顺序放在config前面会优先于环境的请求头生效