Skip to content

Commit

Permalink
fix: 接口用例创建的性能测试,Label显示uuid
Browse files Browse the repository at this point in the history
修复接口用例创建的性能测试,Label显示uuid的问题
  • Loading branch information
Somebody-JIAN committed Jan 27, 2021
1 parent d1b3208 commit 1f011e7
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,28 @@ public JmxInfoDTO genPerformanceTest(@RequestPart("request") RunDefinitionReques
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,53 @@ public void updatePerformanceInfo(TestPlanReport testPlanReport, List<String> pe
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) {
Expand Down

0 comments on commit 1f011e7

Please sign in to comment.