fix(接口测试): 修复大JSON执行报错问题
--bug=1011847 --user=赵勇 【接口测试】json太大,导入到接口定义和作为请求体发送会报错 https://www.tapd.cn/55049933/s/1129499
This commit is contained in:
parent
e11cc40f21
commit
697a919ebb
|
@ -96,9 +96,10 @@ public class Body {
|
|||
} else {
|
||||
try {
|
||||
if (StringUtils.isNotEmpty(this.getRaw())) {
|
||||
String jsonString = JSON.toJSONString(this.getRaw(), SerializerFeature.DisableCircularReferenceDetect);
|
||||
JSONObject jsonObject = JSON.parseObject(jsonString);
|
||||
jsonMockParse(jsonObject);
|
||||
JSONObject jsonObject = JSON.parseObject(this.getRaw());
|
||||
if (!this.getRaw().contains("$ref")) {
|
||||
jsonMockParse(jsonObject);
|
||||
}
|
||||
this.raw = JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -13,6 +13,7 @@ import io.metersphere.api.jmeter.ResourcePoolCalculation;
|
|||
import io.metersphere.api.service.ApiExecutionQueueService;
|
||||
import io.metersphere.api.service.RemakeReportService;
|
||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||
import io.metersphere.base.domain.TestResource;
|
||||
import io.metersphere.base.domain.TestResourcePool;
|
||||
import io.metersphere.base.mapper.TestResourcePoolMapper;
|
||||
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
|
||||
|
@ -21,7 +22,6 @@ import io.metersphere.commons.utils.CommonBeanFactory;
|
|||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.dto.JmeterRunRequestDTO;
|
||||
import io.metersphere.dto.JvmInfoDTO;
|
||||
import io.metersphere.dto.ResultDTO;
|
||||
import io.metersphere.dto.RunModeConfigDTO;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
|
@ -128,7 +128,7 @@ public class GenerateHashTreeUtil {
|
|||
return pool;
|
||||
}
|
||||
|
||||
public static List<JvmInfoDTO> setPoolResource(String id) {
|
||||
public static List<TestResource> setPoolResource(String id) {
|
||||
if (GenerateHashTreeUtil.isResourcePool(id).isPool() && !GenerateHashTreeUtil.isResourcePool(id).isK8s()) {
|
||||
ResourcePoolCalculation resourcePoolCalculation = CommonBeanFactory.getBean(ResourcePoolCalculation.class);
|
||||
return resourcePoolCalculation.getPools(id);
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.metersphere.api.exec.queue.ExecThreadPoolExecutor;
|
|||
import io.metersphere.api.exec.utils.GenerateHashTreeUtil;
|
||||
import io.metersphere.api.service.ApiScenarioReportService;
|
||||
import io.metersphere.api.service.RemakeReportService;
|
||||
import io.metersphere.base.domain.TestResource;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
|
@ -148,9 +149,9 @@ public class JMeterService {
|
|||
}
|
||||
}
|
||||
|
||||
private synchronized void send(JmeterRunRequestDTO request) {
|
||||
private void send(JmeterRunRequestDTO request) {
|
||||
try {
|
||||
List<JvmInfoDTO> resources = GenerateHashTreeUtil.setPoolResource(request.getPoolId());
|
||||
List<TestResource> resources = GenerateHashTreeUtil.setPoolResource(request.getPoolId());
|
||||
if (CollectionUtils.isEmpty(resources)) {
|
||||
LoggerUtil.info("未获取到资源池,请检查配置【系统设置-系统-测试资源池】");
|
||||
RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class);
|
||||
|
@ -159,8 +160,7 @@ public class JMeterService {
|
|||
}
|
||||
|
||||
int index = (int) (Math.random() * resources.size());
|
||||
JvmInfoDTO jvmInfoDTO = resources.get(index);
|
||||
TestResourceDTO testResource = jvmInfoDTO.getTestResource();
|
||||
TestResource testResource = resources.get(index);
|
||||
String configuration = testResource.getConfiguration();
|
||||
NodeDTO node = JSON.parseObject(configuration, NodeDTO.class);
|
||||
request.setCorePoolSize(node.getMaxConcurrency());
|
||||
|
@ -200,13 +200,12 @@ public class JMeterService {
|
|||
|
||||
public boolean getRunningQueue(String poolId, String reportId) {
|
||||
try {
|
||||
List<JvmInfoDTO> resources = GenerateHashTreeUtil.setPoolResource(poolId);
|
||||
List<TestResource> resources = GenerateHashTreeUtil.setPoolResource(poolId);
|
||||
if (CollectionUtils.isEmpty(resources)) {
|
||||
return false;
|
||||
}
|
||||
boolean isRunning = false;
|
||||
for (JvmInfoDTO jvmInfoDTO : resources) {
|
||||
TestResourceDTO testResource = jvmInfoDTO.getTestResource();
|
||||
for (TestResource testResource : resources) {
|
||||
String configuration = testResource.getConfiguration();
|
||||
NodeDTO node = JSON.parseObject(configuration, NodeDTO.class);
|
||||
String nodeIp = node.getIp();
|
||||
|
|
|
@ -7,11 +7,9 @@ import io.metersphere.base.domain.TestResourcePool;
|
|||
import io.metersphere.base.domain.TestResourcePoolExample;
|
||||
import io.metersphere.base.mapper.TestResourceMapper;
|
||||
import io.metersphere.base.mapper.TestResourcePoolMapper;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.dto.JvmInfoDTO;
|
||||
import io.metersphere.dto.NodeDTO;
|
||||
import io.metersphere.dto.TestResourceDTO;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
@ -33,22 +31,22 @@ public class ResourcePoolCalculation {
|
|||
|
||||
private static final String BASE_URL = "http://%s:%d";
|
||||
|
||||
private JvmInfoDTO getNodeJvmInfo(String uri) {
|
||||
private String getNodeJvmInfo(String uri) {
|
||||
try {
|
||||
return restTemplate.getForObject(uri, JvmInfoDTO.class);
|
||||
return restTemplate.getForObject(uri, String.class);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<JvmInfoDTO> getPools(String resourcePoolId) {
|
||||
public List<TestResource> getPools(String resourcePoolId) {
|
||||
// 获取可以执行的资源池
|
||||
TestResourcePoolExample example = new TestResourcePoolExample();
|
||||
example.createCriteria().andStatusEqualTo("VALID").andTypeEqualTo("NODE").andIdEqualTo(resourcePoolId);
|
||||
List<TestResourcePool> pools = testResourcePoolMapper.selectByExample(example);
|
||||
|
||||
// 按照NODE节点的可用内存空间大小排序
|
||||
List<JvmInfoDTO> availableNodes = new ArrayList<>();
|
||||
List<TestResource> availableNodes = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(pools)) {
|
||||
List<String> poolIds = pools.stream().map(pool -> pool.getId()).collect(Collectors.toList());
|
||||
TestResourceExample resourceExample = new TestResourceExample();
|
||||
|
@ -59,15 +57,12 @@ public class ResourcePoolCalculation {
|
|||
NodeDTO node = JSON.parseObject(configuration, NodeDTO.class);
|
||||
String nodeIp = node.getIp();
|
||||
Integer port = node.getPort();
|
||||
String uri = String.format(BASE_URL + "/jmeter/getJvmInfo", nodeIp, port);
|
||||
JvmInfoDTO nodeJvm = this.getNodeJvmInfo(uri);
|
||||
if (nodeJvm == null) {
|
||||
String uri = String.format(BASE_URL + "/jmeter/status", nodeIp, port);
|
||||
String status = this.getNodeJvmInfo(uri);
|
||||
if (!StringUtils.equals(status, "OK")) {
|
||||
continue;
|
||||
}
|
||||
TestResourceDTO dto = new TestResourceDTO();
|
||||
BeanUtils.copyBean(dto,testResource);
|
||||
nodeJvm.setTestResource(dto);
|
||||
availableNodes.add(nodeJvm);
|
||||
availableNodes.add(testResource);
|
||||
}
|
||||
}
|
||||
return availableNodes;
|
||||
|
|
|
@ -241,6 +241,7 @@ public class ApiExecutionQueueService {
|
|||
}
|
||||
|
||||
public void queueNext(ResultDTO dto) {
|
||||
LoggerUtil.info("开始处理队列:" + dto.getReportId() + "QID:" + dto.getQueueId());
|
||||
if (StringUtils.equals(dto.getRunType(), RunModeConstants.PARALLEL.toString())) {
|
||||
ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample();
|
||||
example.createCriteria().andQueueIdEqualTo(dto.getQueueId()).andTestIdEqualTo(dto.getTestId());
|
||||
|
@ -292,6 +293,7 @@ public class ApiExecutionQueueService {
|
|||
example.createCriteria().andQueueIdEqualTo(dto.getQueueId()).andTestIdEqualTo(dto.getTestId());
|
||||
executionQueueDetailMapper.deleteByExample(example);
|
||||
}
|
||||
LoggerUtil.info("处理队列结束:" + dto.getReportId() + "QID:" + dto.getQueueId());
|
||||
}
|
||||
|
||||
public void timeOut() {
|
||||
|
|
Loading…
Reference in New Issue