diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 36b4c9c8ab..3852db12a7 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -158,7 +158,8 @@ public class MsHTTPSamplerProxy extends MsTestElement { if (!path.startsWith("/")) { path = "/" + path; } - path = sampler.getProtocol() + "://" + sampler.getDomain() + ":" + sampler.getPort() + path; + String port = sampler.getPort() != 80 ? ":" + sampler.getPort() : ""; + path = sampler.getProtocol() + "://" + sampler.getDomain() + port + path; } sampler.setPath(path); } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java index a918fd4589..554d8fb504 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java @@ -24,7 +24,6 @@ import org.apache.jmeter.testelement.TestElement; import org.apache.jorphan.collections.HashTree; import java.util.List; -import java.util.stream.Collectors; @Data @EqualsAndHashCode(callSuper = true) @@ -51,7 +50,7 @@ public class MsJDBCSampler extends MsTestElement { @JSONField(ordinal = 28) private String dataSourceId; @JSONField(ordinal = 29) - private String protocol="SQL"; + private String protocol = "SQL"; @Override public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { @@ -62,7 +61,8 @@ public class MsJDBCSampler extends MsTestElement { this.getRefElement(this); } if (StringUtils.isNotEmpty(dataSourceId)) { - initDataSource(); + this.dataSource = null; + this.initDataSource(); } if (this.dataSource == null) { MSException.throwException("数据源为空无法执行"); @@ -79,14 +79,16 @@ public class MsJDBCSampler extends MsTestElement { private void initDataSource() { ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); - ApiTestEnvironmentWithBLOBs environment = environmentService.get(this.dataSourceId); + ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentId); if (environment != null && environment.getConfig() != null) { - EnvironmentConfig config = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); - if (CollectionUtils.isNotEmpty(config.getDatabaseConfigs())) { - List databaseConfigs = config.getDatabaseConfigs().stream().filter((DatabaseConfig d) -> this.dataSourceId.equals(d.getId())).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(databaseConfigs)) { - this.dataSource = databaseConfigs.get(0); - } + EnvironmentConfig envConfig = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); + if (CollectionUtils.isNotEmpty(envConfig.getDatabaseConfigs())) { + envConfig.getDatabaseConfigs().forEach(item -> { + if (item.getId().equals(this.dataSourceId)) { + this.dataSource = item; + return; + } + }); } } } diff --git a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java index 489d58abfb..ae9fbf35be 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -297,6 +297,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl requestResult.setHeaders(result.getRequestHeaders()); requestResult.setRequestSize(result.getSentBytes()); requestResult.setStartTime(result.getStartTime()); + requestResult.setEndTime(result.getEndTime()); requestResult.setTotalAssertions(result.getAssertionResults().length); requestResult.setSuccess(result.isSuccessful()); requestResult.setError(result.getErrorCount()); diff --git a/backend/src/main/java/io/metersphere/api/jmeter/RequestResult.java b/backend/src/main/java/io/metersphere/api/jmeter/RequestResult.java index d3c20cac4e..b90c0c0db0 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/RequestResult.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/RequestResult.java @@ -18,6 +18,8 @@ public class RequestResult { private long startTime; + private long endTime; + private int error; private boolean success; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index 6a7a8a4634..022a7f36d3 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -323,7 +323,9 @@ public class ApiDefinitionService { apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition); } } else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) { - batchMapper.insert(apiDefinition); + if (CollectionUtils.isEmpty(sameRequest)) { + batchMapper.insert(apiDefinition); + } } else { if (CollectionUtils.isEmpty(sameRequest)) { batchMapper.insert(apiDefinition); 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 f30550e488..6c945f5d2e 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -163,6 +163,7 @@ public class ApiScenarioReportService { String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError())); testPlanApiScenario.setPassRate(passRate); testPlanApiScenario.setReportId(report.getId()); + testPlanApiScenario.setUpdateTime(System.currentTimeMillis()); testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario); } returnReport = report; @@ -220,6 +221,7 @@ public class ApiScenarioReportService { apiScenarioReportDetailMapper.insert(detail); testPlanApiScenario.setReportId(report.getId()); + testPlanApiScenario.setUpdateTime(System.currentTimeMillis()); testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario); lastReport = report; @@ -343,13 +345,41 @@ public class ApiScenarioReportService { ids = allIds.stream().filter(id -> !reportRequest.getUnSelectIds().contains(id)).collect(Collectors.toList()); } - ApiScenarioReportDetailExample detailExample = new ApiScenarioReportDetailExample(); - detailExample.createCriteria().andReportIdIn(ids); - apiScenarioReportDetailMapper.deleteByExample(detailExample); + //为预防数量太多,调用删除方法时引起SQL过长的Bug,此处采取分批执行的方式。 + //每次处理的数据数量 + int handleCount = 7000; + //每次处理的集合 + List handleIdList = new ArrayList<>(handleCount); + while (ids.size() > handleCount){ + handleIdList = new ArrayList<>(handleCount); + List otherIdList = new ArrayList<>(); + for (int index = 0;index < ids.size();index++){ + if(index and (api_definition.name like CONCAT('%', #{request.name},'%') - or api_definition.tags like CONCAT('%', #{request.name},'%')) + or api_definition.tags like CONCAT('%', #{request.name},'%') + or api_definition.num like CONCAT('%', #{request.name},'%')) AND api_definition.protocol = #{request.protocol} diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml index 1f391c031a..415d22029b 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml @@ -143,7 +143,9 @@ - and (api_scenario.name like CONCAT('%', #{request.name},'%') or api_scenario.tags like CONCAT('%', #{request.name},'%')) + and (api_scenario.name like CONCAT('%', #{request.name},'%') + or api_scenario.tags like CONCAT('%', #{request.name},'%') + or api_scenario.num like CONCAT('%', #{request.name},'%')) AND project.workspace_id = #{request.workspaceId} diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml index dadfca7047..6d0445ee17 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml @@ -284,7 +284,9 @@ - and (t1.name like CONCAT('%', #{request.name},'%') or t1.tags like CONCAT('%', #{request.name},'%')) + and (t1.name like CONCAT('%', #{request.name},'%') + or t1.tags like CONCAT('%', #{request.name},'%') + or t1.num like CONCAT('%', #{request.name},'%')) and t1.create_time >= #{request.createTime} diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml index 9b56ef1f8d..fabf6ce1da 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml @@ -122,7 +122,7 @@