refactor(接口测试): 接口执行相关控制台日志重构,实现按照执行任务隔离
--bug=1016628 --user=赵勇 【接口测试】github#17740,环境里配置全局脚本,并行批量执行用例当前用例只输出当前用例的日志 https://www.tapd.cn/55049933/s/1267909
This commit is contained in:
parent
30ad47b5ae
commit
10dfb43e98
|
@ -338,7 +338,7 @@ public class ElementUtil {
|
|||
put(ElementConstants.EXTRACT, MsExtract.class.getCanonicalName());
|
||||
put(ElementConstants.JMETER_ELE, MsJmeterElement.class.getCanonicalName());
|
||||
put(ElementConstants.TEST_PLAN, MsTestPlan.class.getCanonicalName());
|
||||
put(ElementConstants.TREAD_GROUP, MsThreadGroup.class.getCanonicalName());
|
||||
put(ElementConstants.THREAD_GROUP, MsThreadGroup.class.getCanonicalName());
|
||||
put(ElementConstants.DNS_CACHE, MsDNSCacheManager.class.getCanonicalName());
|
||||
put(ElementConstants.DEBUG_SAMPLER, MsDebugSampler.class.getCanonicalName());
|
||||
put(ElementConstants.AUTH_MANAGER, MsAuthManager.class.getCanonicalName());
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.util.List;
|
|||
@EqualsAndHashCode(callSuper = true)
|
||||
|
||||
public class MsThreadGroup extends MsTestElement {
|
||||
private String type = ElementConstants.TREAD_GROUP;
|
||||
private String type = ElementConstants.THREAD_GROUP;
|
||||
private String clazzName = MsThreadGroup.class.getCanonicalName();
|
||||
|
||||
private boolean enableCookieShare;
|
||||
|
|
|
@ -115,7 +115,6 @@ public class ApiCaseExecuteService {
|
|||
resourcePoolId = request.getConfig().getResourcePoolId();
|
||||
}
|
||||
if (!request.isRerun()) {
|
||||
Map<String, String> planProjects = new HashMap<>();
|
||||
for (TestPlanApiCase testPlanApiCase : planApiCases) {
|
||||
//处理环境配置为空时的情况
|
||||
RunModeConfigDTO runModeConfigDTO = new RunModeConfigDTO();
|
||||
|
@ -129,16 +128,6 @@ public class ApiCaseExecuteService {
|
|||
}
|
||||
}
|
||||
ApiDefinitionExecResultWithBLOBs report = ApiDefinitionExecResultUtil.addResult(request, runModeConfigDTO, testPlanApiCase, status, caseMap, resourcePoolId);
|
||||
// todo check
|
||||
// if (planProjects.containsKey(testPlanApiCase.getTestPlanId())) {
|
||||
// report.setProjectId(planProjects.get(testPlanApiCase.getTestPlanId()));
|
||||
// } else {
|
||||
// TestPlan plan = CommonBeanFactory.getBean(TestPlanMapper.class).selectByPrimaryKey(testPlanApiCase.getTestPlanId());
|
||||
// if (plan != null) {
|
||||
// planProjects.put(plan.getId(), plan.getProjectId());
|
||||
// report.setProjectId(plan.getProjectId());
|
||||
// }
|
||||
// }
|
||||
executeQueue.put(testPlanApiCase.getId(), report);
|
||||
responseDTOS.add(new MsExecResponseDTO(testPlanApiCase.getId(), report.getId(), request.getTriggerMode()));
|
||||
LoggerUtil.debug("预生成测试用例结果报告:" + report.getName() + ", ID " + report.getId());
|
||||
|
|
|
@ -15,6 +15,8 @@ import io.metersphere.api.exec.queue.DBTestQueue;
|
|||
import io.metersphere.api.jmeter.JMeterService;
|
||||
import io.metersphere.api.jmeter.NewDriverManager;
|
||||
import io.metersphere.api.jmeter.utils.SmoothWeighted;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.service.ApiExecutionQueueService;
|
||||
import io.metersphere.service.RemakeReportService;
|
||||
import io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs;
|
||||
|
@ -28,19 +30,11 @@ import io.metersphere.commons.constants.ApiRunMode;
|
|||
import io.metersphere.commons.constants.ElementConstants;
|
||||
import io.metersphere.commons.constants.PropertyConstant;
|
||||
import io.metersphere.commons.enums.ApiReportStatus;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.JSON;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.dto.JmeterRunRequestDTO;
|
||||
import io.metersphere.dto.ResultDTO;
|
||||
import io.metersphere.environment.service.BaseEnvironmentService;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.commons.utils.GenerateHashTreeUtil;
|
||||
import io.metersphere.commons.utils.HashTreeUtil;
|
||||
import io.metersphere.commons.utils.JSONUtil;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import io.metersphere.commons.utils.RequestParamsUtil;
|
||||
import io.metersphere.xpack.api.service.ApiRetryOnFailureService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
|
@ -155,6 +149,11 @@ public class ApiCaseSerialService {
|
|||
MsThreadGroup group = new MsThreadGroup();
|
||||
group.setLabel(caseWithBLOBs.getName());
|
||||
group.setName(runRequest.getReportId());
|
||||
// 接口用例集成报告
|
||||
if (StringUtils.isNotEmpty(runRequest.getTestPlanReportId())
|
||||
&& StringUtils.equals(runRequest.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
group.setName(runRequest.getTestPlanReportId());
|
||||
}
|
||||
group.setProjectId(caseWithBLOBs.getProjectId());
|
||||
MsTestElement testElement;
|
||||
if (runRequest.isRetryEnable() && runRequest.getRetryNum() > 0) {
|
||||
|
|
|
@ -22,6 +22,7 @@ import io.metersphere.base.mapper.ApiTestCaseMapper;
|
|||
import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper;
|
||||
import io.metersphere.base.mapper.plan.TestPlanApiCaseMapper;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.constants.ElementConstants;
|
||||
import io.metersphere.commons.enums.ApiReportStatus;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.dto.JmeterRunRequestDTO;
|
||||
|
@ -145,6 +146,12 @@ public class ApiExecuteService {
|
|||
}
|
||||
|
||||
public MsExecResponseDTO debug(RunDefinitionRequest request, List<MultipartFile> bodyFiles) {
|
||||
// 补充线程组ID
|
||||
if (request.getTestElement() != null
|
||||
&& CollectionUtils.isNotEmpty(request.getTestElement().getHashTree())
|
||||
&& StringUtils.equalsIgnoreCase(request.getTestElement().getHashTree().get(0).getType(), ElementConstants.THREAD_GROUP)) {
|
||||
request.getTestElement().getHashTree().get(0).setName(request.getId());
|
||||
}
|
||||
JmeterRunRequestDTO runRequest = this.initRunRequest(request, bodyFiles);
|
||||
// 开始执行
|
||||
jMeterService.run(runRequest);
|
||||
|
@ -191,7 +198,7 @@ public class ApiExecuteService {
|
|||
// 单接口调试生成tmp临时目录
|
||||
requests.forEach(item -> {
|
||||
Body body = item.getBody();
|
||||
String tmpFilePath = "tmp/" + request.getReportId();
|
||||
String tmpFilePath = "tmp/" + request.getId();
|
||||
body.setTmpFilePath(tmpFilePath);
|
||||
FileUtils.copyBdyFile(item.getId(), tmpFilePath);
|
||||
FileUtils.createBodyFiles(tmpFilePath, bodyFiles);
|
||||
|
|
|
@ -9,11 +9,14 @@ import io.metersphere.commons.utils.FixedCapacityUtil;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class JMeterLoggerAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
|
||||
private final static String THREAD_SPLIT = " ";
|
||||
|
||||
@Override
|
||||
public void append(ILoggingEvent event) {
|
||||
try {
|
||||
if (!event.getLevel().levelStr.equals(LogUtil.DEBUG)) {
|
||||
if (!event.getLevel().levelStr.equals(LogUtil.DEBUG) && StringUtils.isNotEmpty(event.getThreadName())) {
|
||||
StringBuffer message = new StringBuffer();
|
||||
String threadName = StringUtils.substringBeforeLast(event.getThreadName(), THREAD_SPLIT);
|
||||
message.append(DateUtils.getTimeStr(event.getTimeStamp())).append(StringUtils.SPACE)
|
||||
.append(event.getLevel()).append(StringUtils.SPACE)
|
||||
.append(event.getThreadName()).append(StringUtils.SPACE)
|
||||
|
@ -28,12 +31,9 @@ public class JMeterLoggerAppender extends UnsynchronizedAppenderBase<ILoggingEve
|
|||
}
|
||||
}
|
||||
}
|
||||
if (message != null && !message.toString().contains("java.net.UnknownHostException")) {
|
||||
if (FixedCapacityUtil.fixedCapacityCache.containsKey(event.getTimeStamp())) {
|
||||
FixedCapacityUtil.fixedCapacityCache.get(event.getTimeStamp()).append(message);
|
||||
} else {
|
||||
FixedCapacityUtil.fixedCapacityCache.put(event.getTimeStamp(), message);
|
||||
}
|
||||
if (message != null && !message.toString().contains("java.net.UnknownHostException")
|
||||
&& FixedCapacityUtil.containsKey(threadName)) {
|
||||
FixedCapacityUtil.get(threadName).append(message);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -101,15 +101,15 @@ public class JMeterService {
|
|||
|
||||
private void runLocal(JmeterRunRequestDTO request) {
|
||||
init();
|
||||
if (!FixedCapacityUtil.jmeterLogTask.containsKey(request.getReportId())) {
|
||||
FixedCapacityUtil.jmeterLogTask.put(request.getReportId(), System.currentTimeMillis());
|
||||
}
|
||||
// 接口用例集成报告/测试计划报告日志记录
|
||||
if (StringUtils.isNotEmpty(request.getTestPlanReportId())
|
||||
&& !FixedCapacityUtil.jmeterLogTask.containsKey(request.getTestPlanReportId())
|
||||
&& StringUtils.equals(request.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
FixedCapacityUtil.jmeterLogTask.put(request.getTestPlanReportId(), System.currentTimeMillis());
|
||||
FixedCapacityUtil.put(request.getTestPlanReportId(), new StringBuffer(""));
|
||||
} else {
|
||||
// 报告日志记录
|
||||
FixedCapacityUtil.put(request.getReportId(), new StringBuffer(""));
|
||||
}
|
||||
LoggerUtil.debug("监听MessageCache.tasks当前容量:" + FixedCapacityUtil.jmeterLogTask.size());
|
||||
LoggerUtil.debug("监听MessageCache.tasks当前容量:" + FixedCapacityUtil.size());
|
||||
if (request.isDebug() && !StringUtils.equalsAny(request.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||
LoggerUtil.debug("为请求 [ " + request.getReportId() + " ] 添加同步接收结果 Listener");
|
||||
JMeterBase.addBackendListener(request, request.getHashTree(), MsApiBackendListener.class.getCanonicalName());
|
||||
|
|
|
@ -4,7 +4,10 @@ package io.metersphere.api.jmeter;
|
|||
import io.metersphere.api.exec.queue.PoolExecBlockingQueueUtil;
|
||||
import io.metersphere.cache.JMeterEngineCache;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.FileUtils;
|
||||
import io.metersphere.commons.utils.FixedCapacityUtil;
|
||||
import io.metersphere.commons.utils.JSON;
|
||||
import io.metersphere.constants.BackendListenerConstants;
|
||||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.dto.ResultDTO;
|
||||
|
@ -19,9 +22,7 @@ import org.apache.jmeter.services.FileServer;
|
|||
import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient;
|
||||
import org.apache.jmeter.visualizers.backend.BackendListenerContext;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -60,18 +61,15 @@ public class MsApiBackendListener extends AbstractBackendListenerClient implemen
|
|||
RetryResultUtil.mergeRetryResults(dto.getRequestResults());
|
||||
LoggerUtil.info("重试结果处理【" + dto.getReportId() + " 】结束");
|
||||
}
|
||||
|
||||
String console = FixedCapacityUtil.getJmeterLogger(dto.getReportId(), !StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString()));
|
||||
if (FileUtils.isFolderExists(dto.getReportId())) {
|
||||
console += "\r\n" + DateUtils.getTimeString(new Date()) + " INFO " +
|
||||
"Tmp folder " + FileUtils.BODY_FILE_DIR + File.separator + dto.getReportId() + " has deleted.";
|
||||
String reportId = dto.getReportId();
|
||||
if (StringUtils.isNotEmpty(dto.getTestPlanReportId())
|
||||
&& !FixedCapacityUtil.containsKey(dto.getTestPlanReportId())
|
||||
&& StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
reportId = dto.getTestPlanReportId();
|
||||
}
|
||||
if (FileUtils.isFolderExists("tmp" + File.separator + dto.getReportId())) {
|
||||
console += "\r\n" + DateUtils.getTimeString(new Date()) + " INFO " +
|
||||
"Tmp folder " + FileUtils.BODY_FILE_DIR + File.separator + "tmp" + File.separator + dto.getReportId() + " has deleted.";
|
||||
if (!StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
dto.setConsole(FixedCapacityUtil.getJmeterLogger(reportId, true));
|
||||
}
|
||||
dto.setConsole(console);
|
||||
|
||||
// 入库存储
|
||||
CommonBeanFactory.getBean(TestResultService.class).saveResults(dto);
|
||||
LoggerUtil.info("进入TEST-END处理报告【" + dto.getReportId() + " 】" + dto.getRunMode() + " 整体执行完成");
|
||||
|
|
|
@ -19,7 +19,7 @@ public class ElementConstants {
|
|||
public static final String JDBC_POST = "JDBCPostProcessor";
|
||||
public static final String JMETER_ELE = "JmeterElement";
|
||||
public static final String TEST_PLAN = "TestPlan";
|
||||
public static final String TREAD_GROUP = "ThreadGroup";
|
||||
public static final String THREAD_GROUP = "ThreadGroup";
|
||||
public static final String DNS_CACHE = "DNSCacheManager";
|
||||
public static final String DEBUG_SAMPLER = "DebugSampler";
|
||||
public static final String AUTH_MANAGER = "AuthManager";
|
||||
|
@ -43,7 +43,7 @@ public class ElementConstants {
|
|||
this.add(ElementConstants.JDBC_POST);
|
||||
this.add(ElementConstants.JMETER_ELE);
|
||||
this.add(ElementConstants.TEST_PLAN);
|
||||
this.add(ElementConstants.TREAD_GROUP);
|
||||
this.add(ElementConstants.THREAD_GROUP);
|
||||
this.add(ElementConstants.DNS_CACHE);
|
||||
this.add(ElementConstants.DEBUG_SAMPLER);
|
||||
this.add(ElementConstants.AUTH_MANAGER);
|
||||
|
|
|
@ -2,22 +2,36 @@ package io.metersphere.commons.utils;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FixedCapacityUtil {
|
||||
public static Map<Long, StringBuffer> fixedCapacityCache = Collections.synchronizedMap(new LRUHashMap<>());
|
||||
public final static Map<String, Long> jmeterLogTask = new HashMap<>();
|
||||
private static Map<String, StringBuffer> fixedCapacityCache = Collections.synchronizedMap(new LRUHashMap<>());
|
||||
|
||||
public static StringBuffer get(Long key) {
|
||||
public static StringBuffer get(String key) {
|
||||
return fixedCapacityCache.get(key);
|
||||
}
|
||||
|
||||
public static void put(Long key, StringBuffer value) {
|
||||
fixedCapacityCache.put(key, value);
|
||||
public static boolean containsKey(String key) {
|
||||
if (StringUtils.isEmpty(key)) {
|
||||
return false;
|
||||
}
|
||||
return fixedCapacityCache.containsKey(key);
|
||||
}
|
||||
|
||||
public static void put(String key, StringBuffer value) {
|
||||
if (!fixedCapacityCache.containsKey(key)) {
|
||||
fixedCapacityCache.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static void remove(String key) {
|
||||
if (fixedCapacityCache.containsKey(key)) {
|
||||
fixedCapacityCache.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public static int size() {
|
||||
|
@ -26,7 +40,7 @@ public class FixedCapacityUtil {
|
|||
|
||||
|
||||
static class LRUHashMap<K, V> extends LinkedHashMap<K, V> {
|
||||
private int capacity = 100;
|
||||
private int capacity = 3000;
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
|
||||
|
@ -34,28 +48,36 @@ public class FixedCapacityUtil {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getJmeterLogger(String reportId, boolean isClear) {
|
||||
try {
|
||||
Long startTime = FixedCapacityUtil.jmeterLogTask.get(reportId);
|
||||
if (startTime == null) {
|
||||
startTime = FixedCapacityUtil.jmeterLogTask.get("[" + reportId + "]");
|
||||
StringBuffer console = fixedCapacityCache.get(reportId);
|
||||
if (FileUtils.isFolderExists(reportId)) {
|
||||
console.append(StringUtils.LF)
|
||||
.append(DateUtils.getTimeString(new Date()))
|
||||
.append(" INFO ").append("Tmp folder ")
|
||||
.append(FileUtils.BODY_FILE_DIR)
|
||||
.append(File.separator)
|
||||
.append(reportId)
|
||||
.append(" has deleted.");
|
||||
}
|
||||
if (startTime == null) {
|
||||
startTime = System.currentTimeMillis();
|
||||
if (FileUtils.isFolderExists("tmp" + File.separator + reportId)) {
|
||||
console.append(StringUtils.LF)
|
||||
.append(DateUtils.getTimeString(new Date()))
|
||||
.append(" INFO ")
|
||||
.append("Tmp folder ")
|
||||
.append(FileUtils.BODY_FILE_DIR)
|
||||
.append(File.separator)
|
||||
.append("tmp")
|
||||
.append(File.separator)
|
||||
.append(reportId)
|
||||
.append(" has deleted.");
|
||||
}
|
||||
Long endTime = System.currentTimeMillis();
|
||||
Long finalStartTime = startTime;
|
||||
String logMessage = FixedCapacityUtil.fixedCapacityCache.entrySet().stream()
|
||||
.filter(map -> map.getKey() > finalStartTime && map.getKey() <= endTime)
|
||||
.map(map -> map.getValue()).collect(Collectors.joining());
|
||||
|
||||
return logMessage;
|
||||
return console.toString();
|
||||
} catch (Exception e) {
|
||||
return StringUtils.EMPTY;
|
||||
} finally {
|
||||
if (isClear && FixedCapacityUtil.jmeterLogTask.containsKey(reportId)) {
|
||||
FixedCapacityUtil.jmeterLogTask.remove(reportId);
|
||||
if (isClear && fixedCapacityCache.containsKey(reportId)) {
|
||||
fixedCapacityCache.remove(reportId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -246,14 +246,8 @@ public class ApiExecutionQueueService {
|
|||
// 清除队列
|
||||
executionQueueDetailMapper.deleteByExample(example);
|
||||
queueMapper.deleteByPrimaryKey(executionQueue.getId());
|
||||
|
||||
if (StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
String reportId = dto.getReportId();
|
||||
if (StringUtils.equalsIgnoreCase(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||
reportId = dto.getTestPlanReportId();
|
||||
}
|
||||
apiScenarioReportService.margeReport(reportId, dto.getRunMode(), dto.getConsole());
|
||||
}
|
||||
// 集合报告合并
|
||||
this.margeReport(dto);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -319,13 +313,8 @@ public class ApiExecutionQueueService {
|
|||
long count = executionQueueDetailMapper.countByExample(queueDetailExample);
|
||||
if (count == 0) {
|
||||
queueMapper.deleteByPrimaryKey(dto.getQueueId());
|
||||
if (StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
String reportId = dto.getReportId();
|
||||
if (StringUtils.equalsIgnoreCase(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||
reportId = dto.getTestPlanReportId();
|
||||
}
|
||||
apiScenarioReportService.margeReport(reportId, dto.getRunMode(), dto.getConsole());
|
||||
}
|
||||
// 集合报告合并
|
||||
this.margeReport(dto);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -356,13 +345,8 @@ public class ApiExecutionQueueService {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.equalsIgnoreCase(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
String reportId = dto.getReportId();
|
||||
if (StringUtils.equalsIgnoreCase(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||
reportId = dto.getTestPlanReportId();
|
||||
}
|
||||
apiScenarioReportService.margeReport(reportId, dto.getRunMode(), dto.getConsole());
|
||||
}
|
||||
// 集合报告合并
|
||||
this.margeReport(dto);
|
||||
queueMapper.deleteByPrimaryKey(dto.getQueueId());
|
||||
LoggerUtil.info("Queue execution ends:" + dto.getQueueId());
|
||||
}
|
||||
|
@ -374,6 +358,16 @@ public class ApiExecutionQueueService {
|
|||
LoggerUtil.info("处理队列结束:" + dto.getReportId() + "QID:" + dto.getQueueId());
|
||||
}
|
||||
|
||||
private void margeReport(ResultDTO dto) {
|
||||
if (StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
String reportId = dto.getReportId();
|
||||
if (StringUtils.equalsIgnoreCase(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||
reportId = dto.getTestPlanReportId();
|
||||
}
|
||||
apiScenarioReportService.margeReport(reportId, dto.getRunMode(), dto.getConsole());
|
||||
}
|
||||
}
|
||||
|
||||
public void defendQueue() {
|
||||
final int SECOND_MILLIS = 1000;
|
||||
final int MINUTE_MILLIS = 60 * SECOND_MILLIS;
|
||||
|
|
|
@ -2,10 +2,6 @@ package io.metersphere.service;
|
|||
|
||||
import io.metersphere.api.dto.automation.ApiTestReportVariable;
|
||||
import io.metersphere.api.exec.scenario.ApiEnvironmentRunningParamService;
|
||||
import io.metersphere.service.definition.ApiDefinitionExecResultService;
|
||||
import io.metersphere.service.scenario.ApiScenarioService;
|
||||
import io.metersphere.service.scenario.ApiScenarioExecutionInfoService;
|
||||
import io.metersphere.service.scenario.ApiScenarioReportService;
|
||||
import io.metersphere.base.domain.ApiDefinitionExecResultExample;
|
||||
import io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiScenarioReport;
|
||||
|
@ -22,9 +18,13 @@ import io.metersphere.commons.utils.DateUtils;
|
|||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||
import io.metersphere.dto.ResultDTO;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.notice.sender.NoticeModel;
|
||||
import io.metersphere.notice.service.NoticeSendService;
|
||||
import io.metersphere.service.definition.ApiDefinitionExecResultService;
|
||||
import io.metersphere.service.scenario.ApiScenarioExecutionInfoService;
|
||||
import io.metersphere.service.scenario.ApiScenarioReportService;
|
||||
import io.metersphere.service.scenario.ApiScenarioReportStructureService;
|
||||
import io.metersphere.service.scenario.ApiScenarioService;
|
||||
import org.apache.commons.beanutils.BeanMap;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -33,11 +33,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
@ -58,6 +54,8 @@ public class TestResultService {
|
|||
private RedisTemplate<String, Object> redisTemplate;
|
||||
@Resource
|
||||
private ApiScenarioExecutionInfoService scenarioExecutionInfoService;
|
||||
@Resource
|
||||
private ApiScenarioReportStructureService apiScenarioReportStructureService;
|
||||
|
||||
// 场景
|
||||
private static final List<String> scenarioRunModes = new ArrayList<>() {{
|
||||
|
@ -111,16 +109,14 @@ public class TestResultService {
|
|||
}
|
||||
|
||||
/**
|
||||
* 批量存储执行结果
|
||||
*
|
||||
* @param resultDtoMap
|
||||
* 批量存储来自NODE/K8s的执行结果
|
||||
*/
|
||||
public void batchSaveResults(Map<String, List<ResultDTO>> resultDtoMap) {
|
||||
// 处理环境
|
||||
List<String> environmentList = new LinkedList<>();
|
||||
for (String key : resultDtoMap.keySet()) {
|
||||
List<ResultDTO> dtos = resultDtoMap.get(key);
|
||||
for (ResultDTO dto : dtos) {
|
||||
List<ResultDTO> resultDTOS = resultDtoMap.get(key);
|
||||
for (ResultDTO dto : resultDTOS) {
|
||||
if (dto.getArbitraryData() != null && dto.getArbitraryData().containsKey("ENV")) {
|
||||
environmentList = (List<String>) dto.getArbitraryData().get("ENV");
|
||||
}
|
||||
|
@ -128,14 +124,22 @@ public class TestResultService {
|
|||
if (CollectionUtils.isNotEmpty(environmentList)) {
|
||||
apiEnvironmentRunningParamService.parseEnvironment(environmentList);
|
||||
}
|
||||
// 处理集合报告的console日志
|
||||
if (StringUtils.isNotEmpty(dto.getConsole()) && StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
String reportId = dto.getReportId();
|
||||
if (StringUtils.equalsIgnoreCase(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||
reportId = dto.getTestPlanReportId();
|
||||
}
|
||||
apiScenarioReportStructureService.update(reportId, dto.getConsole(), true);
|
||||
}
|
||||
}
|
||||
//测试计划定时任务-接口执行逻辑的话,需要同步测试计划的报告数据
|
||||
if (StringUtils.equals(key, "schedule-task")) {
|
||||
apiDefinitionExecResultService.batchSaveApiResult(dtos, true);
|
||||
apiDefinitionExecResultService.batchSaveApiResult(resultDTOS, true);
|
||||
} else if (StringUtils.equals(key, "api-test-case-task")) {
|
||||
apiDefinitionExecResultService.batchSaveApiResult(dtos, false);
|
||||
apiDefinitionExecResultService.batchSaveApiResult(resultDTOS, false);
|
||||
} else if (StringUtils.equalsAny(key, "api-scenario-task")) {
|
||||
apiScenarioReportService.batchSaveResult(dtos);
|
||||
apiScenarioReportService.batchSaveResult(resultDTOS);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,11 +42,7 @@ import io.metersphere.base.mapper.plan.TestPlanApiScenarioMapper;
|
|||
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiScenarioReportResultMapper;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.constants.NoticeConstants;
|
||||
import io.metersphere.commons.constants.ReportTriggerMode;
|
||||
import io.metersphere.commons.constants.ReportTypeConstants;
|
||||
import io.metersphere.commons.constants.TriggerMode;
|
||||
import io.metersphere.commons.constants.*;
|
||||
import io.metersphere.commons.enums.ApiReportStatus;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
|
@ -151,7 +147,7 @@ public class ApiScenarioReportService {
|
|||
public ApiScenarioReport testEnded(ResultDTO dto) {
|
||||
if (!StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
// 更新控制台信息
|
||||
apiScenarioReportStructureService.update(dto.getReportId(), dto.getConsole());
|
||||
apiScenarioReportStructureService.update(dto.getReportId(), dto.getConsole(), false);
|
||||
}
|
||||
// 优化当前执行携带结果作为状态判断依据
|
||||
ApiScenarioReport scenarioReport;
|
||||
|
@ -435,6 +431,7 @@ public class ApiScenarioReportService {
|
|||
|
||||
public void margeReport(String reportId, String runMode, String console) {
|
||||
// 更新场景状态
|
||||
boolean isActuator = false;
|
||||
if (StringUtils.equalsIgnoreCase(runMode, ApiRunMode.DEFINITION.name())) {
|
||||
ApiDefinitionExecResultWithBLOBs result = definitionExecResultMapper.selectByPrimaryKey(reportId);
|
||||
if (!StringUtils.equalsAnyIgnoreCase(result.getStatus(), ApiReportStatus.RERUNNING.name())) {
|
||||
|
@ -443,6 +440,7 @@ public class ApiScenarioReportService {
|
|||
List<String> statusList = extApiDefinitionExecResultMapper.selectDistinctStatusByReportId(reportId);
|
||||
result.setStatus(this.getIntegrationReportStatus(statusList));
|
||||
definitionExecResultMapper.updateByPrimaryKeySelective(result);
|
||||
isActuator = !StringUtils.equals(result.getActuator(), StorageConstants.LOCAL.name());
|
||||
} else {
|
||||
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId);
|
||||
if (report != null) {
|
||||
|
@ -455,17 +453,16 @@ public class ApiScenarioReportService {
|
|||
apiScenarioReportMapper.updateByPrimaryKey(report);
|
||||
//场景集合报告,按照集合报告的结果作为场景的最后执行结果
|
||||
scenarioExecutionInfoService.insertExecutionInfoByScenarioIds(report.getScenarioId(), report.getStatus(), report.getTriggerMode());
|
||||
isActuator = !StringUtils.equals(report.getActuator(), StorageConstants.LOCAL.name());
|
||||
}
|
||||
}
|
||||
|
||||
console = StringUtils.isNotEmpty(console) ? console : FixedCapacityUtil.getJmeterLogger(reportId, true);
|
||||
if (StringUtils.isNotEmpty(console)) {
|
||||
apiScenarioReportStructureService.update(reportId, console);
|
||||
if (StringUtils.isNotEmpty(console) && !isActuator) {
|
||||
apiScenarioReportStructureService.update(reportId, console, false);
|
||||
}
|
||||
// 更新控制台信息
|
||||
if (FixedCapacityUtil.jmeterLogTask.containsKey(reportId)) {
|
||||
FixedCapacityUtil.jmeterLogTask.remove(reportId);
|
||||
}
|
||||
FixedCapacityUtil.remove(reportId);
|
||||
}
|
||||
|
||||
public ApiScenarioReport updateScenario(ResultDTO dto) {
|
||||
|
|
|
@ -116,12 +116,16 @@ public class ApiScenarioReportStructureService {
|
|||
}
|
||||
}
|
||||
|
||||
public void update(String reportId, String console) {
|
||||
public void update(String reportId, String console, boolean isActuator) {
|
||||
ApiScenarioReportStructureExample example = new ApiScenarioReportStructureExample();
|
||||
example.createCriteria().andReportIdEqualTo(reportId);
|
||||
List<ApiScenarioReportStructureWithBLOBs> structures = mapper.selectByExampleWithBLOBs(example);
|
||||
for (ApiScenarioReportStructureWithBLOBs structure : structures) {
|
||||
structure.setConsole(console);
|
||||
if (isActuator) {
|
||||
structure.setConsole(StringUtils.join(structure.getConsole(), StringUtils.LF, console));
|
||||
} else {
|
||||
structure.setConsole(console);
|
||||
}
|
||||
mapper.updateByPrimaryKeyWithBLOBs(structure);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -229,7 +229,7 @@
|
|||
</rollingPolicy>
|
||||
<encoder>
|
||||
<charset>UTF-8</charset>
|
||||
<Pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</Pattern>
|
||||
<Pattern>%d %t %-5level %logger{36} %line - %msg%n</Pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<appender name="infoTestPlanAsyncAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
|
@ -252,7 +252,7 @@
|
|||
</filter>
|
||||
<File>${logging.file.path}/ms-jmeter-run.log</File>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<FileNamePattern>${logging.file.path}/history/ms-jmeter-run-log.%d{yyyyMMdd}-%i.log
|
||||
<FileNamePattern>${logging.file.path}/history/ms-jmeter-run.%d{yyyyMMdd}-%i.log
|
||||
</FileNamePattern>
|
||||
<maxHistory>${logger.max.history:-30}</maxHistory>
|
||||
<TimeBasedFileNamingAndTriggeringPolicy
|
||||
|
@ -262,7 +262,7 @@
|
|||
</rollingPolicy>
|
||||
<encoder>
|
||||
<charset>UTF-8</charset>
|
||||
<Pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</Pattern>
|
||||
<Pattern>%d %t %-5level %logger{36} %line - %msg%n</Pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<appender name="runLogAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
|
@ -272,7 +272,7 @@
|
|||
<queueSize>10000</queueSize>
|
||||
<appender-ref ref="apiRunLogAppender"/>
|
||||
</appender>
|
||||
<logger name="ms-jmeter-run-log" additivity="false">
|
||||
<logger name="ms-jmeter-run" additivity="false">
|
||||
<level value="${logger.level:INFO}"/>
|
||||
<appender-ref ref="runLogAppender"/>
|
||||
</logger>
|
||||
|
|
Loading…
Reference in New Issue