fix(测试跟踪): 批量执行测试计划重构,解决重复键问题

--user=郭雨琦
批量执行测试计划重构,解决重复键问题,增加批次,排序属性
This commit is contained in:
guoyuqi 2022-04-14 16:36:00 +08:00 committed by 刘瑞斌
parent 777afe6bc5
commit 5efce8644a
14 changed files with 354 additions and 119 deletions

View File

@ -15,5 +15,9 @@ public class TestPlanExecutionQueue implements Serializable {
private String testPlanId;
private String resourceId;
private Integer num;
private static final long serialVersionUID = 1L;
}

View File

@ -443,6 +443,136 @@ public class TestPlanExecutionQueueExample {
addCriterion("test_plan_id not between", value1, value2, "testPlanId");
return (Criteria) this;
}
public Criteria andResourceIdIsNull() {
addCriterion("resource_id is null");
return (Criteria) this;
}
public Criteria andResourceIdIsNotNull() {
addCriterion("resource_id is not null");
return (Criteria) this;
}
public Criteria andResourceIdEqualTo(String value) {
addCriterion("resource_id =", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotEqualTo(String value) {
addCriterion("resource_id <>", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdGreaterThan(String value) {
addCriterion("resource_id >", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdGreaterThanOrEqualTo(String value) {
addCriterion("resource_id >=", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdLessThan(String value) {
addCriterion("resource_id <", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdLessThanOrEqualTo(String value) {
addCriterion("resource_id <=", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdLike(String value) {
addCriterion("resource_id like", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotLike(String value) {
addCriterion("resource_id not like", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdIn(List<String> values) {
addCriterion("resource_id in", values, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotIn(List<String> values) {
addCriterion("resource_id not in", values, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdBetween(String value1, String value2) {
addCriterion("resource_id between", value1, value2, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotBetween(String value1, String value2) {
addCriterion("resource_id not between", value1, value2, "resourceId");
return (Criteria) this;
}
public Criteria andNumIsNull() {
addCriterion("num is null");
return (Criteria) this;
}
public Criteria andNumIsNotNull() {
addCriterion("num is not null");
return (Criteria) this;
}
public Criteria andNumEqualTo(Integer value) {
addCriterion("num =", value, "num");
return (Criteria) this;
}
public Criteria andNumNotEqualTo(Integer value) {
addCriterion("num <>", value, "num");
return (Criteria) this;
}
public Criteria andNumGreaterThan(Integer value) {
addCriterion("num >", value, "num");
return (Criteria) this;
}
public Criteria andNumGreaterThanOrEqualTo(Integer value) {
addCriterion("num >=", value, "num");
return (Criteria) this;
}
public Criteria andNumLessThan(Integer value) {
addCriterion("num <", value, "num");
return (Criteria) this;
}
public Criteria andNumLessThanOrEqualTo(Integer value) {
addCriterion("num <=", value, "num");
return (Criteria) this;
}
public Criteria andNumIn(List<Integer> values) {
addCriterion("num in", values, "num");
return (Criteria) this;
}
public Criteria andNumNotIn(List<Integer> values) {
addCriterion("num not in", values, "num");
return (Criteria) this;
}
public Criteria andNumBetween(Integer value1, Integer value2) {
addCriterion("num between", value1, value2, "num");
return (Criteria) this;
}
public Criteria andNumNotBetween(Integer value1, Integer value2) {
addCriterion("num not between", value1, value2, "num");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -7,6 +7,8 @@
<result column="run_mode" jdbcType="VARCHAR" property="runMode" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="test_plan_id" jdbcType="VARCHAR" property="testPlanId" />
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
<result column="num" jdbcType="INTEGER" property="num" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -67,7 +69,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, report_id, run_mode, create_time, test_plan_id
id, report_id, run_mode, create_time, test_plan_id, resource_id, num
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.TestPlanExecutionQueueExample" resultMap="BaseResultMap">
select
@ -101,9 +103,11 @@
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.TestPlanExecutionQueue">
insert into test_plan_execution_queue (id, report_id, run_mode,
create_time, test_plan_id)
create_time, test_plan_id, resource_id,
num)
values (#{id,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, #{runMode,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{testPlanId,jdbcType=VARCHAR})
#{createTime,jdbcType=BIGINT}, #{testPlanId,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR},
#{num,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.TestPlanExecutionQueue">
insert into test_plan_execution_queue
@ -123,6 +127,12 @@
<if test="testPlanId != null">
test_plan_id,
</if>
<if test="resourceId != null">
resource_id,
</if>
<if test="num != null">
num,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -140,6 +150,12 @@
<if test="testPlanId != null">
#{testPlanId,jdbcType=VARCHAR},
</if>
<if test="resourceId != null">
#{resourceId,jdbcType=VARCHAR},
</if>
<if test="num != null">
#{num,jdbcType=INTEGER},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.TestPlanExecutionQueueExample" resultType="java.lang.Long">
@ -166,6 +182,12 @@
<if test="record.testPlanId != null">
test_plan_id = #{record.testPlanId,jdbcType=VARCHAR},
</if>
<if test="record.resourceId != null">
resource_id = #{record.resourceId,jdbcType=VARCHAR},
</if>
<if test="record.num != null">
num = #{record.num,jdbcType=INTEGER},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -177,7 +199,9 @@
report_id = #{record.reportId,jdbcType=VARCHAR},
run_mode = #{record.runMode,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
test_plan_id = #{record.testPlanId,jdbcType=VARCHAR}
test_plan_id = #{record.testPlanId,jdbcType=VARCHAR},
resource_id = #{record.resourceId,jdbcType=VARCHAR},
num = #{record.num,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -197,6 +221,12 @@
<if test="testPlanId != null">
test_plan_id = #{testPlanId,jdbcType=VARCHAR},
</if>
<if test="resourceId != null">
resource_id = #{resourceId,jdbcType=VARCHAR},
</if>
<if test="num != null">
num = #{num,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -205,7 +235,9 @@
set report_id = #{reportId,jdbcType=VARCHAR},
run_mode = #{runMode,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
test_plan_id = #{testPlanId,jdbcType=VARCHAR}
test_plan_id = #{testPlanId,jdbcType=VARCHAR},
resource_id = #{resourceId,jdbcType=VARCHAR},
num = #{num,jdbcType=INTEGER}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -1,7 +1,9 @@
package io.metersphere.base.mapper.ext;
import io.metersphere.base.domain.ApiDefinition;
import io.metersphere.base.domain.TestPlanExecutionQueue;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -9,4 +11,6 @@ public interface ExtTestPlanExecutionQueueMapper {
@InsertProvider(type = ExtTestPlanExecutionQueueProvider.class, method = "insertListSql")
void sqlInsert(List<TestPlanExecutionQueue> list);
TestPlanExecutionQueue getNextNum(@Param("resourceId") String resourceId);
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.ext.ExtTestPlanExecutionQueueMapper">
<select id="getNextNum" resultType="io.metersphere.base.domain.TestPlanExecutionQueue">
SELECT * FROM test_plan_execution_queue WHERE test_plan_execution_queue.resource_id = #{resourceId} ORDER BY num DESC LIMIT 1;
</select>
</mapper>

View File

@ -7,7 +7,7 @@ import java.util.List;
public class ExtTestPlanExecutionQueueProvider {
public String insertListSql(List<TestPlanExecutionQueue> list) {
StringBuffer sqlList = new StringBuffer();
sqlList.append("insert into test_plan_execution_queue (id,report_id, run_mode, create_time, test_plan_id) values ");
sqlList.append("insert into test_plan_execution_queue (id,report_id, run_mode, create_time, test_plan_id, resource_id, num) values ");
for (int i = 0; i < list.size(); i++) {
TestPlanExecutionQueue result = list.get(i);
sqlList.append(" (")
@ -21,7 +21,10 @@ public class ExtTestPlanExecutionQueueProvider {
.append(result.getCreateTime())
.append("','")
.append(result.getTestPlanId())
.append("'")
.append("','")
.append(result.getResourceId())
.append("',")
.append(result.getNum())
.append(")");
if (i < list.size() - 1) {
sqlList.append(",");

View File

@ -10,7 +10,6 @@ import io.metersphere.base.domain.*;
import io.metersphere.commons.constants.*;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.dto.MsExecResponseDTO;
import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.notice.annotation.SendNotice;
import io.metersphere.service.CheckPermissionService;
@ -229,9 +228,9 @@ public class TestPlanController {
@PostMapping(value = "/run/batch")
@MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.ids)", msClass = TestPlanService.class)
public List<MsExecResponseDTO> runBatch(@RequestBody TestplanRunRequest request) {
public void runBatch(@RequestBody TestplanRunRequest request) {
request.setTriggerMode(TriggerMode.BATCH.name());
return testPlanService.runBatch(request);
testPlanService.runBatch(request);
}
@GetMapping("/report/export/{planId}")

View File

@ -1,11 +1,9 @@
package io.metersphere.track.dto;
import io.metersphere.base.domain.TestPlanReport;
import io.metersphere.base.domain.TestPlanReportContent;
import lombok.Getter;
import lombok.Setter;
import java.util.LinkedHashMap;
import java.util.Map;
/**
@ -16,7 +14,7 @@ import java.util.Map;
@Setter
public class TestPlanScheduleReportInfoDTO {
private TestPlanReport testPlanReport;
private Map<String, String> planScenarioIdMap = new LinkedHashMap<>();
private Map<String, String> apiTestCaseDataMap = new LinkedHashMap<>();
private Map<String, String> performanceIdMap = new LinkedHashMap<>();
private Map<String, String> planScenarioIdMap;
private Map<String, String> apiTestCaseDataMap;
private Map<String, String> performanceIdMap;
}

View File

@ -1,7 +1,5 @@
package io.metersphere.track.request.testplan;
import io.metersphere.track.dto.TestPlanScheduleReportInfoDTO;
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
import lombok.Getter;
import lombok.Setter;
@ -26,7 +24,7 @@ public class TestplanRunRequest {
private String environmentGroupId;
private List<String> testPlanIds;
private Boolean isAll;
private TestPlanScheduleReportInfoDTO planScheduleReportInfoDTO;
private String reportId;
private QueryTestPlanRequest queryTestPlanRequest;
}

View File

@ -0,0 +1,34 @@
package io.metersphere.track.service;
import io.metersphere.base.domain.TestPlanExecutionQueue;
import io.metersphere.base.mapper.ext.ExtTestPlanExecutionQueueMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;
@Service
public class TestPlanExecutionQueueService {
@Resource
private ExtTestPlanExecutionQueueMapper extTestPlanExecutionQueueMapper;
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void batchSave(List<TestPlanExecutionQueue> planExecutionQueues) {
if (!planExecutionQueues.isEmpty()) {
extTestPlanExecutionQueueMapper.sqlInsert(planExecutionQueues);
}
}
public int getNextNum(String resourceId) {
TestPlanExecutionQueue testPlanExecutionQueue = extTestPlanExecutionQueueMapper.getNextNum(resourceId);
if (testPlanExecutionQueue == null || testPlanExecutionQueue.getNum() == null) {
return 100001;
} else {
return Optional.of(testPlanExecutionQueue.getNum() + 1).orElse(100001);
}
}
}

View File

@ -221,6 +221,12 @@ public class TestPlanReportService {
}
public TestPlanScheduleReportInfoDTO genTestPlanReportBySchedule(String planReportId, String planId, String userId, String triggerMode) {
TestPlanReport testPlanReport = this.getTestPlanReport(planReportId);
TestPlanScheduleReportInfoDTO returnDTO = new TestPlanScheduleReportInfoDTO();
if (testPlanReport != null) {
returnDTO.setTestPlanReport(testPlanReport);
}
Map<String, String> planScenarioIdMap = new LinkedHashMap<>();
Map<String, String> planTestCaseIdMap = new LinkedHashMap<>();
Map<String, String> performanceIdMap = new LinkedHashMap<>();
@ -239,7 +245,6 @@ public class TestPlanReportService {
performanceIdMap.put(dto.getId(), dto.getLoadCaseId());
}
Map<String, String> apiCaseInfoMap = new HashMap<>();
for (String id : planTestCaseIdMap.keySet()) {
apiCaseInfoMap.put(id, TestPlanApiExecuteStatus.PREPARE.name());
@ -253,16 +258,6 @@ public class TestPlanReportService {
performanceInfoMap.put(id, TestPlanApiExecuteStatus.PREPARE.name());
}
TestPlanScheduleReportInfoDTO returnDTO = new TestPlanScheduleReportInfoDTO();
TestPlanReport testPlanReport;
if(StringUtils.isBlank(planReportId)){
planReportId = UUID.randomUUID().toString();
testPlanReport = null;
}else{
testPlanReport= this.getTestPlanReport(planReportId);
returnDTO.setTestPlanReport(testPlanReport);
}
TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(planReportId, planId, userId, triggerMode,
planTestCaseIdMap.size() > 0, planScenarioIdMap.size() > 0, performanceIdMap.size() > 0,
apiCaseInfoMap, scenarioInfoMap, performanceInfoMap);
@ -273,6 +268,7 @@ public class TestPlanReportService {
returnDTO.setPlanScenarioIdMap(planScenarioIdMap);
returnDTO.setApiTestCaseDataMap(planTestCaseIdMap);
returnDTO.setPerformanceIdMap(performanceIdMap);
return returnDTO;
}
@ -498,7 +494,7 @@ public class TestPlanReportService {
}
content.setPlanApiCaseReportStruct(JSONObject.toJSONString(apiTestCases));
} catch (Exception e) {
LogUtil.error("update test plan api error! "+e.getMessage());
LogUtil.error("update test plan api error! " , e.getMessage());
}
}
if (StringUtils.isNotEmpty(content.getPlanScenarioReportStruct())) {
@ -533,7 +529,7 @@ public class TestPlanReportService {
}
content.setPlanScenarioReportStruct(JSONObject.toJSONString(scenarioCases));
} catch (Exception e) {
LogUtil.error("update test plan api error! "+e.getMessage());
LogUtil.error("update test plan api error! " , e.getMessage());
}
}
//更新content表对结束日期
@ -560,13 +556,16 @@ public class TestPlanReportService {
testPlanExecutionQueueExample.createCriteria().andReportIdEqualTo(testPlanReportId);
List<TestPlanExecutionQueue> planExecutionQueues = testPlanExecutionQueueMapper.selectByExample(testPlanExecutionQueueExample);
String runMode = null;
String resourceId = null;
if (CollectionUtils.isNotEmpty(planExecutionQueues)) {
runMode = planExecutionQueues.get(0).getRunMode();
resourceId = planExecutionQueues.get(0).getResourceId();
testPlanExecutionQueueMapper.deleteByExample(testPlanExecutionQueueExample);
}
if(runMode!=null&&StringUtils.equalsIgnoreCase(runMode, RunModeConstants.SERIAL.name())){
if (runMode != null && StringUtils.equalsIgnoreCase(runMode, RunModeConstants.SERIAL.name()) && resourceId != null) {
TestPlanExecutionQueueExample queueExample = new TestPlanExecutionQueueExample();
queueExample.createCriteria().andReportIdIsNotNull();
queueExample.createCriteria().andReportIdIsNotNull().andResourceIdEqualTo(resourceId);
queueExample.setOrderByClause("`num` ASC");
List<TestPlanExecutionQueue> planExecutionQueueList = testPlanExecutionQueueMapper.selectByExample(queueExample);
if (CollectionUtils.isEmpty(planExecutionQueueList)) {
return testPlanReport;
@ -575,8 +574,7 @@ public class TestPlanReportService {
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(testPlanExecutionQueue.getTestPlanId());
JSONObject jsonObject = JSONObject.parseObject(testPlan.getRunModeConfig());
TestplanRunRequest runRequest = JSON.toJavaObject(jsonObject, TestplanRunRequest.class);
TestPlanScheduleReportInfoDTO testPlanScheduleReportInfoDTO = this.genTestPlanReportBySchedule( testPlanExecutionQueue.getReportId(), testPlanExecutionQueue.getTestPlanId(), runRequest.getUserId(), runRequest.getTriggerMode());
runRequest.setPlanScheduleReportInfoDTO(testPlanScheduleReportInfoDTO);
runRequest.setReportId(testPlanExecutionQueue.getReportId());
testPlanService.runPlan(runRequest);
}
}
@ -1007,9 +1005,9 @@ public class TestPlanReportService {
return null;
}
if (this.isDynamicallyGenerateReports(testPlanReportContent)) {
Log.info("----> GenerateReports: "+ JSONObject.toJSONString(testPlanReportContent));
LogUtil.info("----> GenerateReports: " + JSONObject.toJSONString(testPlanReportContent));
testPlanReportContent = this.dynamicallyGenerateReports(testPlanReportContent);
Log.info("----> GenerateReports OVER: "+ JSONObject.toJSONString(testPlanReportContent));
LogUtil.info("----> GenerateReports OVER: " + JSONObject.toJSONString(testPlanReportContent));
}
TestPlanSimpleReportDTO testPlanReportDTO = new TestPlanSimpleReportDTO();
BeanUtils.copyBean(testPlanReportDTO, testPlanReportContent);
@ -1114,11 +1112,14 @@ public class TestPlanReportService {
if (StringUtils.isNotEmpty(testPlanReportContentWithBLOBs.getPlanApiCaseReportStruct())) {
try {
apiCaseInfoDTOList = JSONArray.parseArray(testPlanReportContentWithBLOBs.getPlanApiCaseReportStruct(), TestPlanFailureApiDTO.class);
}catch (Exception ignore){}
} catch (Exception e) {
LogUtil.error(e);
}
if (apiCaseInfoDTOList == null) {
try {
testPlanApiCaseIdAndReportIdMap = JSONObject.parseObject(testPlanReportContentWithBLOBs.getPlanApiCaseReportStruct(), Map.class);
} catch (Exception ignore) {
} catch (Exception e) {
LogUtil.error(e);
}
} else {
for (TestPlanFailureApiDTO item : apiCaseInfoDTOList) {
@ -1129,7 +1130,9 @@ public class TestPlanReportService {
if (StringUtils.isNotEmpty(testPlanReportContentWithBLOBs.getPlanScenarioReportStruct())) {
try {
scenarioInfoDTOList = JSONArray.parseArray(testPlanReportContentWithBLOBs.getPlanScenarioReportStruct(), TestPlanFailureScenarioDTO.class);
}catch (Exception ignore){}
} catch (Exception e) {
LogUtil.error(e);
}
if (scenarioInfoDTOList == null) {
try {
testPlanScenarioIdAndReportIdMap = JSONObject.parseObject(testPlanReportContentWithBLOBs.getPlanScenarioReportStruct(), Map.class);

View File

@ -176,8 +176,7 @@ public class TestPlanService {
@Resource
private ProjectService projectService;
@Resource
private ExtTestPlanExecutionQueueMapper extTestPlanExecutionQueueMapper;
private TestPlanExecutionQueueService testPlanExecutionQueueService;
public synchronized TestPlan addTestPlan(AddTestPlanRequest testPlan) {
if (getTestPlanByName(testPlan.getName()).size() > 0) {
@ -937,12 +936,12 @@ public class TestPlanService {
}
@Transactional(propagation = Propagation.NOT_SUPPORTED)
TestPlanScheduleReportInfoDTO genTestPlanReport(String projectID, String planId, String userId, String triggerMode) {
TestPlanScheduleReportInfoDTO reportInfoDTO = testPlanReportService.genTestPlanReportBySchedule(null, planId, userId, triggerMode);
TestPlanScheduleReportInfoDTO genTestPlanReport(String planReportId, String planId, String userId, String triggerMode) {
TestPlanScheduleReportInfoDTO reportInfoDTO = testPlanReportService.genTestPlanReportBySchedule(planReportId, planId, userId, triggerMode);
return reportInfoDTO;
}
public String run(String testPlanID, String projectID, String userId, String triggerMode, TestPlanScheduleReportInfoDTO reportInfoDTO, String apiRunConfig) {
public String run(String testPlanID, String projectID, String userId, String triggerMode, String planReportId, String apiRunConfig) {
RunModeConfigDTO runModeConfig = null;
try {
runModeConfig = JSONObject.parseObject(apiRunConfig, RunModeConfigDTO.class);
@ -960,28 +959,41 @@ public class TestPlanService {
runModeConfig.setEnvMap(new HashMap<>());
}
}
//创建测试报告然后返回的ID重新赋值为resourceID作为后续的参数
if (reportInfoDTO == null) {
reportInfoDTO = this.genTestPlanReport(projectID, testPlanID, userId, triggerMode);
if (planReportId == null) {
planReportId = UUID.randomUUID().toString();
}
//创建测试报告然后返回的ID重新赋值为resourceID作为后续的参数
TestPlanScheduleReportInfoDTO reportInfoDTO = this.genTestPlanReport(planReportId, testPlanID, userId, triggerMode);
//测试计划准备执行取消测试计划的实际结束时间
extTestPlanMapper.updateActualEndTimeIsNullById(testPlanID);
String planReportId = reportInfoDTO.getTestPlanReport().getId();
testPlanLog.info("ReportId[" + planReportId + "] created. TestPlanID:[" + testPlanID + "]. " + "API Run Config:【" + apiRunConfig + "");
Map<String, String> apiCaseReportMap = null;
Map<String, String> scenarioReportMap = null;
Map<String, String> loadCaseReportMap = null;
if(reportInfoDTO.getApiTestCaseDataMap()!=null){
//执行接口案例任务
LoggerUtil.info("开始执行测试计划接口用例 " + planReportId);
Map<String, String> apiCaseReportMap = this.executeApiTestCase(triggerMode, planReportId, userId, new ArrayList<>(reportInfoDTO.getApiTestCaseDataMap().keySet()), runModeConfig);
apiCaseReportMap = this.executeApiTestCase(triggerMode, planReportId, userId, new ArrayList<>(reportInfoDTO.getApiTestCaseDataMap().keySet()), runModeConfig);
}
if(reportInfoDTO.getPlanScenarioIdMap()!=null){
//执行场景执行任务
LoggerUtil.info("开始执行测试计划场景用例 " + planReportId);
Map<String, String> scenarioReportMap = this.executeScenarioCase(planReportId, testPlanID, projectID, runModeConfig, triggerMode, userId, reportInfoDTO.getPlanScenarioIdMap());
scenarioReportMap = this.executeScenarioCase(planReportId, testPlanID, projectID, runModeConfig, triggerMode, userId, reportInfoDTO.getPlanScenarioIdMap());
}
if(reportInfoDTO.getPerformanceIdMap()!=null){
//执行性能测试任务
LoggerUtil.info("开始执行测试计划性能用例 " + planReportId);
Map<String, String> loadCaseReportMap = this.executeLoadCaseTask(planReportId, runModeConfig, triggerMode, reportInfoDTO.getPerformanceIdMap());
loadCaseReportMap = this.executeLoadCaseTask(planReportId,runModeConfig, triggerMode, reportInfoDTO.getPerformanceIdMap());
}
if(apiCaseReportMap!=null&&scenarioReportMap!=null&&loadCaseReportMap!=null){
LoggerUtil.info("开始生成测试计划报告 " + planReportId);
testPlanReportService.createTestPlanReportContentReportIds(planReportId, apiCaseReportMap, scenarioReportMap, loadCaseReportMap);
}
return planReportId;
}
@ -1852,7 +1864,7 @@ public class TestPlanService {
String apiRunConfig = JSONObject.toJSONString(runModeConfig);
updatePlan(testplanRunRequest, testPlanId);
return this.run(testPlanId, testplanRunRequest.getProjectId(),
testplanRunRequest.getUserId(), testplanRunRequest.getTriggerMode(), testplanRunRequest.getPlanScheduleReportInfoDTO() != null ? testplanRunRequest.getPlanScheduleReportInfoDTO() : null, apiRunConfig);
testplanRunRequest.getUserId(), testplanRunRequest.getTriggerMode(), testplanRunRequest.getReportId(), apiRunConfig);
}
@ -2052,10 +2064,10 @@ public class TestPlanService {
return extTestPlanMapper.list(request);
}
public List<MsExecResponseDTO> runBatch(TestplanRunRequest request) {
public void runBatch(TestplanRunRequest request) {
List<String> ids = request.getTestPlanIds();
if (CollectionUtils.isEmpty(ids) && !request.getIsAll()) {
return new LinkedList<>();
return;
}
LoggerUtil.info("开始查询测试计划");
List<TestPlanWithBLOBs> planList = new ArrayList<>();
@ -2070,25 +2082,31 @@ public class TestPlanService {
}
Map<String, TestPlanWithBLOBs> testPlanMap = planList.stream().collect(Collectors.toMap(TestPlan::getId, a -> a, (k1, k2) -> k1));
Map<String, TestPlanReport> executeQueue = new LinkedHashMap<>();
List<MsExecResponseDTO> responseDTOS = new LinkedList<>();
Map<String, TestPlanScheduleReportInfoDTO> planScheduleReportInfoDTOMap = new LinkedHashMap<>();
boolean startThread = true;
Map<String, String> executeQueue = new LinkedHashMap<>();
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < planList.size(); i++) {
if (StringUtils.isBlank(planList.get(i).getRunModeConfig())) {
StringBuilder append = stringBuilder.append("请保存[").append(planList.get(i).getName()).append("]的运行配置");
if (i <= planList.size() - 2) {
append.append("/");
}
}
}
if (StringUtils.isNotEmpty(stringBuilder)) {
MSException.throwException(stringBuilder.toString());
}
for (String id : ids) {
TestPlanWithBLOBs testPlan = testPlanMap.get(id);
if (StringUtils.isBlank(testPlan.getRunModeConfig())) {
startThread = false;
MSException.throwException("请保存[" + testPlan.getName() + "]的运行配置");
}
//创建测试报告然后返回的ID重新赋值为resourceID作为后续的参数
TestPlanScheduleReportInfoDTO reportInfoDTO = this.genTestPlanReport(testPlan.getProjectId(), testPlan.getId(), request.getUserId(), request.getTriggerMode());
String planReportId = UUID.randomUUID().toString();
//创建测试报告
this.genTestPlanReport(planReportId, testPlan.getId(), request.getUserId(), request.getTriggerMode());
//测试计划准备执行取消测试计划的实际结束时间
extTestPlanMapper.updateActualEndTimeIsNullById(testPlan.getId());
executeQueue.put(testPlan.getId(), planReportId);
executeQueue.put(testPlan.getId(), reportInfoDTO.getTestPlanReport());
responseDTOS.add(new MsExecResponseDTO(testPlan.getId(), reportInfoDTO.getTestPlanReport().getId(), request.getTriggerMode()));
planScheduleReportInfoDTOMap.put(testPlan.getId(), reportInfoDTO);
}
LoggerUtil.info("开始生成测试计划队列");
@ -2096,29 +2114,34 @@ public class TestPlanService {
List<TestPlanExecutionQueue> planExecutionQueues = getTestPlanExecutionQueues(request, executeQueue);
if (CollectionUtils.isNotEmpty(planExecutionQueues)) {
extTestPlanExecutionQueueMapper.sqlInsert(planExecutionQueues);
testPlanExecutionQueueService.batchSave(planExecutionQueues);
}
// 开始选择执行模式
runByMode(startThread, request, testPlanMap, planScheduleReportInfoDTOMap, planExecutionQueues);
runByMode(request, testPlanMap, planExecutionQueues);
return responseDTOS;
}
private List<TestPlanExecutionQueue> getTestPlanExecutionQueues(TestplanRunRequest request, Map<String, TestPlanReport> executeQueue) {
private List<TestPlanExecutionQueue> getTestPlanExecutionQueues(TestplanRunRequest request, Map<String, String> executeQueue) {
List<TestPlanExecutionQueue>planExecutionQueues = new ArrayList<>();
String resourceId = UUID.randomUUID().toString();
final int[] nextNum = {testPlanExecutionQueueService.getNextNum(resourceId)};
executeQueue.forEach((k, v)->{
TestPlanExecutionQueue executionQueue = new TestPlanExecutionQueue();
executionQueue.setId(UUID.randomUUID().toString());
executionQueue.setCreateTime(System.currentTimeMillis());
executionQueue.setReportId(v.getId());
executionQueue.setReportId(v);
executionQueue.setTestPlanId(k);
executionQueue.setRunMode(request.getMode());
executionQueue.setResourceId(resourceId);
executionQueue.setNum(nextNum[0]);
nextNum[0]++;
planExecutionQueues.add(executionQueue);
});
return planExecutionQueues;
}
private void runByMode(boolean startThread, TestplanRunRequest request, Map<String, TestPlanWithBLOBs> testPlanMap, Map<String, TestPlanScheduleReportInfoDTO> planScheduleReportInfoDTOMap, List<TestPlanExecutionQueue> planExecutionQueues) {
private void runByMode(TestplanRunRequest request, Map<String, TestPlanWithBLOBs> testPlanMap, List<TestPlanExecutionQueue> planExecutionQueues) {
if (CollectionUtils.isNotEmpty(planExecutionQueues)) {
Thread thread = new Thread(new Runnable() {
@Override
@ -2129,24 +2152,22 @@ public class TestPlanService {
TestPlanWithBLOBs testPlan = testPlanMap.get(planExecutionQueue.getTestPlanId());
JSONObject jsonObject = JSONObject.parseObject(testPlan.getRunModeConfig());
TestplanRunRequest runRequest = JSON.toJavaObject(jsonObject,TestplanRunRequest.class);
runRequest.setPlanScheduleReportInfoDTO(planScheduleReportInfoDTOMap.get(planExecutionQueue.getTestPlanId()));
runRequest.setReportId(planExecutionQueue.getReportId());
runPlan(runRequest);
}else {
for (TestPlanExecutionQueue planExecutionQueue : planExecutionQueues) {
TestPlanWithBLOBs testPlan = testPlanMap.get(planExecutionQueue.getTestPlanId());
JSONObject jsonObject = JSONObject.parseObject(testPlan.getRunModeConfig());
TestplanRunRequest runRequest = JSON.toJavaObject(jsonObject,TestplanRunRequest.class);
runRequest.setPlanScheduleReportInfoDTO(planScheduleReportInfoDTOMap.get(planExecutionQueue.getTestPlanId()));
runRequest.setReportId(planExecutionQueue.getReportId());
runPlan(runRequest);
}
}
}
});
if (startThread) {
thread.start();
}
}
}
public void updateRunModeConfig(TestplanRunRequest testplanRunRequest) {
String testPlanId = testplanRunRequest.getTestPlanId();

View File

@ -181,16 +181,18 @@ CREATE TABLE IF NOT EXISTS `test_plan_execution_queue`
`run_mode` varchar(100) COMMENT '执行模式/scenario/api/test_paln_api/test_pan_scenario',
create_time bigint(13) NULL COMMENT '创建时间',
`test_plan_id` varchar(100) COMMENT 'testPlanId',
`resource_id` varchar(100) COMMENT 'resourceId/批次id',
`num` int null comment 'order',
PRIMARY KEY (`id`),
KEY `report_id_idx` (`report_id`)
KEY `report_id_idx` (`report_id`),
KEY `resource_id_index` (`resource_id`),
KEY `num_index` (`num`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
-- 场景步骤结果增加简要信息
ALTER TABLE api_scenario_report_result ADD `base_info` LONGTEXT NULL;
-- quota
-- 处理移除组织时遗留的脏数据
delete

View File

@ -86,7 +86,7 @@
<!-- <ignoreColumn column="clean_load_report_expr"/>-->
<!-- <ignoreColumn column="repeatable"/>-->
<!-- </table>-->
<table tableName="test_plan"/>
<table tableName="test_plan_execution_queue"/>
<!--<table tableName="enterprise_test_report_send_record"/>-->
<!--<table tableName="test_case_review_api_case"/>
<table tableName="test_case_review_load"/>