fix: 接口用例创建的性能测试,Label显示uuid

修复接口用例创建的性能测试,Label显示uuid的问题
This commit is contained in:
song.tianyang 2021-01-27 14:33:16 +08:00
parent d1b32083da
commit 1f011e7ccc
2 changed files with 69 additions and 8 deletions

View File

@ -393,14 +393,28 @@ public class APITestController {
String jmxString = runRequest.getTestElement().getJmx(hashTree);
String testName = runRequest.getName();
//将ThreadGroup的testname改为接口名称
Document doc = DocumentHelper.parseText(jmxString);// 获取可续保保单列表报文模板
Element root = doc.getRootElement();
Element rootHashTreeElement = root.element("hashTree");
Element innerHashTreeElement = rootHashTreeElement.elements("hashTree").get(0);
Element theadGroupElement = innerHashTreeElement.elements("ThreadGroup").get(0);
theadGroupElement.attribute("testname").setText(testName);
jmxString = root.asXML();
try{
//将ThreadGroup的testname改为接口名称
Document doc = DocumentHelper.parseText(jmxString);// 获取可续保保单列表报文模板
Element root = doc.getRootElement();
Element rootHashTreeElement = root.element("hashTree");
Element innerHashTreeElement = rootHashTreeElement.elements("hashTree").get(0);
Element theadGroupElement = innerHashTreeElement.elements("ThreadGroup").get(0);
theadGroupElement.attribute("testname").setText(testName);
List<Element> thirdHashTreeElementList =innerHashTreeElement.elements("hashTree");
for (Element element:thirdHashTreeElementList) {
List<Element> sampleProxyElementList = element.elements("HTTPSamplerProxy");
for (Element itemElement: sampleProxyElementList) {
itemElement.attribute("testname").setText(testName);
}
}
jmxString = root.asXML();
}catch (Exception e){
e.printStackTrace();
}
JmxInfoDTO dto = new JmxInfoDTO();
dto.setName(runRequest.getName()+".jmx");

View File

@ -421,6 +421,53 @@ public class TestPlanReportService {
models.setPerformanceInfo(JSONArray.toJSONString(performaneReportIDList));
testPlanReportDataMapper.updateByPrimaryKeyWithBLOBs(models);
}
/**
* 虽然kafka已经设置了topic推送但是当执行机器性能不够时会影响到报告状态当修改
* 同时如果执行过程中报告删除那么此时也应当记为失败
*/
List<String> updatePerformaneReportIDList = new ArrayList<>(performaneReportIDList);
executorService.submit(() -> {
//错误数据检查集合 如果错误数据出现超过20次则取消该条数据的检查
Map<String,Integer> errorDataCheckMap = new HashMap<>();
while (performaneReportIDList.size()>0) {
List<String> selectList = new ArrayList<>(performaneReportIDList);
for (String loadTestReportId:selectList) {
LoadTestReportWithBLOBs loadTestReportFromDatabase = loadTestReportMapper.selectByPrimaryKey(loadTestReportId);
if(loadTestReportFromDatabase == null){
//检查错误数据
if(errorDataCheckMap.containsKey(loadTestReportId)){
if(errorDataCheckMap.get(loadTestReportId)>20){
performaneReportIDList.remove(loadTestReportId);
}else {
errorDataCheckMap.put(loadTestReportId,errorDataCheckMap.get(loadTestReportId)+1);
}
}else {
errorDataCheckMap.put(loadTestReportId,1);
}
}else if (StringUtils.equalsAny(loadTestReportFromDatabase.getStatus(),
PerformanceTestStatus.Completed.name(), PerformanceTestStatus.Error.name())) {
performaneReportIDList.remove(loadTestReportId);
}
}
if(performaneReportIDList.isEmpty()){
for (String string: updatePerformaneReportIDList) {
TestPlanLoadCaseEventDTO eventDTO = new TestPlanLoadCaseEventDTO();
eventDTO.setReportId(string);
eventDTO.setTriggerMode(ReportTriggerMode.SCHEDULE.name());
eventDTO.setStatus(PerformanceTestStatus.Completed.name());
this.updatePerformanceTestStatus(eventDTO);
}
}else {
try {
//查询定时任务是否关闭
Thread.sleep(1000 * 10);// 检查 loadtest 的状态
} catch (InterruptedException e) {
}
}
}
return true;
});
}
public void updatePerformanceTestStatus(TestPlanLoadCaseEventDTO eventDTO) {