From 3a1bfedf1591785dee2e952e532f8fd6e0c92dcd Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Sun, 22 Aug 2021 00:40:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E6=8A=A5=E5=91=8A):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=90=E8=A1=8C=E4=B8=AD=E7=9A=84=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=8A=A5=E5=91=8A=E6=89=93=E5=BC=80=E8=BF=87=E6=85=A2?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复运行中的测试报告打开过慢的问题 --- .../api/cache/TestPlanExecuteInfo.java | 159 +++++ .../api/cache/TestPlanReportExecuteCatch.java | 67 +++ .../ApiDefinitionExecResultService.java | 8 +- .../api/service/ApiScenarioReportService.java | 6 +- .../base/domain/TestPlanReportResource.java | 19 - .../domain/TestPlanReportResourceExample.java | 550 ------------------ .../mapper/TestPlanReportResourceMapper.java | 30 - .../mapper/TestPlanReportResourceMapper.xml | 211 ------- .../ext/ExtTestPlanReportResourceMapper.java | 9 - .../ext/ExtTestPlanReportResourceMapper.xml | 11 - .../dto/TestPlanScheduleReportInfoDTO.java | 3 +- .../TestPlanReportResourceService.java | 75 --- .../track/service/TestPlanReportService.java | 319 +++------- .../track/service/TestPlanService.java | 142 +++-- .../db/migration/V93__v1.12_release.sql | 3 + .../complete/EditCompleteTCPApi.vue | 10 +- 16 files changed, 416 insertions(+), 1206 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/api/cache/TestPlanExecuteInfo.java create mode 100644 backend/src/main/java/io/metersphere/api/cache/TestPlanReportExecuteCatch.java delete mode 100644 backend/src/main/java/io/metersphere/base/domain/TestPlanReportResource.java delete mode 100644 backend/src/main/java/io/metersphere/base/domain/TestPlanReportResourceExample.java delete mode 100644 backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.java delete mode 100644 backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.xml delete mode 100644 backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportResourceMapper.java delete mode 100644 backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportResourceMapper.xml delete mode 100644 backend/src/main/java/io/metersphere/track/service/TestPlanReportResourceService.java diff --git a/backend/src/main/java/io/metersphere/api/cache/TestPlanExecuteInfo.java b/backend/src/main/java/io/metersphere/api/cache/TestPlanExecuteInfo.java new file mode 100644 index 0000000000..c4e0ad9d9d --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/cache/TestPlanExecuteInfo.java @@ -0,0 +1,159 @@ +package io.metersphere.api.cache; + + +import io.metersphere.commons.constants.TestPlanApiExecuteStatus; +import io.metersphere.commons.constants.TestPlanResourceType; +import lombok.Getter; +import lombok.Setter; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author song.tianyang + * @Date 2021/8/21 5:15 下午 + */ +@Getter +@Setter +public class TestPlanExecuteInfo { + private String reportId; + private Map apiCaseExecInfo = new HashMap<>(); + private Map apiScenarioCaseExecInfo = new HashMap<>(); + private Map loadCaseExecInfo = new HashMap<>(); + private boolean reportDataInDataBase; + + int lastUnFinishedNumCount = 0; + long lastFinishedNumCountTime = 0; + + private boolean isApiCaseAllExecuted; + private boolean isScenarioAllExecuted; + private boolean isLoadCaseAllExecuted; + + public synchronized void updateExecuteInfo(Map apiCaseExecInfo, Map apiScenarioCaseExecInfo, Map loadCaseExecInfo) { + if (MapUtils.isNotEmpty(apiCaseExecInfo)) { + this.apiCaseExecInfo.putAll(apiCaseExecInfo); + } + + if (MapUtils.isNotEmpty(apiScenarioCaseExecInfo)) { + this.apiScenarioCaseExecInfo.putAll(apiScenarioCaseExecInfo); + } + + if (MapUtils.isNotEmpty(loadCaseExecInfo)) { + this.loadCaseExecInfo.putAll(loadCaseExecInfo); + } + } + + public synchronized int countUnFinishedNum() { + int unFinishedCount = 0; + + this.isApiCaseAllExecuted = true; + this.isScenarioAllExecuted = true; + this.isLoadCaseAllExecuted = true; + + for (String result : apiCaseExecInfo.values()) { + if (StringUtils.equalsIgnoreCase(result, TestPlanApiExecuteStatus.RUNNING.name())) { + unFinishedCount++; + if (this.isApiCaseAllExecuted) { + this.isApiCaseAllExecuted = false; + } + } + } + for (String result : apiScenarioCaseExecInfo.values()) { + if (StringUtils.equalsIgnoreCase(result, TestPlanApiExecuteStatus.RUNNING.name())) { + unFinishedCount++; + if (this.isScenarioAllExecuted) { + isScenarioAllExecuted = false; + } + } + } + for (String result : loadCaseExecInfo.values()) { + if (StringUtils.equalsIgnoreCase(result, TestPlanApiExecuteStatus.RUNNING.name())) { + unFinishedCount++; + if (this.isLoadCaseAllExecuted) { + isLoadCaseAllExecuted = false; + } + } + } + if (lastUnFinishedNumCount != unFinishedCount) { + lastUnFinishedNumCount = unFinishedCount; + lastFinishedNumCountTime = System.currentTimeMillis(); + } + return unFinishedCount; + } + + public Map> getExecutedResult() { + Map> resourceTypeMap = new HashMap<>(); + + for (Map.Entry entry : apiCaseExecInfo.entrySet()) { + String resourceId = entry.getKey(); + String executeResult = entry.getValue(); + String resourceType = TestPlanResourceType.API_CASE.name(); + + if (resourceTypeMap.containsKey(resourceType)) { + resourceTypeMap.get(resourceType).put(resourceId, executeResult); + } else { + Map map = new HashMap<>(); + map.put(resourceId, executeResult); + resourceTypeMap.put(resourceType, map); + } + } + + for (Map.Entry entry : apiScenarioCaseExecInfo.entrySet()) { + String resourceId = entry.getKey(); + String executeResult = entry.getValue(); + String resourceType = TestPlanResourceType.SCENARIO_CASE.name(); + + if (resourceTypeMap.containsKey(resourceType)) { + resourceTypeMap.get(resourceType).put(resourceId, executeResult); + } else { + Map map = new HashMap<>(); + map.put(resourceId, executeResult); + resourceTypeMap.put(resourceType, map); + } + } + + for (Map.Entry entry : loadCaseExecInfo.entrySet()) { + String resourceId = entry.getKey(); + String executeResult = entry.getValue(); + String resourceType = TestPlanResourceType.PERFORMANCE_CASE.name(); + + if (resourceTypeMap.containsKey(resourceType)) { + resourceTypeMap.get(resourceType).put(resourceId, executeResult); + } else { + Map map = new HashMap<>(); + map.put(resourceId, executeResult); + resourceTypeMap.put(resourceType, map); + } + } + + return resourceTypeMap; + } + + public void finishAllTask() { + for (Map.Entry entry : apiCaseExecInfo.entrySet()) { + String resourceId = entry.getKey(); + String executeResult = entry.getValue(); + if (StringUtils.equalsIgnoreCase(executeResult, TestPlanApiExecuteStatus.RUNNING.name())) { + apiCaseExecInfo.put(resourceId, TestPlanApiExecuteStatus.FAILD.name()); + } + } + for (Map.Entry entry : apiScenarioCaseExecInfo.entrySet()) { + String resourceId = entry.getKey(); + String executeResult = entry.getValue(); + if (StringUtils.equalsIgnoreCase(executeResult, TestPlanApiExecuteStatus.RUNNING.name())) { + apiScenarioCaseExecInfo.put(resourceId, TestPlanApiExecuteStatus.FAILD.name()); + } + } + for (Map.Entry entry : loadCaseExecInfo.entrySet()) { + String resourceId = entry.getKey(); + String executeResult = entry.getValue(); + if (StringUtils.equalsIgnoreCase(executeResult, TestPlanApiExecuteStatus.RUNNING.name())) { + loadCaseExecInfo.put(resourceId, TestPlanApiExecuteStatus.FAILD.name()); + } + } + + this.countUnFinishedNum(); + } +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/api/cache/TestPlanReportExecuteCatch.java b/backend/src/main/java/io/metersphere/api/cache/TestPlanReportExecuteCatch.java new file mode 100644 index 0000000000..1cacc9888a --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/cache/TestPlanReportExecuteCatch.java @@ -0,0 +1,67 @@ +package io.metersphere.api.cache; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author song.tianyang + * @Date 2021/8/20 3:29 下午 + */ +public class TestPlanReportExecuteCatch { + private static Map testPlanReportMap = new HashMap<>(); + + private TestPlanReportExecuteCatch() { + } + + public synchronized static void addApiTestPlanExecuteInfo(String reportId, + Map apiCaseExecInfo, Map apiScenarioCaseExecInfo, Map loadCaseExecInfo) { + if(testPlanReportMap == null){ + testPlanReportMap = new HashMap<>(); + } + if(apiCaseExecInfo == null){ + apiCaseExecInfo = new HashMap<>(); + } + if(apiScenarioCaseExecInfo == null){ + apiScenarioCaseExecInfo = new HashMap<>(); + } + if(loadCaseExecInfo == null){ + loadCaseExecInfo = new HashMap<>(); + } + + TestPlanExecuteInfo executeInfo = new TestPlanExecuteInfo(); + executeInfo.setReportId(reportId); + executeInfo.setApiCaseExecInfo(apiCaseExecInfo); + executeInfo.setApiScenarioCaseExecInfo(apiScenarioCaseExecInfo); + executeInfo.setLoadCaseExecInfo(loadCaseExecInfo); + testPlanReportMap.put(reportId,executeInfo); + } + + public synchronized static void updateApiTestPlanExecuteInfo(String reportId, + Map apiCaseExecInfo, Map apiScenarioCaseExecInfo, Map loadCaseExecInfo) { + if(testPlanReportMap != null && testPlanReportMap.containsKey(reportId)){ + testPlanReportMap.get(reportId).updateExecuteInfo(apiCaseExecInfo,apiScenarioCaseExecInfo,loadCaseExecInfo); + } + } + + public static TestPlanExecuteInfo getTestPlanExecuteInfo(String reportId){ + return testPlanReportMap.get(reportId); + } + + public static synchronized void setReportDataCheckResult(String reportId, boolean result) { + if(testPlanReportMap.containsKey(reportId)){ + testPlanReportMap.get(reportId).setReportDataInDataBase(result); + } + } + + public static synchronized void remove(String reportId){ + if(testPlanReportMap.containsKey(reportId)){ + testPlanReportMap.remove(reportId); + } + } + + public static void finishAllTask(String planReportId) { + if(testPlanReportMap.containsKey(planReportId)){ + testPlanReportMap.get(planReportId).finishAllTask(); + } + } +} diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java index ba743f9de7..cfa7cd68d7 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -2,6 +2,7 @@ package io.metersphere.api.service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import io.metersphere.api.cache.TestPlanReportExecuteCatch; import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult; import io.metersphere.api.jmeter.TestResult; import io.metersphere.base.domain.*; @@ -11,14 +12,12 @@ import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.TestCaseReviewApiCaseMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.commons.constants.*; -import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.DateUtils; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.track.dto.TestPlanDTO; import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.service.TestCaseReviewApiCaseService; import io.metersphere.track.service.TestPlanApiCaseService; -import io.metersphere.track.service.TestPlanReportService; import io.metersphere.track.service.TestPlanService; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -251,8 +250,9 @@ public class ApiDefinitionExecResultService { }); } testPlanLog.info("TestPlanReportId[" + testPlanReportId + "] APICASE OVER. API CASE STATUS:" + JSONObject.toJSONString(apiIdResultMap)); - TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class); - testPlanReportService.updateExecuteApis(testPlanReportId, apiIdResultMap, null, null); + TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(testPlanReportId,apiIdResultMap,null,null); +// TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class); +// testPlanReportService.updateExecuteApis(testPlanReportId, apiIdResultMap, null, null); } public void deleteByResourceId(String resourceId) { 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 8e60778994..5f29d96a7f 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import io.metersphere.api.cache.TestPlanReportExecuteCatch; import io.metersphere.api.dto.APIReportBatchRequest; import io.metersphere.api.dto.DeleteAPIReportRequest; import io.metersphere.api.dto.QueryAPIReportRequest; @@ -378,8 +379,9 @@ public class ApiScenarioReportService { testPlanLog.info("TestPlanReportId" + JSONArray.toJSONString(testPlanReportIdList) + " EXECUTE OVER. SCENARIO STATUS : " + JSONObject.toJSONString(scenarioAndErrorMap)); - for (String planId : testPlanReportIdList) { - testPlanReportService.updateExecuteApis(planId, null, scenarioAndErrorMap, null); + for (String reportId : testPlanReportIdList) { +// testPlanReportService.updateExecuteApis(planId, null, scenarioAndErrorMap, null); + TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(reportId,null,scenarioAndErrorMap,null); } return lastReport; diff --git a/backend/src/main/java/io/metersphere/base/domain/TestPlanReportResource.java b/backend/src/main/java/io/metersphere/base/domain/TestPlanReportResource.java deleted file mode 100644 index d9aced46bd..0000000000 --- a/backend/src/main/java/io/metersphere/base/domain/TestPlanReportResource.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.metersphere.base.domain; - -import java.io.Serializable; -import lombok.Data; - -@Data -public class TestPlanReportResource implements Serializable { - private String id; - - private String testPlanReportId; - - private String resourceId; - - private String resourceType; - - private String executeResult; - - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/TestPlanReportResourceExample.java b/backend/src/main/java/io/metersphere/base/domain/TestPlanReportResourceExample.java deleted file mode 100644 index 93e2afd28d..0000000000 --- a/backend/src/main/java/io/metersphere/base/domain/TestPlanReportResourceExample.java +++ /dev/null @@ -1,550 +0,0 @@ -package io.metersphere.base.domain; - -import java.util.ArrayList; -import java.util.List; - -public class TestPlanReportResourceExample { - protected String orderByClause; - - protected boolean distinct; - - protected List oredCriteria; - - public TestPlanReportResourceExample() { - oredCriteria = new ArrayList(); - } - - public void setOrderByClause(String orderByClause) { - this.orderByClause = orderByClause; - } - - public String getOrderByClause() { - return orderByClause; - } - - public void setDistinct(boolean distinct) { - this.distinct = distinct; - } - - public boolean isDistinct() { - return distinct; - } - - public List getOredCriteria() { - return oredCriteria; - } - - public void or(Criteria criteria) { - oredCriteria.add(criteria); - } - - public Criteria or() { - Criteria criteria = createCriteriaInternal(); - oredCriteria.add(criteria); - return criteria; - } - - public Criteria createCriteria() { - Criteria criteria = createCriteriaInternal(); - if (oredCriteria.size() == 0) { - oredCriteria.add(criteria); - } - return criteria; - } - - protected Criteria createCriteriaInternal() { - Criteria criteria = new Criteria(); - return criteria; - } - - public void clear() { - oredCriteria.clear(); - orderByClause = null; - distinct = false; - } - - protected abstract static class GeneratedCriteria { - protected List criteria; - - protected GeneratedCriteria() { - super(); - criteria = new ArrayList(); - } - - public boolean isValid() { - return criteria.size() > 0; - } - - public List getAllCriteria() { - return criteria; - } - - public List getCriteria() { - return criteria; - } - - protected void addCriterion(String condition) { - if (condition == null) { - throw new RuntimeException("Value for condition cannot be null"); - } - criteria.add(new Criterion(condition)); - } - - protected void addCriterion(String condition, Object value, String property) { - if (value == null) { - throw new RuntimeException("Value for " + property + " cannot be null"); - } - criteria.add(new Criterion(condition, value)); - } - - protected void addCriterion(String condition, Object value1, Object value2, String property) { - if (value1 == null || value2 == null) { - throw new RuntimeException("Between values for " + property + " cannot be null"); - } - criteria.add(new Criterion(condition, value1, value2)); - } - - public Criteria andIdIsNull() { - addCriterion("id is null"); - return (Criteria) this; - } - - public Criteria andIdIsNotNull() { - addCriterion("id is not null"); - return (Criteria) this; - } - - public Criteria andIdEqualTo(String value) { - addCriterion("id =", value, "id"); - return (Criteria) this; - } - - public Criteria andIdNotEqualTo(String value) { - addCriterion("id <>", value, "id"); - return (Criteria) this; - } - - public Criteria andIdGreaterThan(String value) { - addCriterion("id >", value, "id"); - return (Criteria) this; - } - - public Criteria andIdGreaterThanOrEqualTo(String value) { - addCriterion("id >=", value, "id"); - return (Criteria) this; - } - - public Criteria andIdLessThan(String value) { - addCriterion("id <", value, "id"); - return (Criteria) this; - } - - public Criteria andIdLessThanOrEqualTo(String value) { - addCriterion("id <=", value, "id"); - return (Criteria) this; - } - - public Criteria andIdLike(String value) { - addCriterion("id like", value, "id"); - return (Criteria) this; - } - - public Criteria andIdNotLike(String value) { - addCriterion("id not like", value, "id"); - return (Criteria) this; - } - - public Criteria andIdIn(List values) { - addCriterion("id in", values, "id"); - return (Criteria) this; - } - - public Criteria andIdNotIn(List values) { - addCriterion("id not in", values, "id"); - return (Criteria) this; - } - - public Criteria andIdBetween(String value1, String value2) { - addCriterion("id between", value1, value2, "id"); - return (Criteria) this; - } - - public Criteria andIdNotBetween(String value1, String value2) { - addCriterion("id not between", value1, value2, "id"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdIsNull() { - addCriterion("test_plan_report_id is null"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdIsNotNull() { - addCriterion("test_plan_report_id is not null"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdEqualTo(String value) { - addCriterion("test_plan_report_id =", value, "testPlanReportId"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdNotEqualTo(String value) { - addCriterion("test_plan_report_id <>", value, "testPlanReportId"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdGreaterThan(String value) { - addCriterion("test_plan_report_id >", value, "testPlanReportId"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdGreaterThanOrEqualTo(String value) { - addCriterion("test_plan_report_id >=", value, "testPlanReportId"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdLessThan(String value) { - addCriterion("test_plan_report_id <", value, "testPlanReportId"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdLessThanOrEqualTo(String value) { - addCriterion("test_plan_report_id <=", value, "testPlanReportId"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdLike(String value) { - addCriterion("test_plan_report_id like", value, "testPlanReportId"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdNotLike(String value) { - addCriterion("test_plan_report_id not like", value, "testPlanReportId"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdIn(List values) { - addCriterion("test_plan_report_id in", values, "testPlanReportId"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdNotIn(List values) { - addCriterion("test_plan_report_id not in", values, "testPlanReportId"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdBetween(String value1, String value2) { - addCriterion("test_plan_report_id between", value1, value2, "testPlanReportId"); - return (Criteria) this; - } - - public Criteria andTestPlanReportIdNotBetween(String value1, String value2) { - addCriterion("test_plan_report_id not between", value1, value2, "testPlanReportId"); - 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 values) { - addCriterion("resource_id in", values, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdNotIn(List 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 andResourceTypeIsNull() { - addCriterion("resource_type is null"); - return (Criteria) this; - } - - public Criteria andResourceTypeIsNotNull() { - addCriterion("resource_type is not null"); - return (Criteria) this; - } - - public Criteria andResourceTypeEqualTo(String value) { - addCriterion("resource_type =", value, "resourceType"); - return (Criteria) this; - } - - public Criteria andResourceTypeNotEqualTo(String value) { - addCriterion("resource_type <>", value, "resourceType"); - return (Criteria) this; - } - - public Criteria andResourceTypeGreaterThan(String value) { - addCriterion("resource_type >", value, "resourceType"); - return (Criteria) this; - } - - public Criteria andResourceTypeGreaterThanOrEqualTo(String value) { - addCriterion("resource_type >=", value, "resourceType"); - return (Criteria) this; - } - - public Criteria andResourceTypeLessThan(String value) { - addCriterion("resource_type <", value, "resourceType"); - return (Criteria) this; - } - - public Criteria andResourceTypeLessThanOrEqualTo(String value) { - addCriterion("resource_type <=", value, "resourceType"); - return (Criteria) this; - } - - public Criteria andResourceTypeLike(String value) { - addCriterion("resource_type like", value, "resourceType"); - return (Criteria) this; - } - - public Criteria andResourceTypeNotLike(String value) { - addCriterion("resource_type not like", value, "resourceType"); - return (Criteria) this; - } - - public Criteria andResourceTypeIn(List values) { - addCriterion("resource_type in", values, "resourceType"); - return (Criteria) this; - } - - public Criteria andResourceTypeNotIn(List values) { - addCriterion("resource_type not in", values, "resourceType"); - return (Criteria) this; - } - - public Criteria andResourceTypeBetween(String value1, String value2) { - addCriterion("resource_type between", value1, value2, "resourceType"); - return (Criteria) this; - } - - public Criteria andResourceTypeNotBetween(String value1, String value2) { - addCriterion("resource_type not between", value1, value2, "resourceType"); - return (Criteria) this; - } - - public Criteria andExecuteResultIsNull() { - addCriterion("execute_result is null"); - return (Criteria) this; - } - - public Criteria andExecuteResultIsNotNull() { - addCriterion("execute_result is not null"); - return (Criteria) this; - } - - public Criteria andExecuteResultEqualTo(String value) { - addCriterion("execute_result =", value, "executeResult"); - return (Criteria) this; - } - - public Criteria andExecuteResultNotEqualTo(String value) { - addCriterion("execute_result <>", value, "executeResult"); - return (Criteria) this; - } - - public Criteria andExecuteResultGreaterThan(String value) { - addCriterion("execute_result >", value, "executeResult"); - return (Criteria) this; - } - - public Criteria andExecuteResultGreaterThanOrEqualTo(String value) { - addCriterion("execute_result >=", value, "executeResult"); - return (Criteria) this; - } - - public Criteria andExecuteResultLessThan(String value) { - addCriterion("execute_result <", value, "executeResult"); - return (Criteria) this; - } - - public Criteria andExecuteResultLessThanOrEqualTo(String value) { - addCriterion("execute_result <=", value, "executeResult"); - return (Criteria) this; - } - - public Criteria andExecuteResultLike(String value) { - addCriterion("execute_result like", value, "executeResult"); - return (Criteria) this; - } - - public Criteria andExecuteResultNotLike(String value) { - addCriterion("execute_result not like", value, "executeResult"); - return (Criteria) this; - } - - public Criteria andExecuteResultIn(List values) { - addCriterion("execute_result in", values, "executeResult"); - return (Criteria) this; - } - - public Criteria andExecuteResultNotIn(List values) { - addCriterion("execute_result not in", values, "executeResult"); - return (Criteria) this; - } - - public Criteria andExecuteResultBetween(String value1, String value2) { - addCriterion("execute_result between", value1, value2, "executeResult"); - return (Criteria) this; - } - - public Criteria andExecuteResultNotBetween(String value1, String value2) { - addCriterion("execute_result not between", value1, value2, "executeResult"); - return (Criteria) this; - } - } - - public static class Criteria extends GeneratedCriteria { - - protected Criteria() { - super(); - } - } - - public static class Criterion { - private String condition; - - private Object value; - - private Object secondValue; - - private boolean noValue; - - private boolean singleValue; - - private boolean betweenValue; - - private boolean listValue; - - private String typeHandler; - - public String getCondition() { - return condition; - } - - public Object getValue() { - return value; - } - - public Object getSecondValue() { - return secondValue; - } - - public boolean isNoValue() { - return noValue; - } - - public boolean isSingleValue() { - return singleValue; - } - - public boolean isBetweenValue() { - return betweenValue; - } - - public boolean isListValue() { - return listValue; - } - - public String getTypeHandler() { - return typeHandler; - } - - protected Criterion(String condition) { - super(); - this.condition = condition; - this.typeHandler = null; - this.noValue = true; - } - - protected Criterion(String condition, Object value, String typeHandler) { - super(); - this.condition = condition; - this.value = value; - this.typeHandler = typeHandler; - if (value instanceof List) { - this.listValue = true; - } else { - this.singleValue = true; - } - } - - protected Criterion(String condition, Object value) { - this(condition, value, null); - } - - protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { - super(); - this.condition = condition; - this.value = value; - this.secondValue = secondValue; - this.typeHandler = typeHandler; - this.betweenValue = true; - } - - protected Criterion(String condition, Object value, Object secondValue) { - this(condition, value, secondValue, null); - } - } -} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.java b/backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.java deleted file mode 100644 index 1e9580641a..0000000000 --- a/backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.metersphere.base.mapper; - -import io.metersphere.base.domain.TestPlanReportResource; -import io.metersphere.base.domain.TestPlanReportResourceExample; -import java.util.List; -import org.apache.ibatis.annotations.Param; - -public interface TestPlanReportResourceMapper { - long countByExample(TestPlanReportResourceExample example); - - int deleteByExample(TestPlanReportResourceExample example); - - int deleteByPrimaryKey(String id); - - int insert(TestPlanReportResource record); - - int insertSelective(TestPlanReportResource record); - - List selectByExample(TestPlanReportResourceExample example); - - TestPlanReportResource selectByPrimaryKey(String id); - - int updateByExampleSelective(@Param("record") TestPlanReportResource record, @Param("example") TestPlanReportResourceExample example); - - int updateByExample(@Param("record") TestPlanReportResource record, @Param("example") TestPlanReportResourceExample example); - - int updateByPrimaryKeySelective(TestPlanReportResource record); - - int updateByPrimaryKey(TestPlanReportResource record); -} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.xml deleted file mode 100644 index a6fb88a90b..0000000000 --- a/backend/src/main/java/io/metersphere/base/mapper/TestPlanReportResourceMapper.xml +++ /dev/null @@ -1,211 +0,0 @@ - - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - - - - - - - - - id, test_plan_report_id, resource_id, resource_type, execute_result - - - - - delete from test_plan_report_resource - where id = #{id,jdbcType=VARCHAR} - - - delete from test_plan_report_resource - - - - - - insert into test_plan_report_resource (id, test_plan_report_id, resource_id, - resource_type, execute_result) - values (#{id,jdbcType=VARCHAR}, #{testPlanReportId,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR}, - #{resourceType,jdbcType=VARCHAR}, #{executeResult,jdbcType=VARCHAR}) - - - insert into test_plan_report_resource - - - id, - - - test_plan_report_id, - - - resource_id, - - - resource_type, - - - execute_result, - - - - - #{id,jdbcType=VARCHAR}, - - - #{testPlanReportId,jdbcType=VARCHAR}, - - - #{resourceId,jdbcType=VARCHAR}, - - - #{resourceType,jdbcType=VARCHAR}, - - - #{executeResult,jdbcType=VARCHAR}, - - - - - - update test_plan_report_resource - - - id = #{record.id,jdbcType=VARCHAR}, - - - test_plan_report_id = #{record.testPlanReportId,jdbcType=VARCHAR}, - - - resource_id = #{record.resourceId,jdbcType=VARCHAR}, - - - resource_type = #{record.resourceType,jdbcType=VARCHAR}, - - - execute_result = #{record.executeResult,jdbcType=VARCHAR}, - - - - - - - - update test_plan_report_resource - set id = #{record.id,jdbcType=VARCHAR}, - test_plan_report_id = #{record.testPlanReportId,jdbcType=VARCHAR}, - resource_id = #{record.resourceId,jdbcType=VARCHAR}, - resource_type = #{record.resourceType,jdbcType=VARCHAR}, - execute_result = #{record.executeResult,jdbcType=VARCHAR} - - - - - - update test_plan_report_resource - - - test_plan_report_id = #{testPlanReportId,jdbcType=VARCHAR}, - - - resource_id = #{resourceId,jdbcType=VARCHAR}, - - - resource_type = #{resourceType,jdbcType=VARCHAR}, - - - execute_result = #{executeResult,jdbcType=VARCHAR}, - - - where id = #{id,jdbcType=VARCHAR} - - - update test_plan_report_resource - set test_plan_report_id = #{testPlanReportId,jdbcType=VARCHAR}, - resource_id = #{resourceId,jdbcType=VARCHAR}, - resource_type = #{resourceType,jdbcType=VARCHAR}, - execute_result = #{executeResult,jdbcType=VARCHAR} - where id = #{id,jdbcType=VARCHAR} - - \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportResourceMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportResourceMapper.java deleted file mode 100644 index b72dc34ba9..0000000000 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportResourceMapper.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.metersphere.base.mapper.ext; - -import io.metersphere.base.domain.TestPlanReportResource; - -import java.util.List; - -public interface ExtTestPlanReportResourceMapper { - List selectResourceIdAndResourceTypeAndExecuteResultByTestPlanReportId(String testPlanReportId); -} diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportResourceMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportResourceMapper.xml deleted file mode 100644 index cdc8861079..0000000000 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportResourceMapper.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - diff --git a/backend/src/main/java/io/metersphere/track/dto/TestPlanScheduleReportInfoDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestPlanScheduleReportInfoDTO.java index e9ebe96d56..359c7f125d 100644 --- a/backend/src/main/java/io/metersphere/track/dto/TestPlanScheduleReportInfoDTO.java +++ b/backend/src/main/java/io/metersphere/track/dto/TestPlanScheduleReportInfoDTO.java @@ -1,5 +1,6 @@ package io.metersphere.track.dto; +import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.TestPlanReport; import lombok.Getter; import lombok.Setter; @@ -16,6 +17,6 @@ import java.util.Map; public class TestPlanScheduleReportInfoDTO { private TestPlanReport testPlanReport; private Map planScenarioIdMap = new LinkedHashMap<>(); - private Map apiTestCaseIdMap = new LinkedHashMap<>(); + private Map apiTestCaseDataMap = new LinkedHashMap<>(); private Map performanceIdMap = new LinkedHashMap<>(); } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanReportResourceService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanReportResourceService.java deleted file mode 100644 index 1989012221..0000000000 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportResourceService.java +++ /dev/null @@ -1,75 +0,0 @@ -package io.metersphere.track.service; - -import io.metersphere.base.domain.TestPlanReportResource; -import io.metersphere.base.domain.TestPlanReportResourceExample; -import io.metersphere.base.mapper.TestPlanReportResourceMapper; -import io.metersphere.base.mapper.ext.ExtTestPlanReportResourceMapper; -import org.apache.commons.collections.CollectionUtils; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author song.tianyang - * @Date 2021/8/2 1:57 下午 - */ -@Service -@Transactional(rollbackFor = Exception.class) -public class TestPlanReportResourceService { - @Resource - private TestPlanReportResourceMapper testPlanReportResourceMapper; - @Resource - private ExtTestPlanReportResourceMapper extTestPlanReportResourceMapper; - - public int updateExecuteResultByReportIdAndResourceIds(String executeResult, String planReportId, List ids) { - if(CollectionUtils.isEmpty(ids)){ - return 0; - }else { - TestPlanReportResourceExample example = new TestPlanReportResourceExample(); - example.createCriteria().andTestPlanReportIdEqualTo(planReportId).andResourceIdIn(ids); - - TestPlanReportResource updateModel = new TestPlanReportResource(); - updateModel.setExecuteResult(executeResult); - return testPlanReportResourceMapper.updateByExampleSelective(updateModel,example); - } - } - - public long countByReportIdAndResourceTypeAndExecuteResultNotEquals(String planReportId, String resourceType, String executeResult) { - TestPlanReportResourceExample example = new TestPlanReportResourceExample(); - example.createCriteria().andTestPlanReportIdEqualTo(planReportId).andResourceTypeEqualTo(resourceType).andExecuteResultNotEqualTo(executeResult); - return this.testPlanReportResourceMapper.countByExample(example); - } - - public long countByReportIdAndResourceTypeAndExecuteResultEquals(String planReportId, String resourceType, String executeResult) { - TestPlanReportResourceExample example = new TestPlanReportResourceExample(); - example.createCriteria().andTestPlanReportIdEqualTo(planReportId).andResourceTypeEqualTo(resourceType).andExecuteResultEqualTo(executeResult); - return this.testPlanReportResourceMapper.countByExample(example); - } - - public Map> selectExecuteResultByTestPlanReportId(String testPlanReportId) { - Map> resourceTypeMap = new HashMap<>(); - List testPlanReportResourceList = extTestPlanReportResourceMapper.selectResourceIdAndResourceTypeAndExecuteResultByTestPlanReportId(testPlanReportId); - for (TestPlanReportResource model : testPlanReportResourceList) { - String resourceType = model.getResourceType(); - String resourceId = model.getResourceId(); - String executeResult = model.getExecuteResult(); - - if(resourceTypeMap.containsKey(resourceType)){ - resourceTypeMap.get(resourceType).put(resourceId,executeResult); - }else { - Map map = new HashMap<>(); - map.put(resourceId,executeResult); - resourceTypeMap.put(resourceType,map); - } - } - return resourceTypeMap; - } - - public void deleteByExample(TestPlanReportResourceExample resourceExample) { - testPlanReportResourceMapper.deleteByExample(resourceExample); - } -} diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java index 01176892e7..b6afdd0f98 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -3,6 +3,8 @@ package io.metersphere.track.service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import io.metersphere.api.cache.TestPlanExecuteInfo; +import io.metersphere.api.cache.TestPlanReportExecuteCatch; import io.metersphere.api.dto.automation.ApiScenarioDTO; import io.metersphere.api.dto.automation.TestPlanScenarioRequest; import io.metersphere.api.dto.definition.ApiTestCaseRequest; @@ -74,11 +76,7 @@ public class TestPlanReportService { @Resource ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper; @Resource - TestPlanReportResourceService testPlanReportResourceService; - // @Resource -// TestPlanLoadCaseService testPlanLoadCaseService; -// @Resource -// TestPlanService testPlanService; + ApiTestCaseMapper apiTestCaseMapper; @Resource LoadTestReportMapper loadTestReportMapper; @@ -110,13 +108,10 @@ public class TestPlanReportService { // } // } - private TestPlanReport updateTestPlanReportById(String id) { - return this.updateExecuteApis(id, null, null, null); - } - public TestPlanScheduleReportInfoDTO genTestPlanReportBySchedule(String projectID, String planId, String userId, String triggerMode) { Map planScenarioIdMap = new LinkedHashMap<>(); Map apiTestCaseIdMap = new LinkedHashMap<>(); + Map apiTestCaseDataMap = new LinkedHashMap<>(); Map performanceIdMap = new LinkedHashMap<>(); List testPlanApiScenarioList = extTestPlanScenarioCaseMapper.selectLegalDataByTestPlanId(planId); @@ -140,8 +135,21 @@ public class TestPlanReportService { String planReportId = UUID.randomUUID().toString(); Map apiCaseInfoMap = new HashMap<>(); - for (String id : apiTestCaseIdMap.keySet()) { - apiCaseInfoMap.put(id, TestPlanApiExecuteStatus.PREPARE.name()); + if(!apiTestCaseIdMap.isEmpty()){ + ApiTestCaseExample apiTestCaseExample = new ApiTestCaseExample(); + apiTestCaseExample.createCriteria().andIdIn(new ArrayList<>(apiTestCaseIdMap.keySet())); + List apiCaseList = apiTestCaseMapper.selectByExampleWithBLOBs(apiTestCaseExample); + Map apiCaseDataMap = new HashMap<>(); + if(!apiCaseList.isEmpty()){ + apiCaseDataMap = apiCaseList.stream().collect(Collectors.toMap(ApiTestCaseWithBLOBs::getId, k -> k)); + for (String id : apiCaseDataMap.keySet()) { + apiCaseInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name()); + String testPlanApiCaseId = apiTestCaseIdMap.get(id); + if(StringUtils.isNotEmpty(testPlanApiCaseId)){ + apiTestCaseDataMap.put(apiCaseDataMap.get(id),testPlanApiCaseId); + } + } + } } Map scenarioInfoMap = new HashMap<>(); for (String id : planScenarioIdMap.keySet()) { @@ -159,7 +167,7 @@ public class TestPlanReportService { TestPlanScheduleReportInfoDTO returnDTO = new TestPlanScheduleReportInfoDTO(); returnDTO.setTestPlanReport(report); returnDTO.setPlanScenarioIdMap(planScenarioIdMap); - returnDTO.setApiTestCaseIdMap(apiTestCaseIdMap); + returnDTO.setApiTestCaseDataMap(apiTestCaseDataMap); returnDTO.setPerformanceIdMap(performanceIdMap); return returnDTO; } @@ -234,56 +242,11 @@ public class TestPlanReportService { performanceInfoMap = saveRequest.getPerformanceIdMap(); } - List resourceList = new ArrayList<>(); - if (MapUtils.isNotEmpty(apiCaseInfoMap)) { - for (Map.Entry entry : apiCaseInfoMap.entrySet()) { - String id = entry.getKey(); - String status = entry.getValue(); - String type = TestPlanResourceType.API_CASE.name(); - - TestPlanReportResource apiCaseResource = new TestPlanReportResource(); - apiCaseResource.setResourceId(id); - apiCaseResource.setTestPlanReportId(testPlanReportID); - apiCaseResource.setResourceType(type); - apiCaseResource.setExecuteResult(status); - apiCaseResource.setId(UUID.randomUUID().toString()); - resourceList.add(apiCaseResource); - } - } - if (MapUtils.isNotEmpty(scenarioInfoMap)) { - for (Map.Entry entry : scenarioInfoMap.entrySet()) { - String id = entry.getKey(); - String status = entry.getValue(); - String type = TestPlanResourceType.SCENARIO_CASE.name(); - - TestPlanReportResource scenarioResource = new TestPlanReportResource(); - scenarioResource.setResourceId(id); - scenarioResource.setTestPlanReportId(testPlanReportID); - scenarioResource.setResourceType(type); - scenarioResource.setExecuteResult(status); - scenarioResource.setId(UUID.randomUUID().toString()); - resourceList.add(scenarioResource); - } - } - if (MapUtils.isNotEmpty(performanceInfoMap)) { - for (Map.Entry entry : performanceInfoMap.entrySet()) { - String id = entry.getKey(); - String status = entry.getValue(); - String type = TestPlanResourceType.PERFORMANCE_CASE.name(); - - TestPlanReportResource performanceResource = new TestPlanReportResource(); - performanceResource.setResourceId(id); - performanceResource.setTestPlanReportId(testPlanReportID); - performanceResource.setResourceType(type); - performanceResource.setExecuteResult(status); - performanceResource.setId(UUID.randomUUID().toString()); - resourceList.add(performanceResource); - } - } + TestPlanReportExecuteCatch.addApiTestPlanExecuteInfo(testPlanReportID,apiCaseInfoMap,scenarioInfoMap,performanceInfoMap); testPlanReport.setPrincipal(testPlan.getPrincipal()); if (testPlanReport.getIsScenarioExecuting() || testPlanReport.getIsApiCaseExecuting() || testPlanReport.getIsPerformanceExecuting()) { - testPlanReport.setStatus(APITestStatus.Starting.name()); + testPlanReport.setStatus(APITestStatus.Running.name()); } else { testPlanReport.setStatus(APITestStatus.Completed.name()); } @@ -291,12 +254,8 @@ public class TestPlanReportService { SqlSession sqlSession = sqlSessionFactory.openSession(false); TestPlanReportMapper insertReportMapper = sqlSession.getMapper(TestPlanReportMapper.class); TestPlanReportDataMapper insertReportDataMapper = sqlSession.getMapper(TestPlanReportDataMapper.class); - TestPlanReportResourceMapper insertResourceMapper = sqlSession.getMapper(TestPlanReportResourceMapper.class); insertReportMapper.insert(testPlanReport); insertReportDataMapper.insert(testPlanReportData); - for (TestPlanReportResource resource : resourceList) { - insertResourceMapper.insert(resource); - } sqlSession.commit(); sqlSession.flushStatements(); @@ -310,9 +269,9 @@ public class TestPlanReportService { TestPlanReportDTO returnDTO = new TestPlanReportDTO(); TestPlanReport report = testPlanReportMapper.selectByPrimaryKey(reportId); if (report != null) { - if (StringUtils.equalsIgnoreCase(report.getStatus(), TestPlanApiExecuteStatus.RUNNING.name())) { - report = this.updateExecuteApis(reportId, null, null, null); - } +// if (StringUtils.equalsIgnoreCase(report.getStatus(), TestPlanApiExecuteStatus.RUNNING.name())) { +// report = this.updateExecuteApis(reportId); +// } TestPlanReportDataExample example = new TestPlanReportDataExample(); example.createCriteria().andTestPlanReportIdEqualTo(reportId); List reportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example); @@ -510,113 +469,6 @@ public class TestPlanReportService { loadResult.add(dto); } } -// for (int i = 0; i < apiCaseExecuteArr.size(); i++) { -// JSONObject jsonObj = apiCaseExecuteArr.getJSONObject(i); -// -// Map countMap = new HashMap<>(); -// if (jsonObj.containsKey("status")) { -// String status = jsonObj.getString("status"); -// -// } -// -// } -// -// for (int i = 0; i < scenarioExecuteArr.size(); i++) { -// JSONObject jsonObj = scenarioExecuteArr.getJSONObject(i); -// Map countMap = new HashMap<>(); -// if (jsonObj.containsKey("status")) { -// String status = jsonObj.getString("status"); -// if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name())) { -// if (countMap.containsKey("Pass")) { -// countMap.put("Pass", countMap.get("Pass") + 1); -// } else { -// countMap.put("Pass", 1); -// } -// } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.FAILD.name())) { -// if (jsonObj.containsKey("id")) { -// faliureScenarioCaseIdList.add(jsonObj.getString("id")); -// } -// if (countMap.containsKey("Failure")) { -// countMap.put("Failure", countMap.get("Failure") + 1); -// } else { -// countMap.put("Failure", 1); -// } -// } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.PREPARE.name())) { -// if (jsonObj.containsKey("id")) { -// faliureScenarioCaseIdList.add(jsonObj.getString("id")); -// } -// if (countMap.containsKey("Skip")) { -// countMap.put("Skip", countMap.get("Skip") + 1); -// } else { -// countMap.put("Skip", 1); -// } -// } else { -// if (countMap.containsKey("Underway")) { -// countMap.put("Underway", countMap.get("Underway") + 1); -// } else { -// countMap.put("Underway", 1); -// } -// } -// } -// -// for (Map.Entry entry : countMap.entrySet()) { -// String status = entry.getKey(); -// Integer value = entry.getValue(); -// TestCaseReportStatusResultDTO dto = new TestCaseReportStatusResultDTO(); -// dto.setStatus(status); -// dto.setCount(value); -// scenarioResult.add(dto); -// } -// } -// -// for (int i = 0; i < loadExecuteArr.size(); i++) { -// JSONObject jsonObj = loadExecuteArr.getJSONObject(i); -// Map countMap = new HashMap<>(); -// if (jsonObj.containsKey("status")) { -// String status = jsonObj.getString("status"); -// if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name())) { -// if (countMap.containsKey("Pass")) { -// countMap.put("Pass", countMap.get("Pass") + 1); -// } else { -// countMap.put("Pass", 1); -// } -// } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.FAILD.name())) { -// if (jsonObj.containsKey("id")) { -// faliureLoadCaseIdList.add(jsonObj.getString("id")); -// } -// if (countMap.containsKey("Failure")) { -// countMap.put("Failure", countMap.get("Failure") + 1); -// } else { -// countMap.put("Failure", 1); -// } -// } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.PREPARE.name())) { -// if (jsonObj.containsKey("id")) { -// faliureLoadCaseIdList.add(jsonObj.getString("id")); -// } -// if (countMap.containsKey("Skip")) { -// countMap.put("Skip", countMap.get("Skip") + 1); -// } else { -// countMap.put("Skip", 1); -// } -// } else { -// if (countMap.containsKey("Underway")) { -// countMap.put("Underway", countMap.get("Underway") + 1); -// } else { -// countMap.put("Underway", 1); -// } -// } -// } -// -// for (Map.Entry entry : countMap.entrySet()) { -// String status = entry.getKey(); -// Integer value = entry.getValue(); -// TestCaseReportStatusResultDTO dto = new TestCaseReportStatusResultDTO(); -// dto.setStatus(status); -// dto.setCount(value); -// loadResult.add(dto); -// } -// } - statusDTO.setApiResult(apiResult); statusDTO.setScenarioResult(scenarioResult); statusDTO.setLoadResult(loadResult); @@ -662,7 +514,7 @@ public class TestPlanReportService { return returnDTO; } - public TestPlanReport updateReport(TestPlanReportDataWithBLOBs testPlanReportData, boolean apiCaseIsOk, boolean scenarioIsOk, boolean performanceIsOk, boolean updateTime) { + public TestPlanReport updateReport(TestPlanReportDataWithBLOBs testPlanReportData,boolean updateTime,TestPlanExecuteInfo executeInfo) { TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(testPlanReportData.getTestPlanReportId()); if (testPlanReport == null) { return null; @@ -673,6 +525,13 @@ public class TestPlanReportService { testPlanReport.setUpdateTime(System.currentTimeMillis()); } + boolean apiCaseIsOk = executeInfo.isApiCaseAllExecuted(); + boolean scenarioIsOk = executeInfo.isScenarioAllExecuted(); + boolean performanceIsOk = executeInfo.isLoadCaseAllExecuted(); + + testPlanLog.info("ReportId[" + testPlanReportData.getTestPlanReportId() + "] count over. Testplan Execute Result: Api is over ->" + apiCaseIsOk + "; scenario is over ->" + scenarioIsOk + "; performance is over ->" + performanceIsOk); + + if (apiCaseIsOk) { testPlanReport.setIsApiCaseExecuting(false); } @@ -683,6 +542,10 @@ public class TestPlanReportService { testPlanReport.setIsPerformanceExecuting(false); } + if(apiCaseIsOk && scenarioIsOk && performanceIsOk){ + TestPlanReportExecuteCatch.remove(testPlanReportData.getTestPlanReportId()); + } + int[] componentIndexArr = new int[]{1, 3, 4}; testPlanReport.setComponents(JSONArray.toJSONString(componentIndexArr)); @@ -699,7 +562,7 @@ public class TestPlanReportService { testPlanService.buildScenarioCaseReport(testPlanReport.getTestPlanId(), components); testPlanService.buildLoadCaseReport(testPlanReport.getTestPlanId(), components); - Map> testPlanExecuteResult = testPlanReportResourceService.selectExecuteResultByTestPlanReportId(testPlanReportData.getTestPlanReportId()); + Map> testPlanExecuteResult = executeInfo.getExecutedResult(); testPlanLog.info("ReportId[" + testPlanReportData.getTestPlanReportId() + "] COUNT OVER. COUNT RESULT :" + JSONObject.toJSONString(testPlanExecuteResult)); @@ -1063,7 +926,8 @@ public class TestPlanReportService { this.updatePerformanceTestStatus(eventDTO); } } - this.updateExecuteApis(testPlanReport.getId(), null, null, finishLoadTestId); +// this.updateExecuteApis(testPlanReport.getId(), null, null, finishLoadTestId); + TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(testPlanReport.getId(),null,null,finishLoadTestId); } else { try { //查询定时任务是否关闭 @@ -1091,9 +955,9 @@ public class TestPlanReportService { TestPlanReportDataExample example = new TestPlanReportDataExample(); example.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId); testPlanReportDataMapper.deleteByExample(example); - TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample(); - resourceExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId); - testPlanReportResourceService.deleteByExample(resourceExample); +// TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample(); +// resourceExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId); +// testPlanReportResourceService.deleteByExample(resourceExample); } } @@ -1118,9 +982,9 @@ public class TestPlanReportService { example.createCriteria().andTestPlanReportIdIn(deleteReportIds); testPlanReportDataMapper.deleteByExample(example); - TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample(); - resourceExample.createCriteria().andTestPlanReportIdIn(deleteReportIds); - testPlanReportResourceService.deleteByExample(resourceExample); +// TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample(); +// resourceExample.createCriteria().andTestPlanReportIdIn(deleteReportIds); +// testPlanReportResourceService.deleteByExample(resourceExample); } } @@ -1151,9 +1015,13 @@ public class TestPlanReportService { return null; } - public synchronized TestPlanReport updateExecuteApis(String planReportId, Map executeApiCaseIdMap, Map executeScenarioCaseIdMap, Map executePerformanceIdMap) { - TestPlanReportDataExample example = new TestPlanReportDataExample(); -// List resourceIdList = new ArrayList<>(); + public synchronized TestPlanReport updateExecuteApis(String planReportId) { + + TestPlanExecuteInfo executeInfo = TestPlanReportExecuteCatch.getTestPlanExecuteInfo(planReportId); + + Map executeApiCaseIdMap = executeInfo.getApiCaseExecInfo(); + Map executeScenarioCaseIdMap = executeInfo.getApiScenarioCaseExecInfo(); + Map executePerformanceIdMap = executeInfo.getLoadCaseExecInfo(); if (executeApiCaseIdMap == null) { executeApiCaseIdMap = new HashMap<>(); } @@ -1163,77 +1031,20 @@ public class TestPlanReportService { if (executePerformanceIdMap == null) { executePerformanceIdMap = new HashMap<>(); } + boolean updateTime = MapUtils.isNotEmpty(executeApiCaseIdMap) || MapUtils.isNotEmpty(executeScenarioCaseIdMap) || MapUtils.isNotEmpty(executePerformanceIdMap); testPlanLog.info("ReportId[" + planReportId + "] Executed. api :" + JSONObject.toJSONString(executeApiCaseIdMap) + "; scenario:" + JSONObject.toJSONString(executeScenarioCaseIdMap) + "; performance:" + JSONObject.toJSONString(executePerformanceIdMap)); + TestPlanReportDataExample example = new TestPlanReportDataExample(); example.createCriteria().andTestPlanReportIdEqualTo(planReportId); List reportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example); TestPlanReport report = null; if (!reportDataList.isEmpty()) { - Map> batchUpdateMap = new HashMap<>(); - for (Map.Entry entry : executeApiCaseIdMap.entrySet()) { - String id = entry.getKey(); - String result = entry.getValue(); - if (batchUpdateMap.containsKey(result)) { - batchUpdateMap.get(result).add(id); - } else { - List idList = new ArrayList<>(); - idList.add(id); - batchUpdateMap.put(result, idList); - } - } - for (Map.Entry entry : executeScenarioCaseIdMap.entrySet()) { - String id = entry.getKey(); - String result = entry.getValue(); - if (batchUpdateMap.containsKey(result)) { - batchUpdateMap.get(result).add(id); - } else { - List idList = new ArrayList<>(); - idList.add(id); - batchUpdateMap.put(result, idList); - } - } - for (Map.Entry entry : executePerformanceIdMap.entrySet()) { - String id = entry.getKey(); - String result = entry.getValue(); - if (batchUpdateMap.containsKey(result)) { - batchUpdateMap.get(result).add(id); - } else { - List idList = new ArrayList<>(); - idList.add(id); - batchUpdateMap.put(result, idList); - } - } - - for (Map.Entry> entry : batchUpdateMap.entrySet()) { - String status = entry.getKey(); - List ids = entry.getValue(); - if (CollectionUtils.isEmpty(ids)) { - continue; - } - int updateCount = this.testPlanReportResourceService.updateExecuteResultByReportIdAndResourceIds(status, planReportId, ids); - testPlanLog.info("ReportId[" + planReportId + "] Update Execute Result. Update datas count is :[" + updateCount + "]; Update Status:[" + status + "],Update ids :[" + JSONArray.toJSONString(ids) + "] "); - } - boolean apiCaseExecuteOk = testPlanReportResourceService.countByReportIdAndResourceTypeAndExecuteResultEquals(planReportId, TestPlanResourceType.API_CASE.name(), TestPlanApiExecuteStatus.RUNNING.name()) == 0; - boolean scenarioExecuteOk = testPlanReportResourceService.countByReportIdAndResourceTypeAndExecuteResultEquals(planReportId, TestPlanResourceType.SCENARIO_CASE.name(), TestPlanApiExecuteStatus.RUNNING.name()) == 0; - boolean performanceExecuteOk = testPlanReportResourceService.countByReportIdAndResourceTypeAndExecuteResultEquals(planReportId, TestPlanResourceType.PERFORMANCE_CASE.name(), TestPlanApiExecuteStatus.RUNNING.name()) == 0; - ; - - testPlanLog.info("ReportId[" + planReportId + "] count over. Testplan Execute Result: Api is over ->" + apiCaseExecuteOk + "; scenario is over ->" + scenarioExecuteOk + "; performance is over ->" + performanceExecuteOk); - + TestPlanReportExecuteCatch.setReportDataCheckResult(planReportId,true); TestPlanReportDataWithBLOBs reportData = reportDataList.get(0); - - -// SqlSession sqlSession = sqlSessionFactory.openSession(false); -// TestPlanReportDataMapper updateReportDataMapper = sqlSession.getMapper(TestPlanReportDataMapper.class); -// updateReportDataMapper.updateByPrimaryKeySelective(reportData); -// sqlSession.commit(); -// sqlSession.flushStatements(); - - - report = this.updateReport(reportData, apiCaseExecuteOk, scenarioExecuteOk, performanceExecuteOk, updateTime); + report = this.updateReport(reportData,updateTime,executeInfo); } else { - testPlanLog.info("ReportId[" + planReportId + "] CANNOT FIND REPORT! Execited result. api :" + JSONObject.toJSONString(executeApiCaseIdMap) + "; scenario:" + JSONObject.toJSONString(executeScenarioCaseIdMap) + "; performance:" + JSONObject.toJSONString(executePerformanceIdMap)); + TestPlanReportExecuteCatch.setReportDataCheckResult(planReportId,false); } return report; @@ -1249,4 +1060,18 @@ public class TestPlanReportService { } this.delete(testPlanReportIdList); } + + public void countReport(String planReportId) { + TestPlanExecuteInfo executeInfo = TestPlanReportExecuteCatch.getTestPlanExecuteInfo(planReportId); + int unFinishNum = executeInfo.countUnFinishedNum(); + if(unFinishNum > 0){ + //如果间隔超过5分钟没有案例执行完成,则把执行结果变成false + long lastCountTime = executeInfo.getLastFinishedNumCountTime(); + long nowTime = System.currentTimeMillis(); + if(nowTime - lastCountTime > 300000){ + TestPlanReportExecuteCatch.finishAllTask(planReportId); + } + } + this.updateExecuteApis(planReportId); + } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 88543b1e9f..32ba31ee3b 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import io.metersphere.api.cache.TestPlanReportExecuteCatch; import io.metersphere.api.dto.APIReportResult; import io.metersphere.api.dto.automation.*; import io.metersphere.api.dto.definition.ApiTestCaseRequest; @@ -62,6 +63,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -75,6 +77,8 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -168,6 +172,8 @@ public class TestPlanService { @Resource private IssueTemplateService issueTemplateService; + private final ExecutorService executorService = Executors.newFixedThreadPool(20); + public synchronized TestPlan addTestPlan(AddTestPlanRequest testPlan) { if (getTestPlanByName(testPlan.getName()).size() > 0) { MSException.throwException(Translator.get("plan_name_already_exists")); @@ -979,13 +985,14 @@ public class TestPlanService { return returnId; } + @Transactional(propagation = Propagation.NOT_SUPPORTED) public String run(String testPlanID, String projectID, String userId, String triggerMode, String apiRunConfig) { //创建测试报告,然后返回的ID重新赋值为resourceID,作为后续的参数 TestPlanScheduleReportInfoDTO reportInfoDTO = testPlanReportService.genTestPlanReportBySchedule(projectID, testPlanID, userId, triggerMode); TestPlanReport testPlanReport = reportInfoDTO.getTestPlanReport(); Map planScenarioIdMap = reportInfoDTO.getPlanScenarioIdMap(); - Map apiTestCaseIdMap = reportInfoDTO.getApiTestCaseIdMap(); + Map apiTestCaseDataMap = reportInfoDTO.getApiTestCaseDataMap(); Map performanceIdMap = reportInfoDTO.getPerformanceIdMap(); String planReportId = testPlanReport.getId(); @@ -1042,61 +1049,106 @@ public class TestPlanService { } - for (Map.Entry entry : apiTestCaseIdMap.entrySet()) { - String apiCaseID = entry.getKey(); - executeApiCaseIdMap.put(apiCaseID, TestPlanApiExecuteStatus.RUNNING.name()); + for (Map.Entry entry : apiTestCaseDataMap.entrySet()) { + ApiTestCaseWithBLOBs model = entry.getKey(); + executeApiCaseIdMap.put(model.getId(), TestPlanApiExecuteStatus.RUNNING.name()); } for (String id : planScenarioIdMap.keySet()) { executeScenarioCaseIdMap.put(id, TestPlanApiExecuteStatus.RUNNING.name()); } testPlanLog.info("ReportId[" + planReportId + "] start run. TestPlanID:[" + testPlanID + "]. Execute api :" + JSONObject.toJSONString(executeApiCaseIdMap) + "; Execute scenario:" + JSONObject.toJSONString(executeScenarioCaseIdMap) + "; Execute performance:" + JSONObject.toJSONString(executePerformanceIdMap)); - testPlanReportService.updateExecuteApis(planReportId, executeApiCaseIdMap, executeScenarioCaseIdMap, executePerformanceIdMap); - +// testPlanReportService.updateExecuteApis(planReportId, executeApiCaseIdMap, executeScenarioCaseIdMap, executePerformanceIdMap); + TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(planReportId,executeApiCaseIdMap,executeScenarioCaseIdMap,executePerformanceIdMap); //执行接口案例任务 - for (Map.Entry entry : apiTestCaseIdMap.entrySet()) { - String apiCaseID = entry.getKey(); -// String planCaseID = entry.getValue(); - ApiTestCaseWithBLOBs blobs = apiTestCaseService.get(apiCaseID); - //需要更新这里来保证PlanCase的状态能正常更改 - if (StringUtils.equals(triggerMode, ReportTriggerMode.API.name())) { - apiTestCaseService.run(blobs, UUID.randomUUID().toString(), planReportId, testPlanID, ApiRunMode.JENKINS_API_PLAN.name()); - } else { - apiTestCaseService.run(blobs, UUID.randomUUID().toString(), planReportId, testPlanID, ApiRunMode.SCHEDULE_API_PLAN.name()); - } - executeApiCaseIdMap.put(apiCaseID, TestPlanApiExecuteStatus.RUNNING.name()); - } - + this.executeApiTestCase(triggerMode,planReportId,testPlanID,apiTestCaseDataMap); //执行场景执行任务 - if (!planScenarioIdMap.isEmpty()) { - SchedulePlanScenarioExecuteRequest scenarioRequest = new SchedulePlanScenarioExecuteRequest(); - String senarionReportID = UUID.randomUUID().toString(); - scenarioRequest.setId(senarionReportID); - scenarioRequest.setReportId(senarionReportID); - scenarioRequest.setProjectId(projectID); - if (StringUtils.equals(triggerMode, ReportTriggerMode.API.name())) { - scenarioRequest.setTriggerMode(ReportTriggerMode.API.name()); - scenarioRequest.setRunMode(ApiRunMode.JENKINS_SCENARIO_PLAN.name()); - - } else { - scenarioRequest.setTriggerMode(ReportTriggerMode.SCHEDULE.name()); - scenarioRequest.setRunMode(ApiRunMode.SCHEDULE_SCENARIO_PLAN.name()); - } - scenarioRequest.setExecuteType(ExecuteType.Saved.name()); - Map> testPlanScenarioIdMap = new HashMap<>(); - testPlanScenarioIdMap.put(testPlanID, planScenarioIdMap); - scenarioRequest.setTestPlanScenarioIDMap(testPlanScenarioIdMap); - scenarioRequest.setReportUserID(userId); - scenarioRequest.setTestPlanID(testPlanID); - - scenarioRequest.setTestPlanReportId(planReportId); - RunModeConfig runModeConfig = JSONObject.parseObject(apiRunConfig, RunModeConfig.class); - scenarioRequest.setConfig(runModeConfig); - String scenarioReportID = this.scenarioRunModeConfig(scenarioRequest); - } + this.executeScenarioCase(planReportId,testPlanID,projectID,apiRunConfig,triggerMode,userId,planScenarioIdMap); + this.listenTaskExecuteStatus(planReportId); return testPlanReport.getId(); } + private void listenTaskExecuteStatus(String planReportId) { + executorService.submit(()->{ + try { + Thread.sleep(30000); + while (TestPlanReportExecuteCatch.getTestPlanExecuteInfo(planReportId) != null){ + testPlanReportService.countReport(planReportId); + Thread.sleep(30000); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + + }); + } + + private void executeApiTestCase(String triggerMode, String planReportId,String testPlanId,Map apiTestCaseDataMap) { + executorService.submit(() -> { + Map executeErrorMap = new HashMap<>(); + for (Map.Entry entry : apiTestCaseDataMap.entrySet()) { + ApiTestCaseWithBLOBs blobs = entry.getKey(); + try{ + if (StringUtils.equals(triggerMode, ReportTriggerMode.API.name())) { + apiTestCaseService.run(blobs, UUID.randomUUID().toString(), planReportId, testPlanId, ApiRunMode.JENKINS_API_PLAN.name()); + } else { + apiTestCaseService.run(blobs, UUID.randomUUID().toString(), planReportId, testPlanId, ApiRunMode.SCHEDULE_API_PLAN.name()); + } + }catch (Exception e){ + executeErrorMap.put(blobs.getId(),TestPlanApiExecuteStatus.FAILD.name()); + } + } + + if(!executeErrorMap.isEmpty()){ + TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(planReportId,executeErrorMap,null,null); + } + }); + } + + private void executeScenarioCase(String planReportId,String testPlanID,String projectID, String apiRunConfig, String triggerMode, String userId, Map planScenarioIdMap) { + executorService.submit(()->{ + if (!planScenarioIdMap.isEmpty()) { + SchedulePlanScenarioExecuteRequest scenarioRequest = new SchedulePlanScenarioExecuteRequest(); + String senarionReportID = UUID.randomUUID().toString(); + scenarioRequest.setId(senarionReportID); + scenarioRequest.setReportId(senarionReportID); + scenarioRequest.setProjectId(projectID); + if (StringUtils.equals(triggerMode, ReportTriggerMode.API.name())) { + scenarioRequest.setTriggerMode(ReportTriggerMode.API.name()); + scenarioRequest.setRunMode(ApiRunMode.JENKINS_SCENARIO_PLAN.name()); + + } else { + scenarioRequest.setTriggerMode(ReportTriggerMode.SCHEDULE.name()); + scenarioRequest.setRunMode(ApiRunMode.SCHEDULE_SCENARIO_PLAN.name()); + } + scenarioRequest.setExecuteType(ExecuteType.Saved.name()); + Map> testPlanScenarioIdMap = new HashMap<>(); + testPlanScenarioIdMap.put(testPlanID, planScenarioIdMap); + scenarioRequest.setTestPlanScenarioIDMap(testPlanScenarioIdMap); + scenarioRequest.setReportUserID(userId); + scenarioRequest.setTestPlanID(testPlanID); + + scenarioRequest.setTestPlanReportId(planReportId); + RunModeConfig runModeConfig = null; + try { + runModeConfig = JSONObject.parseObject(apiRunConfig, RunModeConfig.class); + runModeConfig.setOnSampleError(false); + }catch(Exception e){ + e.printStackTrace(); + } + if (runModeConfig == null){ + runModeConfig = new RunModeConfig(); + runModeConfig.setMode("serial"); + runModeConfig.setReportType("iddReport"); + runModeConfig.setOnSampleError(false); + } + + scenarioRequest.setConfig(runModeConfig); + this.scenarioRunModeConfig(scenarioRequest); + } + }); + } + public String getLogDetails(String id) { TestPlan plan = testPlanMapper.selectByPrimaryKey(id); if (plan != null) { diff --git a/backend/src/main/resources/db/migration/V93__v1.12_release.sql b/backend/src/main/resources/db/migration/V93__v1.12_release.sql index b219f916b2..14c03c8f7d 100644 --- a/backend/src/main/resources/db/migration/V93__v1.12_release.sql +++ b/backend/src/main/resources/db/migration/V93__v1.12_release.sql @@ -96,3 +96,6 @@ ALTER TABLE share_info change SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'Share Custom Data'; ALTER TABLE test_plan ADD report_config text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '测试计划报告配置'; + +-- 删除不用的记录表 +DROP TABLE test_plan_report_resource; \ No newline at end of file diff --git a/frontend/src/business/components/api/definition/components/complete/EditCompleteTCPApi.vue b/frontend/src/business/components/api/definition/components/complete/EditCompleteTCPApi.vue index 747385c5af..036a03d147 100644 --- a/frontend/src/business/components/api/definition/components/complete/EditCompleteTCPApi.vue +++ b/frontend/src/business/components/api/definition/components/complete/EditCompleteTCPApi.vue @@ -25,7 +25,7 @@

{{ $t('test_track.plan_view.mock_info') }}

- + Mock地址: {{ this.mockInfo }} @@ -34,6 +34,9 @@ type="primary">当前项目未开启Mock服务 + + Mock设置 +
@@ -60,7 +63,7 @@ import MsTcpBasicApi from "./TCPBasicApi"; import MsTcpFormatParameters from "../request/tcp/TcpFormatParameters"; import MsChangeHistory from "../../../../history/ChangeHistory"; -import {hasLicense,getCurrentProjectID} from "@/common/js/utils"; +import {hasLicense, getCurrentProjectID, getUUID} from "@/common/js/utils"; const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/); const esbDefinition = (requireComponent!=null&&requireComponent.keys().length) > 0 ? requireComponent("./apidefinition/EsbDefinition.vue") : {}; @@ -214,6 +217,9 @@ export default { this.mockInfo = response.data; }); }, + mockSetting() { + this.$store.state.currentApiCase={mock : getUUID()}; + }, }, }