refactor(性能测试): 修改性能测试报告页面报错的弹框

--bug=1010368 --user=刘瑞斌 [性能测试] github#10684性能执行过程中,执行时长,开始时间显示异常 https://www.tapd.cn/55049933/s/1108562

Closes #10684
This commit is contained in:
CaptainB 2022-02-23 13:24:34 +08:00 committed by CountryBuilder
parent 028aef7c70
commit 687267923a
2 changed files with 37 additions and 16 deletions

View File

@ -43,7 +43,10 @@ import javax.servlet.http.HttpServletResponse;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@ -173,31 +176,41 @@ public class PerformanceReportService {
} }
public List<Statistics> getReportStatistics(String id) { public List<Statistics> getReportStatistics(String id) {
checkReportStatus(id); if (isReportError(id)) {
return Collections.emptyList();
}
String reportValue = getContent(id, ReportKeys.RequestStatistics); String reportValue = getContent(id, ReportKeys.RequestStatistics);
return JSON.parseArray(reportValue, Statistics.class); return JSON.parseArray(reportValue, Statistics.class);
} }
public List<Errors> getReportErrors(String id) { public List<Errors> getReportErrors(String id) {
checkReportStatus(id); if (isReportError(id)) {
return Collections.emptyList();
}
String content = getContent(id, ReportKeys.Errors); String content = getContent(id, ReportKeys.Errors);
return JSON.parseArray(content, Errors.class); return JSON.parseArray(content, Errors.class);
} }
public List<ErrorsTop5> getReportErrorsTOP5(String id) { public List<ErrorsTop5> getReportErrorsTOP5(String id) {
checkReportStatus(id); if (isReportError(id)) {
return Collections.emptyList();
}
String content = getContent(id, ReportKeys.ErrorsTop5); String content = getContent(id, ReportKeys.ErrorsTop5);
return JSON.parseArray(content, ErrorsTop5.class); return JSON.parseArray(content, ErrorsTop5.class);
} }
public TestOverview getTestOverview(String id) { public TestOverview getTestOverview(String id) {
checkReportStatus(id); if (isReportError(id)) {
return new TestOverview();
}
String content = getContent(id, ReportKeys.Overview); String content = getContent(id, ReportKeys.Overview);
return JSON.parseObject(content, TestOverview.class); return JSON.parseObject(content, TestOverview.class);
} }
public ReportTimeInfo getReportTimeInfo(String id) { public ReportTimeInfo getReportTimeInfo(String id) {
checkReportStatus(id); if (isReportError(id)) {
return new ReportTimeInfo();
}
String content = getContent(id, ReportKeys.TimeInfo); String content = getContent(id, ReportKeys.TimeInfo);
try { try {
return JSON.parseObject(content, ReportTimeInfo.class); return JSON.parseObject(content, ReportTimeInfo.class);
@ -221,26 +234,28 @@ public class PerformanceReportService {
} }
public List<ChartsData> getLoadChartData(String id) { public List<ChartsData> getLoadChartData(String id) {
checkReportStatus(id); if (isReportError(id)) {
return Collections.emptyList();
}
String content = getContent(id, ReportKeys.LoadChart); String content = getContent(id, ReportKeys.LoadChart);
return JSON.parseArray(content, ChartsData.class); return JSON.parseArray(content, ChartsData.class);
} }
public List<ChartsData> getResponseTimeChartData(String id) { public List<ChartsData> getResponseTimeChartData(String id) {
checkReportStatus(id); if (isReportError(id)) {
return Collections.emptyList();
}
String content = getContent(id, ReportKeys.ResponseTimeChart); String content = getContent(id, ReportKeys.ResponseTimeChart);
return JSON.parseArray(content, ChartsData.class); return JSON.parseArray(content, ChartsData.class);
} }
public void checkReportStatus(String reportId) { public boolean isReportError(String reportId) {
LoadTestReport loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId); LoadTestReport loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId);
String reportStatus = ""; String reportStatus = "";
if (loadTestReport != null) { if (loadTestReport != null) {
reportStatus = loadTestReport.getStatus(); reportStatus = loadTestReport.getStatus();
} }
if (StringUtils.equals(PerformanceTestStatus.Error.name(), reportStatus)) { return StringUtils.equals(PerformanceTestStatus.Error.name(), reportStatus);
MSException.throwException("Report generation error!");
}
} }
public LoadTestReportWithBLOBs getLoadTestReport(String id) { public LoadTestReportWithBLOBs getLoadTestReport(String id) {
@ -329,13 +344,17 @@ public class PerformanceReportService {
} }
public List<ChartsData> getErrorChartData(String id) { public List<ChartsData> getErrorChartData(String id) {
checkReportStatus(id); if (isReportError(id)) {
return Collections.emptyList();
}
String content = getContent(id, ReportKeys.ErrorsChart); String content = getContent(id, ReportKeys.ErrorsChart);
return JSON.parseArray(content, ChartsData.class); return JSON.parseArray(content, ChartsData.class);
} }
public List<ChartsData> getResponseCodeChartData(String id) { public List<ChartsData> getResponseCodeChartData(String id) {
checkReportStatus(id); if (isReportError(id)) {
return Collections.emptyList();
}
String content = getContent(id, ReportKeys.ResponseCodeChart); String content = getContent(id, ReportKeys.ResponseCodeChart);
return JSON.parseArray(content, ChartsData.class); return JSON.parseArray(content, ChartsData.class);
} }
@ -423,7 +442,9 @@ public class PerformanceReportService {
} }
public List<ChartsData> getReportChart(String reportKey, String reportId) { public List<ChartsData> getReportChart(String reportKey, String reportId) {
checkReportStatus(reportId); if (isReportError(reportId)) {
return Collections.emptyList();
}
try { try {
String content = getContent(reportId, ReportKeys.valueOf(reportKey)); String content = getContent(reportId, ReportKeys.valueOf(reportKey));
return JSON.parseArray(content, ChartsData.class); return JSON.parseArray(content, ChartsData.class);

View File

@ -330,7 +330,7 @@ export default {
this.$set(this.report, "refresh", e.data); // this.$set(this.report, "refresh", e.data); //
if (e.data.startsWith('Error')) { if (e.data.startsWith('Error')) {
this.$set(this.report, "status", 'Error'); this.$set(this.report, "status", 'Error');
this.$warning(e.data); this.$error(e.data);
return; return;
} }
this.$set(this.report, "status", 'Running'); this.$set(this.report, "status", 'Running');