fix(性能测试): 修复同步接口用例没有实时更新的问题

--bug=1017983 --user=刘瑞斌 【性能测试】同步场景测试最新变更更新后下载jtl请求无变化 https://www.tapd.cn/55049933/s/1261952
This commit is contained in:
CaptainB 2022-10-14 16:04:09 +08:00 committed by 刘瑞斌
parent 0d617a8c97
commit 843087819d
2 changed files with 35 additions and 22 deletions

View File

@ -0,0 +1,13 @@
package io.metersphere.api.dto;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
public class ApiCaseExportJmxRequest {
private List<String> caseIds;
private String envId;
}

View File

@ -1,9 +1,6 @@
package io.metersphere.api.service;
import io.metersphere.api.dto.ApiLoadType;
import io.metersphere.api.dto.ApiScenarioBatchRequest;
import io.metersphere.api.dto.ApiScenarioExportJmxDTO;
import io.metersphere.api.dto.ScenarioToPerformanceInfoDTO;
import io.metersphere.api.dto.*;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiLoadTestMapper;
import io.metersphere.base.mapper.LoadTestFileMapper;
@ -54,6 +51,10 @@ public class ApiPerformanceService {
return microService.postForData(MicroServiceName.API_TEST, "/api/automation/export/jmx", request, ScenarioToPerformanceInfoDTO.class);
}
public List<JmxInfoDTO> exportApiCaseJmx(Object request) {
return microService.postForDataArray(MicroServiceName.API_TEST, "/api/testcase/export/jmx", request, JmxInfoDTO.class);
}
public Object list(int goPage, int pageSize, Object request) {
return microService.postForResultHolder(MicroServiceName.API_TEST, "/api/automation/list/" + goPage + "/" + pageSize, request);
}
@ -119,7 +120,7 @@ public class ApiPerformanceService {
.filter(i -> i.getType().equals(ApiLoadType.SCENARIO.name()))
.map(ApiLoadTest::getApiId)
.collect(Collectors.toList());
if (!org.apache.commons.collections4.CollectionUtils.isEmpty(scenarioIds)) {
if (!CollectionUtils.isEmpty(scenarioIds)) {
ApiScenarioBatchRequest scenarioRequest = new ApiScenarioBatchRequest();
scenarioRequest.setIds(scenarioIds);
List<ApiScenarioExportJmxDTO> apiScenrioExportJmxes = this.exportJmx(scenarioRequest).getScenarioJmxList();
@ -135,23 +136,22 @@ public class ApiPerformanceService {
}
public void syncApiCase(LoadTestWithBLOBs loadTest, List<ApiLoadTest> apiLoadTests) {
// todo
// List<String> caseIds = apiLoadTests.stream()
// .filter(i -> i.getType().equals(ApiLoadType.API_CASE.name()))
// .map(ApiLoadTest::getApiId)
// .collect(Collectors.toList());
// if (!org.apache.commons.collections4.CollectionUtils.isEmpty(caseIds)) {
// ApiScenarioBatchRequest scenarioRequest = new ApiScenarioBatchRequest();
// scenarioRequest.setIds(caseIds);
//
// List<JmxInfoDTO> jmxInfoDTOS = apiTestCaseService.exportJmx(caseIds, apiLoadTests.get(0).getEnvId());
// deleteLoadTestFiles(loadTest.getId());
// jmxInfoDTOS.forEach(item -> {
// this.updateVersion(loadTest.getId(), item.getId(), item.getVersion());
// saveJmxFile(item.getXml(), item.getName(), loadTest.getProjectId(), loadTest.getId());
// saveBodyFile(item.getFileMetadataList(), loadTest.getId(), item.getId());
// });
// }
List<String> caseIds = apiLoadTests.stream()
.filter(i -> i.getType().equals(ApiLoadType.API_CASE.name()))
.map(ApiLoadTest::getApiId)
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(caseIds)) {
ApiCaseExportJmxRequest request = new ApiCaseExportJmxRequest();
request.setCaseIds(caseIds);
request.setEnvId(apiLoadTests.get(0).getEnvId());
List<JmxInfoDTO> jmxInfoDTOS = this.exportApiCaseJmx(request);
deleteLoadTestFiles(loadTest.getId());
jmxInfoDTOS.forEach(item -> {
this.updateVersion(loadTest.getId(), item.getId(), item.getVersion());
saveJmxFile(item.getXml(), item.getName(), loadTest.getProjectId(), loadTest.getId());
saveBodyFile(item.getFileMetadataList(), loadTest.getId(), item.getId());
});
}
}