性能测试增加执行人
This commit is contained in:
@@ -120,6 +120,7 @@ public class PerformanceTestController extends BaseController {
|
|||||||
@PostMapping("/addAndExecute")
|
@PostMapping("/addAndExecute")
|
||||||
public AjaxResult addAndExecute(@RequestBody PerformanceTestQO performanceTestQO) {
|
public AjaxResult addAndExecute(@RequestBody PerformanceTestQO performanceTestQO) {
|
||||||
try {
|
try {
|
||||||
|
String createBy = getLoginUser().getUsername();
|
||||||
Long l = performanceTestService.insertPerformanceTest(performanceTestQO);
|
Long l = performanceTestService.insertPerformanceTest(performanceTestQO);
|
||||||
// 获取新增的任务完整信息
|
// 获取新增的任务完整信息
|
||||||
PerformanceTestVO newTaskVo = performanceTestService.selectPerformanceTestById(l);
|
PerformanceTestVO newTaskVo = performanceTestService.selectPerformanceTestById(l);
|
||||||
@@ -135,11 +136,9 @@ public class PerformanceTestController extends BaseController {
|
|||||||
// 执行性能测试
|
// 执行性能测试
|
||||||
try {
|
try {
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
performanceTestCaseReportService.executePerformanceTestAndReport(l, jmeterHomePath, 2);
|
performanceTestCaseReportService.executePerformanceTestAndReport(l, jmeterHomePath, 2, createBy);
|
||||||
});
|
});
|
||||||
return toAjax(true);
|
return toAjax(true);
|
||||||
// Long l1 = performanceTestCaseReportService.executePerformanceTestAndReport(l, jmeterHomePath, 2);
|
|
||||||
// return success(l1);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("执行失败!", e);
|
log.error("执行失败!", e);
|
||||||
return error("执行失败!");
|
return error("执行失败!");
|
||||||
@@ -184,6 +183,7 @@ public class PerformanceTestController extends BaseController {
|
|||||||
@Log(title = "性能测试", businessType = BusinessType.UPDATE)
|
@Log(title = "性能测试", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping("/editAndExecute")
|
@PutMapping("/editAndExecute")
|
||||||
public AjaxResult editAndExecute(@RequestBody PerformanceTestQO performanceTestQO) {
|
public AjaxResult editAndExecute(@RequestBody PerformanceTestQO performanceTestQO) {
|
||||||
|
String createBy = getLoginUser().getUsername();
|
||||||
try {
|
try {
|
||||||
PerformanceTestVO originalTask = performanceTestService.selectPerformanceTestById(performanceTestQO.getId());
|
PerformanceTestVO originalTask = performanceTestService.selectPerformanceTestById(performanceTestQO.getId());
|
||||||
Long l = performanceTestService.updatePerformanceTest(performanceTestQO);
|
Long l = performanceTestService.updatePerformanceTest(performanceTestQO);
|
||||||
@@ -200,11 +200,9 @@ public class PerformanceTestController extends BaseController {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
performanceTestCaseReportService.executePerformanceTestAndReport(l, jmeterHomePath, 2);
|
performanceTestCaseReportService.executePerformanceTestAndReport(l, jmeterHomePath, 2, createBy);
|
||||||
});
|
});
|
||||||
return toAjax(true);
|
return toAjax(true);
|
||||||
// Long l1 = performanceTestCaseReportService.executePerformanceTestAndReport(l, jmeterHomePath, 2);
|
|
||||||
// return success(l1);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("执行失败!", e);
|
log.error("执行失败!", e);
|
||||||
return error("执行失败!"+e);
|
return error("执行失败!"+e);
|
||||||
@@ -232,11 +230,10 @@ public class PerformanceTestController extends BaseController {
|
|||||||
// @PreAuthorize("@ss.hasPermi('system:test:remove')")
|
// @PreAuthorize("@ss.hasPermi('system:test:remove')")
|
||||||
@GetMapping("/executeNow")
|
@GetMapping("/executeNow")
|
||||||
public AjaxResult executeNow(@RequestParam Long id) {
|
public AjaxResult executeNow(@RequestParam Long id) {
|
||||||
|
String createBy = getLoginUser().getUsername();
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
performanceTestCaseReportService.executePerformanceTestAndReport(id, jmeterHomePath, 2);
|
performanceTestCaseReportService.executePerformanceTestAndReport(id, jmeterHomePath, 2, createBy);
|
||||||
});
|
});
|
||||||
return toAjax(true);
|
return toAjax(true);
|
||||||
// Long l1 = performanceTestCaseReportService.executePerformanceTestAndReport(id, jmeterHomePath, 2);
|
|
||||||
// return success(l1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,9 @@ public class TestTaskController extends BaseController {
|
|||||||
try {
|
try {
|
||||||
testTask.setCreateBy(getLoginUser().getUsername());
|
testTask.setCreateBy(getLoginUser().getUsername());
|
||||||
testTask.setCreateTime(DateUtils.getNowDate());
|
testTask.setCreateTime(DateUtils.getNowDate());
|
||||||
|
if (testTask.getStatus() == null) {
|
||||||
|
testTask.setStatus(2);
|
||||||
|
}
|
||||||
int result = testTaskService.insertTestTask(testTask);
|
int result = testTaskService.insertTestTask(testTask);
|
||||||
|
|
||||||
// 如果任务状态是启用且没有被删除,则添加到定时任务管理器
|
// 如果任务状态是启用且没有被删除,则添加到定时任务管理器
|
||||||
@@ -106,6 +109,7 @@ public class TestTaskController extends BaseController {
|
|||||||
|
|
||||||
return toAjax(result);
|
return toAjax(result);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
logger.error("新增失败:", e);
|
||||||
return error("新增失败:" + e.getMessage());
|
return error("新增失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ public interface IPerformanceTestCaseReportService
|
|||||||
* @param id
|
* @param id
|
||||||
* @param jmeterHomePath
|
* @param jmeterHomePath
|
||||||
* @param triggerType 触发方式:1-定时任务;2-手动
|
* @param triggerType 触发方式:1-定时任务;2-手动
|
||||||
|
* @param createBy 创建人
|
||||||
* @return 返回本次性能测试的批次id
|
* @return 返回本次性能测试的批次id
|
||||||
*/
|
*/
|
||||||
public Long executePerformanceTestAndReport(Long id, String jmeterHomePath, Integer triggerType);
|
public Long executePerformanceTestAndReport(Long id, String jmeterHomePath, Integer triggerType, String createBy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询性能测试用例报告
|
* 查询性能测试用例报告
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class PerformanceTestCaseReportServiceImpl implements IPerformanceTestCas
|
|||||||
private ITestCaseStepService testCaseStepService;
|
private ITestCaseStepService testCaseStepService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long executePerformanceTestAndReport(Long id, String jmeterHomePath, Integer triggerType) {
|
public Long executePerformanceTestAndReport(Long id, String jmeterHomePath, Integer triggerType, String createBy) {
|
||||||
Long sid = System.currentTimeMillis();
|
Long sid = System.currentTimeMillis();
|
||||||
PerformanceTest performanceTest = performanceTestMapper.selectPerformanceTestById(id);
|
PerformanceTest performanceTest = performanceTestMapper.selectPerformanceTestById(id);
|
||||||
PerformanceTestCase performanceTestCase = new PerformanceTestCase();
|
PerformanceTestCase performanceTestCase = new PerformanceTestCase();
|
||||||
@@ -89,6 +89,7 @@ public class PerformanceTestCaseReportServiceImpl implements IPerformanceTestCas
|
|||||||
if (!CollectionUtils.isEmpty(jmeterResultList)) {
|
if (!CollectionUtils.isEmpty(jmeterResultList)) {
|
||||||
LabelStatsEntity lastElement = jmeterResultList.get(jmeterResultList.size() - 1);
|
LabelStatsEntity lastElement = jmeterResultList.get(jmeterResultList.size() - 1);
|
||||||
PerformanceTestCaseReport performanceTestCaseReport = new PerformanceTestCaseReport();
|
PerformanceTestCaseReport performanceTestCaseReport = new PerformanceTestCaseReport();
|
||||||
|
performanceTestCaseReport.setCreateBy(createBy);
|
||||||
performanceTestCaseReport.setPerformanceId(id);
|
performanceTestCaseReport.setPerformanceId(id);
|
||||||
performanceTestCaseReport.setTestCaseId(relateTestCase.getTestCaseId());
|
performanceTestCaseReport.setTestCaseId(relateTestCase.getTestCaseId());
|
||||||
performanceTestCaseReport.setSid(sid);
|
performanceTestCaseReport.setSid(sid);
|
||||||
|
|||||||
@@ -30,16 +30,16 @@ public class DynamicTaskManager {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PerformanceTestMapper performanceTestMapper;
|
private PerformanceTestMapper performanceTestMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TaskScheduler taskScheduler;
|
private TaskScheduler taskScheduler;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IPerformanceTestCaseReportService performanceTestCaseReportService;
|
private IPerformanceTestCaseReportService performanceTestCaseReportService;
|
||||||
|
|
||||||
private final Map<Long, ScheduledFuture<?>> scheduledTasks = new ConcurrentHashMap<>();
|
private final Map<Long, ScheduledFuture<?>> scheduledTasks = new ConcurrentHashMap<>();
|
||||||
private final Map<Long, PerformanceTest> taskCache = new ConcurrentHashMap<>();
|
private final Map<Long, PerformanceTest> taskCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
loadTasks(); // 初始加载
|
loadTasks(); // 初始加载
|
||||||
@@ -104,7 +104,7 @@ public class DynamicTaskManager {
|
|||||||
List<PerformanceTest> tasks = performanceTestMapper.selectPerformanceTestList(performanceTest);
|
List<PerformanceTest> tasks = performanceTestMapper.selectPerformanceTestList(performanceTest);
|
||||||
tasks.forEach(this::scheduleTask);
|
tasks.forEach(this::scheduleTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scheduleTask(PerformanceTest task) {
|
private void scheduleTask(PerformanceTest task) {
|
||||||
try {
|
try {
|
||||||
CronTrigger trigger = new CronTrigger(task.getCrontab());
|
CronTrigger trigger = new CronTrigger(task.getCrontab());
|
||||||
@@ -118,17 +118,17 @@ public class DynamicTaskManager {
|
|||||||
log.error("无效的cron表达式: " + task.getCrontab());
|
log.error("无效的cron表达式: " + task.getCrontab());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeTask(PerformanceTest task) {
|
private void executeTask(PerformanceTest task) {
|
||||||
// 执行业务逻辑
|
// 执行业务逻辑
|
||||||
log.info("执行任务: " + task.getId());
|
log.info("执行任务: " + task.getId());
|
||||||
try{
|
try{
|
||||||
performanceTestCaseReportService.executePerformanceTestAndReport(task.getId(),jmeterHomePath,1);
|
performanceTestCaseReportService.executePerformanceTestAndReport(task.getId(),jmeterHomePath,1,"system");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("执行失败!",e);
|
log.error("执行失败!",e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshTasks() {
|
private void refreshTasks() {
|
||||||
PerformanceTest performanceTest =new PerformanceTest();
|
PerformanceTest performanceTest =new PerformanceTest();
|
||||||
performanceTest.setCrontabStatus(1);
|
performanceTest.setCrontabStatus(1);
|
||||||
@@ -137,7 +137,7 @@ public class DynamicTaskManager {
|
|||||||
Set<Long> currentIds = currentTasks.stream()
|
Set<Long> currentIds = currentTasks.stream()
|
||||||
.map(PerformanceTest::getId)
|
.map(PerformanceTest::getId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
// 处理新增或更新的任务
|
// 处理新增或更新的任务
|
||||||
currentTasks.forEach(task -> {
|
currentTasks.forEach(task -> {
|
||||||
Long taskId = task.getId();
|
Long taskId = task.getId();
|
||||||
@@ -162,4 +162,4 @@ public class DynamicTaskManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export default {
|
|||||||
},
|
},
|
||||||
// 编辑
|
// 编辑
|
||||||
hadleClickEdit(val) {
|
hadleClickEdit(val) {
|
||||||
this.$tab.openPage(`修改测试_${val.id}`, `/performance/edit/${val.id}`, { id: val.id });
|
this.$tab.openPage(`修改测试_${val.id}`, `/performance/edit`, { id: val.id });
|
||||||
},
|
},
|
||||||
// 删除
|
// 删除
|
||||||
hadleClickDelete(val) {
|
hadleClickDelete(val) {
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
<el-table-column prop="endTime" label="结束时间" align="center" sortable />
|
<el-table-column prop="endTime" label="结束时间" align="center" sortable />
|
||||||
<el-table-column prop="triggerType" label="触发方式" align="center" sortable>
|
<el-table-column prop="triggerType" label="触发方式" align="center" sortable>
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<div v-if="scope.row.triggerType === 1">按持续时间</div>
|
<div v-if="scope.row.triggerType === 1">定时任务</div>
|
||||||
<div v-else>按迭代次数</div>
|
<div v-else>手动</div>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="status" label="状态" align="center" width="150" sortable>
|
<el-table-column prop="status" label="状态" align="center" width="150" sortable>
|
||||||
|
|||||||
Reference in New Issue
Block a user