fix(性能测试): 性能测试时执行时检查jmx文件
--bug=1026738 --user=宋天阳 【性能测试】上传非正常格式的JMX文件性能测试报告一直处于Starting状态 https://www.tapd.cn/55049933/s/1386050;--bug=1026577 --user=宋天阳 【性能测试】删除性能测试使用的JMX文件导致测试一直处于starting状态 https://www.tapd.cn/55049933/s/1386074
This commit is contained in:
parent
007697defc
commit
32d44ca75b
|
@ -104,7 +104,6 @@ public class FileManagerService {
|
||||||
list.addAll(FileCenter.getRepository(requestByStorageEntry.getKey()).getFileBatch(requestByStorageEntry.getValue()));
|
list.addAll(FileCenter.getRepository(requestByStorageEntry.getKey()).getFileBatch(requestByStorageEntry.getValue()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error("下载文件失败!", e);
|
LogUtil.error("下载文件失败!", e);
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -385,3 +385,5 @@ can_not_move_to_repository_node=Can not move to repository node
|
||||||
target_issue_template_not_checked=Cannot copy, target project not checked
|
target_issue_template_not_checked=Cannot copy, target project not checked
|
||||||
source_issue_template_is_empty=Copy error, source project is empty
|
source_issue_template_is_empty=Copy error, source project is empty
|
||||||
select_resource_error_and_check=Select the resource error, check it please
|
select_resource_error_and_check=Select the resource error, check it please
|
||||||
|
load_test_file_not_have_jmx=Load test not have jmx file
|
||||||
|
load_test_file_is_not_jmx=Load test JMX file is illegal
|
|
@ -382,3 +382,5 @@ name_already_exists_in_module=同层级下已经存在
|
||||||
target_issue_template_not_checked=无法复制,未选中目标项目
|
target_issue_template_not_checked=无法复制,未选中目标项目
|
||||||
source_issue_template_is_empty=复制错误,源项目为空
|
source_issue_template_is_empty=复制错误,源项目为空
|
||||||
select_resource_error_and_check=查找资源出错,请检查资源是否存在
|
select_resource_error_and_check=查找资源出错,请检查资源是否存在
|
||||||
|
load_test_file_not_have_jmx=性能測試里的JMX文件不存在
|
||||||
|
load_test_file_is_not_jmx=性能测试里的JMX文件不合法
|
|
@ -381,3 +381,5 @@ name_already_exists_in_module=同層級下已存在
|
||||||
target_issue_template_not_checked=無法複製,未選中目標項目
|
target_issue_template_not_checked=無法複製,未選中目標項目
|
||||||
source_issue_template_is_empty=複製錯誤,源項目為空
|
source_issue_template_is_empty=複製錯誤,源項目為空
|
||||||
select_resource_error_and_check=查找資源出錯,請檢查資源是否存在
|
select_resource_error_and_check=查找資源出錯,請檢查資源是否存在
|
||||||
|
load_test_file_not_have_jmx=性能測試文件中不包含JMX文件
|
||||||
|
load_test_file_is_not_jmx=性能測試里的JMX文件不合法
|
|
@ -357,6 +357,8 @@ public class PerformanceTestService {
|
||||||
|
|
||||||
@Transactional(noRollbackFor = MSException.class)// 保存失败的信息
|
@Transactional(noRollbackFor = MSException.class)// 保存失败的信息
|
||||||
public String run(RunTestPlanRequest request) {
|
public String run(RunTestPlanRequest request) {
|
||||||
|
//检查性能测试文件
|
||||||
|
this.checkLoadTestJmxFile(request.getId());
|
||||||
LogUtil.info("性能测试run测试");
|
LogUtil.info("性能测试run测试");
|
||||||
final LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(request.getId());
|
final LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(request.getId());
|
||||||
if (request.getUserId() != null) {
|
if (request.getUserId() != null) {
|
||||||
|
@ -380,6 +382,26 @@ public class PerformanceTestService {
|
||||||
return startEngine(loadTest, request);
|
return startEngine(loadTest, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkLoadTestJmxFile(String id) {
|
||||||
|
LoadTestFileExample loadTestFileExample = new LoadTestFileExample();
|
||||||
|
loadTestFileExample.createCriteria().andTestIdEqualTo(id);
|
||||||
|
List<LoadTestFile> loadTestFileList = loadTestFileMapper.selectByExample(loadTestFileExample);
|
||||||
|
List<String> fileIdList = loadTestFileList.stream().map(LoadTestFile::getFileId).collect(Collectors.toList());
|
||||||
|
List<FileInfoDTO> fileInfoDTOList = fileMetadataService.downloadFileByIds(fileIdList);
|
||||||
|
boolean hasJmx = false;
|
||||||
|
for (FileInfoDTO fileInfoDTO : fileInfoDTOList) {
|
||||||
|
if (StringUtils.equalsIgnoreCase(fileInfoDTO.getType(), "jmx")) {
|
||||||
|
hasJmx = true;
|
||||||
|
if (!JmxParseUtil.isJmxFile(fileInfoDTO.getFileByte())) {
|
||||||
|
MSException.throwException(Translator.get("load_test_file_is_not_jmx"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasJmx) {
|
||||||
|
MSException.throwException(Translator.get("load_test_file_not_have_jmx"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void checkKafka() {
|
private void checkKafka() {
|
||||||
String bootstrapServers = kafkaProperties.getBootstrapServers();
|
String bootstrapServers = kafkaProperties.getBootstrapServers();
|
||||||
String[] servers = StringUtils.split(bootstrapServers, ",");
|
String[] servers = StringUtils.split(bootstrapServers, ",");
|
||||||
|
|
|
@ -18,6 +18,22 @@ import java.util.List;
|
||||||
|
|
||||||
//Jmx解析工具类
|
//Jmx解析工具类
|
||||||
public class JmxParseUtil {
|
public class JmxParseUtil {
|
||||||
|
|
||||||
|
public static boolean isJmxFile(byte[] jmxFileByte) {
|
||||||
|
try {
|
||||||
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
XMLUtils.setExpandEntityReferencesFalse(documentBuilderFactory);
|
||||||
|
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
|
||||||
|
final Document document = builder.parse(new InputSource(new ByteArrayInputStream(jmxFileByte)));
|
||||||
|
final Element jmxDoc = document.getDocumentElement();
|
||||||
|
if (StringUtils.equals(jmxDoc.getNodeName(), "jmeterTestPlan")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isJmxHasScriptByFiles(List<MultipartFile> files) {
|
public static boolean isJmxHasScriptByFiles(List<MultipartFile> files) {
|
||||||
if (CollectionUtils.isNotEmpty(files)) {
|
if (CollectionUtils.isNotEmpty(files)) {
|
||||||
for (MultipartFile file : files) {
|
for (MultipartFile file : files) {
|
||||||
|
|
|
@ -285,6 +285,7 @@ public class TestPlanController {
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_PLAN_READ_RUN)
|
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_PLAN_READ_RUN)
|
||||||
@MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.testPlanIds)", msClass = TestPlanService.class)
|
@MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.testPlanIds)", msClass = TestPlanService.class)
|
||||||
public void runBatch(@RequestBody TestPlanRunRequest request) {
|
public void runBatch(@RequestBody TestPlanRunRequest request) {
|
||||||
|
baseUserService.checkUserAndProject(request.getUserId(), request.getProjectId());
|
||||||
request.setTriggerMode(TriggerMode.BATCH.name());
|
request.setTriggerMode(TriggerMode.BATCH.name());
|
||||||
testPlanService.runBatch(request);
|
testPlanService.runBatch(request);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue