jmeter性能测试及报告功能全量提交

This commit is contained in:
liangdaliang
2025-04-18 10:56:21 +08:00
parent e160bd8866
commit 6d4e38b1fd
13 changed files with 460 additions and 34 deletions

View File

@@ -1,7 +1,17 @@
package com.test.test.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.test.common.annotation.Log;
import com.test.common.core.controller.BaseController;
import com.test.common.core.domain.AjaxResult;
import com.test.common.core.page.TableDataInfo;
import com.test.common.enums.BusinessType;
import com.test.test.domain.PerformanceTestCaseReport;
import com.test.test.service.IPerformanceTestCaseReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
/**
* @author liangdaliang
@@ -10,5 +20,43 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("/test/performanceReport")
public class PerformanceReportController {
public class PerformanceReportController extends BaseController {
@Autowired
private IPerformanceTestCaseReportService performanceTestCaseReportService;
@PostMapping("/list")
public TableDataInfo list(@RequestBody PerformanceTestCaseReport input)
{
startPage();
input.setDelFlag("0");
List<PerformanceTestCaseReport> list = performanceTestCaseReportService.selectPerformanceTestCaseReportList(input);
return getDataTable(list);
}
/**
* 获取单个性能测试报告详细信息
*/
@GetMapping(value = "/getInfo/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(performanceTestCaseReportService.selectPerformanceTestCaseReportById(id));
}
/**
* 删除性能测试报告详细信息
*/
@Log(title = "性能测试", businessType = BusinessType.UPDATE)
@PutMapping("/delete/{id}")
public AjaxResult remove(@PathVariable Long id)
{
PerformanceTestCaseReport report = performanceTestCaseReportService.selectPerformanceTestCaseReportById(id);
if (report != null) {
report.setDelFlag("1");
report.setUpdateTime(new Date());
return toAjax(performanceTestCaseReportService.updatePerformanceTestCaseReport(report));
} else {
return null;
}
}
}

View File

@@ -80,6 +80,9 @@ public class PerformanceTestCaseReport extends BaseEntity
/** 删除标记:0正常1删除 */
private String delFlag;
/** 用例名称 */
private String name;
public Long getId() {
return id;
}
@@ -207,4 +210,12 @@ public class PerformanceTestCaseReport extends BaseEntity
public void setDelFlag(String delFlag) {
this.delFlag = delFlag;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@@ -17,8 +17,9 @@ public interface IPerformanceTestCaseReportService
* @param id
* @param jmeterHomePath
* @param triggerType 触发方式1-定时任务2-手动
* @return 返回本次性能测试的批次id
*/
public void executePerformanceTestAndReport(Long id, String jmeterHomePath, Integer triggerType);
public Long executePerformanceTestAndReport(Long id, String jmeterHomePath, Integer triggerType);
/**
* 查询性能测试用例报告

View File

@@ -1,10 +1,8 @@
package com.test.test.service.impl;
import com.google.gson.Gson;
import com.test.common.core.domain.model.JmeterGroupRequest;
import com.test.common.core.domain.model.JmeterRequest;
import com.test.common.core.domain.model.LabelStatsEntity;
import com.test.common.core.domain.model.LoginUser;
import com.google.gson.GsonBuilder;
import com.test.common.core.domain.model.*;
import com.test.common.utils.DateUtils;
import com.test.common.utils.JMeterGroupUtil;
import com.test.common.utils.SecurityUtils;
@@ -49,7 +47,7 @@ public class PerformanceTestCaseReportServiceImpl implements IPerformanceTestCas
private ITestCaseStepService testCaseStepService;
@Override
public void executePerformanceTestAndReport(Long id, String jmeterHomePath, Integer triggerType) {
public Long executePerformanceTestAndReport(Long id, String jmeterHomePath, Integer triggerType) {
Long sid = System.currentTimeMillis();
PerformanceTest performanceTest = performanceTestMapper.selectPerformanceTestById(id);
PerformanceTestCase performanceTestCase = new PerformanceTestCase();
@@ -74,9 +72,13 @@ public class PerformanceTestCaseReportServiceImpl implements IPerformanceTestCas
List<JmeterRequest> jmeterRequestList = dealAddTestCaseHttpStep(testCaseStepList);
jmeterGroupRequest.setJmeterRequestList(jmeterRequestList);
Date startTime = new Date();
List<LabelStatsEntity> jmeterResultList = JMeterGroupUtil.getJmeterResult(jmeterGroupRequest);
JmeterGlobalStatEntity jmeterGlobalStatEntity = JMeterGroupUtil.getJmeterResult(jmeterGroupRequest);
List<LabelStatsEntity> jmeterResultList = jmeterGlobalStatEntity.getStatsEntityList();
ErrorTotalStats errorTotalStats = jmeterGlobalStatEntity.getErrorTotalStats();
Date endTime = new Date();
Gson gson = new Gson();
Gson gson = new GsonBuilder()
.serializeSpecialFloatingPointValues()
.create();
if (!CollectionUtils.isEmpty(jmeterResultList)) {
LabelStatsEntity lastElement = jmeterResultList.get(jmeterResultList.size() - 1);
PerformanceTestCaseReport performanceTestCaseReport = new PerformanceTestCaseReport();
@@ -91,7 +93,7 @@ public class PerformanceTestCaseReportServiceImpl implements IPerformanceTestCas
performanceTestCaseReport.setCostTime(endTime.getTime() - startTime.getTime());
performanceTestCaseReport.setTriggerType(triggerType);
performanceTestCaseReport.setSummaryReport(gson.toJson(jmeterResultList));
performanceTestCaseReport.setErrorReport("");
performanceTestCaseReport.setErrorReport(gson.toJson(errorTotalStats));
performanceTestCaseReport.setStatus("1");
LoginUser user = null;
try {
@@ -110,6 +112,7 @@ public class PerformanceTestCaseReportServiceImpl implements IPerformanceTestCas
performanceTest.setStatus("1");
performanceTest.setUpdateTime(new Date());
performanceTestMapper.updatePerformanceTest(performanceTest);
return sid;
}
/**

View File

@@ -19,6 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="summaryReport" column="summary_report" />
<result property="errorReport" column="error_report" />
<result property="applyUser" column="apply_user" />
<result property="name" column="name" />
<result property="status" column="status" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
@@ -32,22 +33,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectPerformanceTestCaseReportList" parameterType="PerformanceTestCaseReport" resultMap="PerformanceTestCaseReportResult">
<include refid="selectPerformanceTestCaseReportVo"/>
select a.id, a.performance_id, a.test_case_id, b.name, a.sid, a.concurrent_threads, a.average, a.tps, a.start_time, a.end_time, a.cost_time, a.trigger_type, a.status, a.create_by, a.update_by, a.create_time, a.update_time
from performance_test_case_report a left join test_case b on a.test_case_id = b.id
<where>
<if test="performanceId != null "> and performance_id = #{performanceId}</if>
<if test="testCaseId != null "> and test_case_id = #{testCaseId}</if>
<if test="sid != null "> and sid = #{sid}</if>
<if test="concurrentThreads != null "> and concurrent_threads = #{concurrentThreads}</if>
<if test="average != null "> and average = #{average}</if>
<if test="tps != null and tps != ''"> and tps = #{tps}</if>
<if test="startTime != null "> and start_time = #{startTime}</if>
<if test="endTime != null "> and end_time = #{endTime}</if>
<if test="costTime != null "> and cost_time = #{costTime}</if>
<if test="triggerType != null "> and trigger_type = #{triggerType}</if>
<if test="summaryReport != null and summaryReport != ''"> and summary_report = #{summaryReport}</if>
<if test="errorReport != null and errorReport != ''"> and error_report = #{errorReport}</if>
<if test="applyUser != null and applyUser != ''"> and apply_user = #{applyUser}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="performanceId != null "> and a.performance_id = #{performanceId}</if>
<if test="testCaseId != null "> and a.test_case_id = #{testCaseId}</if>
<if test="sid != null "> and a.sid = #{sid}</if>
<if test="name != null and name != ''"> and b.name like concat('%', #{name}, '%')</if>
<if test="startTime != null "> and a.start_time = #{startTime}</if>
<if test="endTime != null "> and a.end_time = #{endTime}</if>
<if test="costTime != null "> and a.cost_time = #{costTime}</if>
<if test="triggerType != null "> and a.trigger_type = #{triggerType}</if>
<if test="delFlag != null and delFlag != ''"> and a.del_flag = #{delFlag}</if>
<if test="status != null and status != ''"> and a.status = #{status}</if>
</where>
</select>