diff --git a/backend/pom.xml b/backend/pom.xml index 4c5e39820b..d6faed4176 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -285,7 +285,7 @@ com.fit2cloud quartz-spring-boot-starter - 0.0.7 + 0.0.9 diff --git a/backend/src/main/java/io/metersphere/api/cache/TestPlanExecuteInfo.java b/backend/src/main/java/io/metersphere/api/cache/TestPlanExecuteInfo.java index d6c3cf79dc..6e750fbc6f 100644 --- a/backend/src/main/java/io/metersphere/api/cache/TestPlanExecuteInfo.java +++ b/backend/src/main/java/io/metersphere/api/cache/TestPlanExecuteInfo.java @@ -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 apiCaseExecInfo = new HashMap<>(); - private Map apiScenarioCaseExecInfo = new HashMap<>(); - private Map loadCaseExecInfo = new HashMap<>(); + private Map apiCaseExecInfo = new ConcurrentHashMap<>(); + private Map apiScenarioCaseExecInfo = new ConcurrentHashMap<>(); + private Map loadCaseExecInfo = new ConcurrentHashMap<>(); - private Map apiCaseExecuteThreadMap = new HashMap<>(); - private Map apiScenarioThreadMap = new HashMap<>(); - private Map loadCaseReportIdMap = new HashMap<>(); + private Map apiCaseExecuteThreadMap = new ConcurrentHashMap<>(); + private Map apiScenarioThreadMap = new ConcurrentHashMap<>(); + private Map loadCaseReportIdMap = new ConcurrentHashMap<>(); private Map apiCaseReportMap = new HashMap<>(); private Map apiScenarioReportMap = new HashMap<>(); @@ -227,7 +228,7 @@ public class TestPlanExecuteInfo { this.countUnFinishedNum(); } - public void updateReport(Map apiCaseExecResultInfo, Map apiScenarioCaseExecResultInfo) { + public synchronized void updateReport(Map apiCaseExecResultInfo, Map apiScenarioCaseExecResultInfo) { if (MapUtils.isNotEmpty(apiCaseExecResultInfo)) { this.apiCaseReportMap.putAll(apiCaseExecResultInfo); } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 990747f5db..b381288873 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -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));