refactor(性能测试): 下载zip报错信息优化

This commit is contained in:
Captain.B 2021-09-24 13:17:35 +08:00 committed by 刘瑞斌
parent b27e21f082
commit ff083f6545
2 changed files with 5 additions and 8 deletions

View File

@ -48,7 +48,7 @@ public class JmeterFileController {
@RequestParam("ratio") String ratio, @RequestParam("ratio") String ratio,
@RequestParam("reportId") String reportId, @RequestParam("resourceIndex") int resourceIndex) { @RequestParam("reportId") String reportId, @RequestParam("resourceIndex") int resourceIndex) {
double[] ratios = Arrays.stream(ratio.split(",")).mapToDouble(Double::parseDouble).toArray(); double[] ratios = Arrays.stream(ratio.split(",")).mapToDouble(Double::parseDouble).toArray();
byte[] bytes = jmeterFileService.downloadZip(testId, ratios, reportId, resourceIndex); byte[] bytes = jmeterFileService.downloadZip(reportId, ratios, resourceIndex);
return ResponseEntity.ok() return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octet-stream")) .contentType(MediaType.parseMediaType("application/octet-stream"))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + testId + ".zip\"") .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + testId + ".zip\"")

View File

@ -1,9 +1,7 @@
package io.metersphere.performance.service; package io.metersphere.performance.service;
import com.alibaba.excel.util.CollectionUtils; import com.alibaba.excel.util.CollectionUtils;
import io.metersphere.base.domain.LoadTestReportWithBLOBs; import io.metersphere.base.domain.LoadTestReportWithBLOBs;
import io.metersphere.base.mapper.LoadTestMapper;
import io.metersphere.base.mapper.LoadTestReportMapper; import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
@ -25,18 +23,17 @@ import java.util.zip.ZipOutputStream;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class JmeterFileService { public class JmeterFileService {
@Resource
private LoadTestMapper loadTestMapper;
@Resource @Resource
private ExtLoadTestReportMapper extLoadTestReportMapper; private ExtLoadTestReportMapper extLoadTestReportMapper;
@Resource @Resource
private LoadTestReportMapper loadTestReportMapper; private LoadTestReportMapper loadTestReportMapper;
public byte[] downloadZip(String testId, double[] ratios, String reportId, int resourceIndex) { public byte[] downloadZip(String reportId, double[] ratios, int resourceIndex) {
try { try {
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId);
if (loadTestReport == null) {
MSException.throwException("测试报告不存在或还没产生");
}
EngineContext context = EngineFactory.createContext(loadTestReport, ratios, reportId, resourceIndex); EngineContext context = EngineFactory.createContext(loadTestReport, ratios, reportId, resourceIndex);
return zipFilesToByteArray(context); return zipFilesToByteArray(context);
} catch (MSException e) { } catch (MSException e) {