refactor(测试计划执行): 优化测试计划场景的报告存储方式
优化测试计划场景的报告存储方式,并升级fit2cloud.qurtz包到0.09
This commit is contained in:
parent
23be3bf6d7
commit
6be05e2c17
|
@ -285,7 +285,7 @@
|
|||
<dependency>
|
||||
<groupId>com.fit2cloud</groupId>
|
||||
<artifactId>quartz-spring-boot-starter</artifactId>
|
||||
<version>0.0.7</version>
|
||||
<version>0.0.9</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
|
@ -29,13 +30,13 @@ import java.util.Map;
|
|||
public class TestPlanExecuteInfo {
|
||||
private String reportId;
|
||||
private String creator;
|
||||
private Map<String, String> apiCaseExecInfo = new HashMap<>();
|
||||
private Map<String, String> apiScenarioCaseExecInfo = new HashMap<>();
|
||||
private Map<String, String> loadCaseExecInfo = new HashMap<>();
|
||||
private Map<String, String> apiCaseExecInfo = new ConcurrentHashMap<>();
|
||||
private Map<String, String> apiScenarioCaseExecInfo = new ConcurrentHashMap<>();
|
||||
private Map<String, String> loadCaseExecInfo = new ConcurrentHashMap<>();
|
||||
|
||||
private Map<String, String> apiCaseExecuteThreadMap = new HashMap<>();
|
||||
private Map<String, String> apiScenarioThreadMap = new HashMap<>();
|
||||
private Map<String, String> loadCaseReportIdMap = new HashMap<>();
|
||||
private Map<String, String> apiCaseExecuteThreadMap = new ConcurrentHashMap<>();
|
||||
private Map<String, String> apiScenarioThreadMap = new ConcurrentHashMap<>();
|
||||
private Map<String, String> loadCaseReportIdMap = new ConcurrentHashMap<>();
|
||||
|
||||
private Map<String, String> apiCaseReportMap = new HashMap<>();
|
||||
private Map<String, String> apiScenarioReportMap = new HashMap<>();
|
||||
|
@ -227,7 +228,7 @@ public class TestPlanExecuteInfo {
|
|||
this.countUnFinishedNum();
|
||||
}
|
||||
|
||||
public void updateReport(Map<String, String> apiCaseExecResultInfo, Map<String, String> apiScenarioCaseExecResultInfo) {
|
||||
public synchronized void updateReport(Map<String, String> apiCaseExecResultInfo, Map<String, String> apiScenarioCaseExecResultInfo) {
|
||||
if (MapUtils.isNotEmpty(apiCaseExecResultInfo)) {
|
||||
this.apiCaseReportMap.putAll(apiCaseExecResultInfo);
|
||||
}
|
||||
|
|
|
@ -160,6 +160,8 @@ public class ApiScenarioReportService {
|
|||
LogUtil.info("从缓存中获取场景报告:【" + test.getName() + "】");
|
||||
report = MessageCache.scenarioExecResourceLock.get(test.getName());
|
||||
LogUtil.info("从缓存中获取场景报告:【" + test.getName() + "】是否为空:" + (report == null));
|
||||
} else {
|
||||
LogUtil.info("数据库中获取场景报告结束:" + report.getId());
|
||||
}
|
||||
if (report != null) {
|
||||
report.setName(report.getScenarioName() + "-" + DateUtils.getTimeStr(System.currentTimeMillis()));
|
||||
|
@ -365,7 +367,8 @@ public class ApiScenarioReportService {
|
|||
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
||||
scenarioIdList.add(testPlanApiScenario.getApiScenarioId());
|
||||
} else {
|
||||
LogUtil.info("TestPlanReport_Id is null. scenario report id : [" + report.getId() + "]; planScenarioIdArr:[" + report.getScenarioId() + "] DATA:" + JSON.toJSONString(scenarioResult));
|
||||
LogUtil.info("Cannot find TestPlanApiScenario!");
|
||||
LogUtil.error("TestPlanReport_Id is null. scenario report id : [" + report.getId() + "]; planScenarioIdArr:[" + report.getScenarioId() + "]. plan_scenario_id:" + planScenarioId + ". DATA:" + JSON.toJSONString(scenarioResult));
|
||||
}
|
||||
|
||||
report.setEndTime(System.currentTimeMillis());
|
||||
|
@ -375,17 +378,26 @@ public class ApiScenarioReportService {
|
|||
// 报告详情内容
|
||||
ApiScenarioReportDetail detail = new ApiScenarioReportDetail();
|
||||
detail.setContent(JSON.toJSONString(newResult).getBytes(StandardCharsets.UTF_8));
|
||||
detail.setReportId(report.getId());
|
||||
|
||||
detail.setProjectId(report.getProjectId());
|
||||
if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals("CASE")) {
|
||||
report.setTriggerMode(TriggerMode.MANUAL.name());
|
||||
}
|
||||
if (StringUtils.equalsIgnoreCase(report.getId(), scenarioResult.getName())) {
|
||||
detail.setReportId(report.getId());
|
||||
} else {
|
||||
detail.setReportId(scenarioResult.getName());
|
||||
LogUtil.info("ReportId" + scenarioResult.getName() + " has changed!");
|
||||
LogUtil.error("ReportId was changed. ScenarioResultData:" + JSON.toJSONString(scenarioResult) + "; ApiScenarioReport:" + JSON.toJSONString(report));
|
||||
}
|
||||
|
||||
try {
|
||||
apiScenarioReportDetailMapper.insert(detail);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error("存储场景报告出错:" + e.getMessage() + "; 步骤信息:" + JSON.toJSONString(scenarioResult));
|
||||
LogUtil.error("Save scenario report error! errorInfo:" + e.getMessage() + "; ScenarioResultData:" + JSON.toJSONString(scenarioResult));
|
||||
LogUtil.error(e);
|
||||
}
|
||||
|
||||
scenarioNames.append(report.getName()).append(",");
|
||||
// 更新场景状态
|
||||
ApiScenario scenario = apiScenarioMapper.selectByPrimaryKey(report.getScenarioId());
|
||||
|
@ -409,7 +421,7 @@ public class ApiScenarioReportService {
|
|||
MessageCache.executionQueue.remove(report.getId());
|
||||
reportIds.add(report.getId());
|
||||
} else {
|
||||
LogUtil.error("测试计划场景[" + result.getTestId() + "]的场景报告未找到。报告ID:" + scenarioResult.getName() + "。 步骤信息:" + JSON.toJSONString(scenarioResult));
|
||||
LogUtil.error("未获取到场景报告。 报告ID:" + scenarioResult.getName() + "。 步骤信息:" + JSON.toJSONString(scenarioResult));
|
||||
}
|
||||
}
|
||||
testPlanLog.info("TestPlanReportId" + JSONArray.toJSONString(testPlanReportIdList) + " EXECUTE OVER. SCENARIO STATUS : " + JSONObject.toJSONString(scenarioAndErrorMap));
|
||||
|
|
Loading…
Reference in New Issue