mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-02 12:09:13 +08:00
fix(接口定义): 修复case执行不显示资源池的缺陷
--bug=1021666 --user=王孝刚 【接口测试】接口定义-执行接口case不保存不会显示资源池和运行环境信息 https://www.tapd.cn/55049933/s/1324285
This commit is contained in:
parent
8ff9814e10
commit
582805e52b
@ -16,5 +16,6 @@ public class MsgDTO {
|
||||
private String reportId;
|
||||
private String toReport;
|
||||
private boolean execEnd;
|
||||
private String runMode;
|
||||
private String content;
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ public class RequestResultExpandDTO extends RequestResult {
|
||||
private String reportId;
|
||||
private long time;
|
||||
private Map<String, String> attachInfoMap;
|
||||
private String poolName;
|
||||
private String envName;
|
||||
|
||||
public RequestResultExpandDTO() {
|
||||
}
|
||||
|
@ -21,9 +21,11 @@ import io.metersphere.api.dto.MsgDTO;
|
||||
import io.metersphere.api.dto.RequestResultExpandDTO;
|
||||
import io.metersphere.api.dto.RunningParamKeys;
|
||||
import io.metersphere.api.exec.queue.PoolExecBlockingQueueUtil;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.dto.RequestResult;
|
||||
import io.metersphere.jmeter.JMeterBase;
|
||||
import io.metersphere.service.definition.ApiDefinitionEnvService;
|
||||
import io.metersphere.utils.JMeterVars;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@ -151,11 +153,15 @@ public class MsDebugListener extends AbstractListenerElement implements SampleLi
|
||||
dto.setToReport(this.getName());
|
||||
|
||||
String console = FixedCapacityUtil.getJmeterLogger(this.getName(), false);
|
||||
ApiDefinitionEnvService apiDefinitionEnvService = CommonBeanFactory.getBean(ApiDefinitionEnvService.class);
|
||||
if (StringUtils.isNotEmpty(requestResult.getName()) && requestResult.getName().startsWith("Transaction=")) {
|
||||
requestResult.getSubRequestResults().forEach(transactionResult -> {
|
||||
transactionResult.getResponseResult().setConsole(console);
|
||||
//对响应内容进行进一步解析和处理。
|
||||
RequestResultExpandDTO expandDTO = ResponseUtil.parseByRequestResult(transactionResult);
|
||||
if (StringUtils.equals(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||
apiDefinitionEnvService.setEnvAndPoolName(transactionResult, expandDTO);
|
||||
}
|
||||
dto.setContent("result_" + JSON.toJSONString(expandDTO));
|
||||
WebSocketUtil.sendMessageSingle(dto);
|
||||
});
|
||||
@ -163,6 +169,9 @@ public class MsDebugListener extends AbstractListenerElement implements SampleLi
|
||||
requestResult.getResponseResult().setConsole(console);
|
||||
//对响应内容进行进一步解析和处理。
|
||||
RequestResultExpandDTO expandDTO = ResponseUtil.parseByRequestResult(requestResult);
|
||||
if (StringUtils.equals(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||
apiDefinitionEnvService.setEnvAndPoolName(requestResult, expandDTO);
|
||||
}
|
||||
dto.setContent("result_" + JSON.toJSONString(expandDTO));
|
||||
WebSocketUtil.sendMessageSingle(dto);
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
package io.metersphere.api.jmeter;
|
||||
|
||||
import io.metersphere.api.dto.MsgDTO;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.constants.KafkaTopicConstants;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.JSONUtil;
|
||||
import io.metersphere.commons.utils.NamedThreadFactory;
|
||||
import io.metersphere.commons.utils.WebSocketUtil;
|
||||
import io.metersphere.service.ApiExecutionQueueService;
|
||||
import io.metersphere.service.TestResultService;
|
||||
import io.metersphere.service.definition.ApiDefinitionEnvService;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -71,6 +74,10 @@ public class MsKafkaListener {
|
||||
LoggerUtil.info("接收到执行结果:", record.key());
|
||||
if (ObjectUtils.isNotEmpty(record.value()) && WebSocketUtil.has(record.key().toString())) {
|
||||
MsgDTO dto = JSONUtil.parseObject(record.value(), MsgDTO.class);
|
||||
if (StringUtils.equals(ApiRunMode.DEFINITION.name(), dto.getRunMode()) && dto.getContent().startsWith("result_")) {
|
||||
ApiDefinitionEnvService apiDefinitionEnvService = CommonBeanFactory.getBean(ApiDefinitionEnvService.class);
|
||||
apiDefinitionEnvService.setEnvAndPoolName(dto);
|
||||
}
|
||||
WebSocketUtil.sendMessageSingle(dto);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -1,10 +1,17 @@
|
||||
package io.metersphere.service.definition;
|
||||
|
||||
import io.metersphere.api.dto.ApiReportEnvConfigUtil;
|
||||
import io.metersphere.api.dto.MsgDTO;
|
||||
import io.metersphere.api.dto.RequestResultExpandDTO;
|
||||
import io.metersphere.base.domain.ApiDefinitionEnv;
|
||||
import io.metersphere.base.domain.ApiDefinitionEnvExample;
|
||||
import io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestEnvironmentExample;
|
||||
import io.metersphere.base.mapper.ApiDefinitionEnvMapper;
|
||||
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
|
||||
import io.metersphere.base.mapper.ApiTestEnvironmentMapper;
|
||||
import io.metersphere.commons.utils.JSON;
|
||||
import io.metersphere.dto.RequestResult;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -12,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@ -21,6 +29,10 @@ public class ApiDefinitionEnvService {
|
||||
private ApiDefinitionEnvMapper apiDefinitionEnvMapper;
|
||||
@Resource
|
||||
private ApiTestEnvironmentMapper apiTestEnvironmentMapper;
|
||||
@Resource
|
||||
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
|
||||
@Resource
|
||||
private ApiDefinitionService apiDefinitionService;
|
||||
|
||||
public void insert(ApiDefinitionEnv env) {
|
||||
env.setId(UUID.randomUUID().toString());
|
||||
@ -63,4 +75,32 @@ public class ApiDefinitionEnvService {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setEnvAndPoolName(RequestResult baseResult, RequestResultExpandDTO expandDTO) {
|
||||
if (StringUtils.isNotBlank(baseResult.getThreadName())) {
|
||||
ApiDefinitionExecResultWithBLOBs result = apiDefinitionExecResultMapper.selectByPrimaryKey(baseResult.getThreadName());
|
||||
if (result != null && StringUtils.isNotEmpty(result.getEnvConfig())) {
|
||||
ApiReportEnvConfigUtil envConfig = apiDefinitionService.getEnvNameByEnvConfig(result.getProjectId(), result.getEnvConfig());
|
||||
if (envConfig != null) {
|
||||
expandDTO.setEnvName(envConfig.getEnvName());
|
||||
expandDTO.setPoolName(envConfig.getResourcePoolName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setEnvAndPoolName(MsgDTO dto) {
|
||||
if (StringUtils.isNotBlank(dto.getToReport())) {
|
||||
ApiDefinitionExecResultWithBLOBs result = apiDefinitionExecResultMapper.selectByPrimaryKey(dto.getToReport());
|
||||
if (result != null && StringUtils.isNotEmpty(result.getEnvConfig())) {
|
||||
ApiReportEnvConfigUtil envConfig = apiDefinitionService.getEnvNameByEnvConfig(result.getProjectId(), result.getEnvConfig());
|
||||
if (envConfig != null) {
|
||||
Map map = JSON.parseObject(dto.getContent().substring(7), Map.class);
|
||||
map.put("envName", envConfig.getEnvName());
|
||||
map.put("poolName", envConfig.getResourcePoolName());
|
||||
dto.setContent("result_" + JSON.toJSONString(map));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,6 @@ export default {
|
||||
|
||||
<style scoped>
|
||||
.header {
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user