feat(测试计划、接口场景): 修复场景批量编辑失败的缺陷、为测试计划的定时任务和Jenkins调用相关函数增加日志
修复场景批量编辑失败的缺陷、为测试计划的定时任务和Jenkins调用相关函数增加日志
This commit is contained in:
parent
f9408cfffa
commit
3c75c6bf45
|
@ -1686,7 +1686,7 @@ public class ApiAutomationService {
|
|||
apiScenarioMapper.updateByExampleSelective(
|
||||
apiScenarioWithBLOBs,
|
||||
apiScenarioExample);
|
||||
apiScenarioReferenceIdService.saveByApiScenario(apiScenarioWithBLOBs);
|
||||
// apiScenarioReferenceIdService.saveByApiScenario(apiScenarioWithBLOBs);
|
||||
}
|
||||
|
||||
public void bathEditEnv(ApiScenarioBatchRequest request) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.api.service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult;
|
||||
import io.metersphere.api.jmeter.TestResult;
|
||||
import io.metersphere.base.domain.*;
|
||||
|
@ -24,6 +25,8 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -33,6 +36,7 @@ import java.util.*;
|
|||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class ApiDefinitionExecResultService {
|
||||
Logger testPlanLog = LoggerFactory.getLogger("testPlanExecuteLog");
|
||||
@Resource
|
||||
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
|
||||
@Resource
|
||||
|
@ -164,6 +168,7 @@ public class ApiDefinitionExecResultService {
|
|||
* @param type
|
||||
*/
|
||||
public void saveApiResultByScheduleTask(TestResult result, String testPlanReportId, String type, String trigeMode) {
|
||||
testPlanLog.info("TestPlanReportId["+testPlanReportId+"] APICASE OVER.");
|
||||
String saveResultType = type;
|
||||
if (StringUtils.equalsAny(saveResultType, ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) {
|
||||
saveResultType = ApiRunMode.API_PLAN.name();
|
||||
|
@ -244,7 +249,7 @@ public class ApiDefinitionExecResultService {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
testPlanLog.info("TestPlanReportId["+testPlanReportId+"] APICASE OVER. API CASE STATUS:"+ JSONObject.toJSONString(apiIdResultMap));
|
||||
TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class);
|
||||
testPlanReportService.updateExecuteApis(testPlanReportId, apiIdResultMap, null, null);
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ public class ApiScenarioReferenceIdService {
|
|||
}
|
||||
|
||||
public void saveByApiScenario(ApiScenarioWithBLOBs scenario) {
|
||||
if(scenario.getId() == null){
|
||||
return;
|
||||
}
|
||||
this.deleteByScenarioId(scenario.getId());
|
||||
|
||||
long createTime = System.currentTimeMillis();
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package io.metersphere.api.service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -38,6 +40,8 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -50,6 +54,7 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class ApiScenarioReportService {
|
||||
Logger testPlanLog = LoggerFactory.getLogger("testPlanExecuteLog");
|
||||
@Resource
|
||||
private ExtApiScenarioReportMapper extApiScenarioReportMapper;
|
||||
@Resource
|
||||
|
@ -250,6 +255,7 @@ public class ApiScenarioReportService {
|
|||
}
|
||||
|
||||
public ApiScenarioReport updateSchedulePlanCase(TestResult result, String runMode) {
|
||||
|
||||
ApiScenarioReport lastReport = null;
|
||||
List<ScenarioResult> scenarioResultList = result.getScenarios();
|
||||
|
||||
|
@ -325,10 +331,12 @@ public class ApiScenarioReportService {
|
|||
reportIds.add(report.getId());
|
||||
}
|
||||
TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class);
|
||||
|
||||
testPlanLog.info("TestPlanReportId"+ JSONArray.toJSONString(testPlanReportIdList) +" EXECUTE OVER. SCENARIO STATUS : "+JSONObject.toJSONString(scenarioAndErrorMap));
|
||||
|
||||
for (String planId :testPlanReportIdList) {
|
||||
testPlanReportService.updateExecuteApis(planId,null,scenarioAndErrorMap,null);
|
||||
}
|
||||
// testPlanReportService.updateReport(testPlanReportIdList, runMode, lastReport.getTriggerMode(), scenarioIdList);
|
||||
|
||||
return lastReport;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ import org.apache.commons.collections.MapUtils;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -49,6 +51,9 @@ import java.util.stream.Collectors;
|
|||
|
||||
@Service
|
||||
public class TestPlanReportService {
|
||||
|
||||
Logger testPlanLog = LoggerFactory.getLogger("testPlanExecuteLog");
|
||||
|
||||
@Resource
|
||||
TestPlanReportMapper testPlanReportMapper;
|
||||
@Resource
|
||||
|
@ -1011,6 +1016,7 @@ public class TestPlanReportService {
|
|||
if(executePerformanceIdMap == null){
|
||||
executePerformanceIdMap = new HashMap<>();
|
||||
}
|
||||
testPlanLog.info("ReportId["+planReportId+"] Executed. api :"+JSONObject.toJSONString(executeApiCaseIdMap)+"; scenario:"+JSONObject.toJSONString(executeScenarioCaseIdMap)+"; performance:"+JSONObject.toJSONString(executePerformanceIdMap));
|
||||
example.createCriteria().andTestPlanReportIdEqualTo(planReportId);
|
||||
List<TestPlanReportDataWithBLOBs> reportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example);
|
||||
if (!reportDataList.isEmpty()) {
|
||||
|
@ -1096,9 +1102,18 @@ public class TestPlanReportService {
|
|||
reportData.setPerformanceInfo(newArr.toJSONString());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
testPlanLog.info("ReportId["+planReportId+"] count over. Execute result: Api ->"+reportData.getApiCaseInfo()+"; scenario->"+reportData.getScenarioInfo()+"; performance->"+reportData.getPerformanceInfo());
|
||||
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(false);
|
||||
TestPlanReportDataMapper updateReportDataMapper = sqlSession.getMapper(TestPlanReportDataMapper.class);
|
||||
updateReportDataMapper.updateByPrimaryKeySelective(reportData);
|
||||
sqlSession.commit();
|
||||
sqlSession.flushStatements();
|
||||
|
||||
|
||||
testPlanReportDataMapper.updateByPrimaryKeySelective(reportData);
|
||||
this.updateReport(reportData, apiCaseExecuteOk, scenarioExecuteOk, performanceExecuteOk);
|
||||
}else {
|
||||
testPlanLog.info("ReportId["+planReportId+"] CANNOT FIND REPORT! Execited result. api :"+JSONObject.toJSONString(executeApiCaseIdMap)+"; scenario:"+JSONObject.toJSONString(executeScenarioCaseIdMap)+"; performance:"+JSONObject.toJSONString(executePerformanceIdMap));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ import org.apache.ibatis.session.SqlSession;
|
|||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.apache.jorphan.collections.ListedHashTree;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -61,6 +63,8 @@ import java.util.stream.Collectors;
|
|||
|
||||
@Service
|
||||
public class TestPlanService {
|
||||
Logger testPlanLog = LoggerFactory.getLogger("testPlanExecuteLog");
|
||||
|
||||
@Resource
|
||||
ExtScheduleMapper extScheduleMapper;
|
||||
@Resource
|
||||
|
@ -1016,6 +1020,7 @@ public class TestPlanService {
|
|||
}
|
||||
//创建测试报告,然后返回的ID重新赋值为resourceID,作为后续的参数
|
||||
TestPlanScheduleReportInfoDTO reportInfoDTO = testPlanReportService.genTestPlanReportBySchedule(projectID,testPlanID,userId,triggerMode);
|
||||
|
||||
TestPlanReport testPlanReport = reportInfoDTO.getTestPlanReport();
|
||||
Map<String, String> planScenarioIdMap = reportInfoDTO.getPlanScenarioIdMap();
|
||||
Map<String, String> apiTestCaseIdMap = reportInfoDTO.getApiTestCaseIdMap();
|
||||
|
@ -1023,6 +1028,8 @@ public class TestPlanService {
|
|||
|
||||
String planReportId = testPlanReport.getId();
|
||||
|
||||
testPlanLog.info("ReportId["+planReportId+"] created. TestPlanID:["+testPlanID+"]. ");
|
||||
|
||||
//不同任务的执行ID
|
||||
Map<String,String> executePerformanceIdMap = new HashMap<>();
|
||||
Map<String,String> executeApiCaseIdMap = new HashMap<>();
|
||||
|
@ -1078,6 +1085,7 @@ public class TestPlanService {
|
|||
for (String id : planScenarioIdMap.keySet()) {
|
||||
executeScenarioCaseIdMap.put(id,TestPlanApiExecuteStatus.RUNNING.name());
|
||||
}
|
||||
testPlanLog.info("ReportId["+planReportId+"] start run. TestPlanID:["+testPlanID+"]. Execute api :"+JSONObject.toJSONString(executeApiCaseIdMap)+"; Execute scenario:"+JSONObject.toJSONString(executeScenarioCaseIdMap)+"; Execute performance:"+JSONObject.toJSONString(executePerformanceIdMap));
|
||||
testPlanReportService.updateExecuteApis(planReportId,executeApiCaseIdMap,executeScenarioCaseIdMap,executePerformanceIdMap);
|
||||
|
||||
|
||||
|
@ -1121,10 +1129,6 @@ public class TestPlanService {
|
|||
RunModeConfig runModeConfig = JSONObject.parseObject(apiRunConfig, RunModeConfig.class);
|
||||
scenarioRequest.setConfig(runModeConfig);
|
||||
String scenarioReportID = this.scenarioRunModeConfig(scenarioRequest);
|
||||
// if (StringUtils.isNotEmpty(scenarioReportID)) {
|
||||
// scenarioIsExcuting = true;
|
||||
// scenarioCaseIdArray = JSONArray.toJSONString(new ArrayList<>(planScenarioIdMap.keySet()));
|
||||
// }
|
||||
}
|
||||
return testPlanReport.getId();
|
||||
}
|
||||
|
|
|
@ -140,7 +140,41 @@
|
|||
<includeCallerData>true</includeCallerData>
|
||||
<appender-ref ref="warnAppender" />
|
||||
</appender>
|
||||
<!-- 自定义JMETER输出日志 -->
|
||||
|
||||
<!-- 自定义测试计划执行的日志 -->
|
||||
<appender name="infoTestPlanAppender"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>INFO</level>
|
||||
</filter>
|
||||
<File>${logging.file.path}/testPlan/info.log</File>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<FileNamePattern>${logging.file.path}/history/testPlan/info.%d{yyyyMMdd}-%i.log
|
||||
</FileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
<TimeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
</TimeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<charset>UTF-8</charset>
|
||||
<Pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</Pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<appender name="infoTestPlanAsyncAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>INFO</level>
|
||||
</filter>
|
||||
<queueSize>10000</queueSize>
|
||||
<appender-ref ref="infoTestPlanAppender" />
|
||||
</appender>
|
||||
<logger name="testPlanExecuteLog" additivity="false">
|
||||
<level value="${logger.level:INFO}"/>
|
||||
<appender-ref ref="infoTestPlanAsyncAppender"/>
|
||||
</logger>
|
||||
|
||||
<!-- 自定义JMETER输出日志 -->
|
||||
<appender name="JMETER_LOG" class="io.metersphere.api.jmeter.JmeterLoggerAppender"/>
|
||||
|
||||
<root level="INFO">
|
||||
|
|
Loading…
Reference in New Issue