parent
12036e577e
commit
811e3e3b39
|
@ -20,6 +20,9 @@ public class RunModeDataDTO {
|
|||
private String apiCaseId;
|
||||
|
||||
private Map<String, String> planEnvMap;
|
||||
|
||||
private String debugReportId;
|
||||
|
||||
public RunModeDataDTO(){
|
||||
|
||||
}
|
||||
|
|
|
@ -242,84 +242,92 @@ public class ApiDefinitionExecResultService {
|
|||
|
||||
if (CollectionUtils.isNotEmpty(result.getScenarios())) {
|
||||
result.getScenarios().forEach(scenarioResult -> {
|
||||
final boolean[] isFirst = {true};
|
||||
if (scenarioResult != null && CollectionUtils.isNotEmpty(scenarioResult.getRequestResults())) {
|
||||
scenarioResult.getRequestResults().forEach(item -> {
|
||||
|
||||
String creator = TestPlanReportExecuteCatch.getCreator(testPlanReportId);
|
||||
|
||||
String status = item.isSuccess() ? "success" : "error";
|
||||
item.getResponseResult().setConsole(result.getConsole());
|
||||
ApiDefinitionExecResult saveResult = new ApiDefinitionExecResult();
|
||||
saveResult.setId(UUID.randomUUID().toString());
|
||||
saveResult.setCreateTime(System.currentTimeMillis());
|
||||
saveResult.setName(getName(type, item.getName(), status, saveResult.getCreateTime(), saveResult.getId()));
|
||||
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = apiDefinitionMapper.selectByPrimaryKey(item.getName());
|
||||
String caseId = null;
|
||||
if (apiDefinitionWithBLOBs != null) {
|
||||
saveResult.setName(apiDefinitionWithBLOBs.getName());
|
||||
caseId = apiDefinitionWithBLOBs.getId();
|
||||
} else {
|
||||
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(item.getName());
|
||||
if (caseWithBLOBs != null) {
|
||||
caseId = caseWithBLOBs.getId();
|
||||
saveResult.setName(caseWithBLOBs.getName());
|
||||
} else {
|
||||
caseWithBLOBs = testPlanApiCaseService.getApiTestCaseById(item.getName());
|
||||
if (caseWithBLOBs != null) {
|
||||
saveResult.setName(caseWithBLOBs.getName());
|
||||
caseId = caseWithBLOBs.getId();
|
||||
if (!StringUtils.startsWithAny(item.getName(), "PRE_PROCESSOR_ENV_", "POST_PROCESSOR_ENV_")) {
|
||||
ApiDefinitionExecResult saveResult = MessageCache.caseExecResourceLock.get(result.getTestId());
|
||||
if (saveResult == null) {
|
||||
saveResult = apiDefinitionExecResultMapper.selectByPrimaryKey(result.getTestId());
|
||||
}
|
||||
item.getResponseResult().setConsole(result.getConsole());
|
||||
boolean saved = true;
|
||||
if (saveResult == null || scenarioResult.getRequestResults().size() > 1) {
|
||||
saveResult = new ApiDefinitionExecResult();
|
||||
if (isFirst[0]) {
|
||||
isFirst[0] = false;
|
||||
saveResult.setId(result.getTestId());
|
||||
} else {
|
||||
saveResult.setId(UUID.randomUUID().toString());
|
||||
}
|
||||
saveResult.setActuator("LOCAL");
|
||||
saveResult.setName(item.getName());
|
||||
if (StringUtils.equals(type, ApiRunMode.JENKINS_API_PLAN.name())) {
|
||||
saveResult.setTriggerMode(TriggerMode.API.name());
|
||||
} else if (StringUtils.equals(type, ApiRunMode.MANUAL_PLAN.name())) {
|
||||
saveResult.setTriggerMode(TriggerMode.MANUAL.name());
|
||||
} else {
|
||||
saveResult.setTriggerMode(TriggerMode.SCHEDULE.name());
|
||||
}
|
||||
saveResult.setType(type);
|
||||
saveResult.setCreateTime(item.getStartTime());
|
||||
if (StringUtils.isNotEmpty(result.getUserId())) {
|
||||
saveResult.setUserId(result.getUserId());
|
||||
} else {
|
||||
if (SessionUtils.getUser() != null) {
|
||||
saveResult.setUserId(SessionUtils.getUser().getId());
|
||||
}
|
||||
}
|
||||
saved = false;
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotEmpty(caseId)) {
|
||||
apiIdResultMap.put(caseId, item.isSuccess() ? TestPlanApiExecuteStatus.SUCCESS.name() : TestPlanApiExecuteStatus.FAILD.name());
|
||||
}
|
||||
|
||||
if (StringUtils.equals(type, ApiRunMode.JENKINS_API_PLAN.name())) {
|
||||
saveResult.setTriggerMode(TriggerMode.API.name());
|
||||
} else if (StringUtils.equals(type, ApiRunMode.MANUAL_PLAN.name())) {
|
||||
saveResult.setTriggerMode(TriggerMode.MANUAL.name());
|
||||
} else {
|
||||
saveResult.setTriggerMode(TriggerMode.SCHEDULE.name());
|
||||
}
|
||||
String status = item.isSuccess() ? "success" : "error";
|
||||
saveResult.setName(getName(type, item.getName(), status, saveResult.getCreateTime(), saveResult.getId()));
|
||||
saveResult.setStatus(status);
|
||||
saveResult.setResourceId(item.getName());
|
||||
saveResult.setContent(JSON.toJSONString(item));
|
||||
saveResult.setStartTime(item.getStartTime());
|
||||
saveResult.setEndTime(item.getResponseResult().getResponseTime());
|
||||
|
||||
saveResult.setResourceId(item.getName());
|
||||
saveResult.setActuator("LOCAL");
|
||||
saveResult.setContent(JSON.toJSONString(item));
|
||||
saveResult.setStartTime(item.getStartTime());
|
||||
saveResult.setEndTime(item.getResponseResult().getResponseTime());
|
||||
saveResult.setType(finalSaveResultType);
|
||||
saveResult.setStatus(status);
|
||||
|
||||
if (StringUtils.equals(type, ApiRunMode.SCHEDULE_API_PLAN.name())) {
|
||||
TestPlanApiCase apiCase = testPlanApiCaseService.getById(item.getName());
|
||||
if (StringUtils.isEmpty(creator)) {
|
||||
creator = testPlanService.findScheduleCreateUserById(apiCase.getTestPlanId());
|
||||
// 清空上次执行结果的内容,只保留近五条结果
|
||||
ApiDefinitionExecResult prevResult = extApiDefinitionExecResultMapper.selectMaxResultByResourceIdAndType(item.getName(), type);
|
||||
if (prevResult != null) {
|
||||
prevResult.setContent(null);
|
||||
apiDefinitionExecResultMapper.updateByPrimaryKeyWithBLOBs(prevResult);
|
||||
}
|
||||
apiCase.setStatus(status);
|
||||
apiCase.setUpdateTime(System.currentTimeMillis());
|
||||
testPlanApiCaseService.updateByPrimaryKeySelective(apiCase);
|
||||
} else if (StringUtils.equals(type, ApiRunMode.JENKINS_API_PLAN.name())) {
|
||||
TestPlanApiCase apiCase = testPlanApiCaseService.getById(item.getName());
|
||||
apiCase.setStatus(status);
|
||||
apiCase.setUpdateTime(System.currentTimeMillis());
|
||||
testPlanApiCaseService.updateByPrimaryKeySelective(apiCase);
|
||||
} else {
|
||||
testPlanApiCaseService.setExecResult(item.getName(), status, item.getStartTime());
|
||||
testCaseReviewApiCaseService.setExecResult(item.getName(), status, item.getStartTime());
|
||||
|
||||
if (StringUtils.isNotEmpty(saveResult.getTriggerMode()) && saveResult.getTriggerMode().equals("CASE")) {
|
||||
saveResult.setTriggerMode(TriggerMode.MANUAL.name());
|
||||
}
|
||||
if (!saved) {
|
||||
apiDefinitionExecResultMapper.insert(saveResult);
|
||||
} else {
|
||||
apiDefinitionExecResultMapper.updateByPrimaryKeyWithBLOBs(saveResult);
|
||||
}
|
||||
apiDefinitionService.removeCache(result.getTestId());
|
||||
if (StringUtils.isNotEmpty(result.getTestId())) {
|
||||
MessageCache.caseExecResourceLock.remove(result.getTestId());
|
||||
}
|
||||
|
||||
String caseId = item.getName();
|
||||
if (StringUtils.equalsAny(type, ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) {
|
||||
TestPlanApiCase apiCase = testPlanApiCaseService.getById(caseId);
|
||||
apiCase.setStatus(status);
|
||||
apiCase.setUpdateTime(System.currentTimeMillis());
|
||||
testPlanApiCaseService.updateByPrimaryKeySelective(apiCase);
|
||||
} else {
|
||||
testPlanApiCaseService.setExecResult(caseId, status, item.getStartTime());
|
||||
testCaseReviewApiCaseService.setExecResult(caseId, status, item.getStartTime());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(caseId)) {
|
||||
apiIdResultMap.put(caseId, item.isSuccess() ? TestPlanApiExecuteStatus.SUCCESS.name() : TestPlanApiExecuteStatus.FAILD.name());
|
||||
}
|
||||
|
||||
caseReportMap.put(caseId, saveResult.getId());
|
||||
}
|
||||
if (creator == null) {
|
||||
creator = "";
|
||||
}
|
||||
saveResult.setUserId(creator);
|
||||
// 前一条数据内容清空
|
||||
ApiDefinitionExecResult prevResult = extApiDefinitionExecResultMapper.selectMaxResultByResourceIdAndType(item.getName(), finalSaveResultType);
|
||||
if (prevResult != null) {
|
||||
prevResult.setContent(null);
|
||||
apiDefinitionExecResultMapper.updateByPrimaryKeyWithBLOBs(prevResult);
|
||||
}
|
||||
apiDefinitionExecResultMapper.insert(saveResult);
|
||||
caseReportMap.put(caseId, saveResult.getId());
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -467,6 +467,7 @@ public class TestPlanApiCaseService {
|
|||
}
|
||||
mapper.updateByPrimaryKey(execResult);
|
||||
modeDataDTO.setApiCaseId(execResult.getId());
|
||||
modeDataDTO.setDebugReportId(request.getPlanReportId());
|
||||
Future<ApiDefinitionExecResult> future = executorService.submit(new SerialApiExecTask(jMeterService, mapper, modeDataDTO, request.getConfig(), request.getTriggerMode()));
|
||||
ApiDefinitionExecResult report = future.get();
|
||||
// 如果开启失败结束执行,则判断返回结果状态
|
||||
|
|
|
@ -39,9 +39,13 @@ public class SerialApiExecTask<T> implements Callable<T> {
|
|||
return null;
|
||||
}
|
||||
if (config != null && StringUtils.isNotBlank(config.getResourcePoolId())) {
|
||||
jMeterService.runTest(runModeDataDTO.getTestId(), runModeDataDTO.getApiCaseId(), runMode, null, config);
|
||||
jMeterService.runTest(runModeDataDTO.getTestId(), runModeDataDTO.getApiCaseId(), runMode, runModeDataDTO.getDebugReportId(), config);
|
||||
} else {
|
||||
jMeterService.runLocal(runModeDataDTO.getApiCaseId(), config, runModeDataDTO.getHashTree(), runModeDataDTO.getReport() != null ? runModeDataDTO.getReport().getTriggerMode() : null, runMode);
|
||||
String debugId = runModeDataDTO.getDebugReportId();
|
||||
if(debugId == null){
|
||||
debugId = runModeDataDTO.getReport() != null ? runModeDataDTO.getReport().getTriggerMode() : null;
|
||||
}
|
||||
jMeterService.runLocal(runModeDataDTO.getApiCaseId(), config, runModeDataDTO.getHashTree(), debugId, runMode);
|
||||
}
|
||||
// 轮询查看报告状态,最多200次,防止死循环
|
||||
ApiDefinitionExecResult report = null;
|
||||
|
|
Loading…
Reference in New Issue