perf(测试跟踪): 导入性能优化

This commit is contained in:
fit2-zhao 2020-09-17 13:51:50 +08:00
parent 8ca36bd18f
commit dfc7f1755e
4 changed files with 25 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package io.metersphere.xmind;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.TestCaseWithBLOBs;
@ -23,6 +24,8 @@ import java.util.*;
/**
* 数据转换
* 1 解析Xmind文件 XmindParser.parseJson
* 2 解析后的JSON 转成测试用例
*/
public class XmindToTestCaseParser {
@ -218,14 +221,25 @@ public class XmindToTestCaseParser {
return true;
}
// 导入思维导图处理
public String importXmind(MultipartFile multipartFile) {
StringBuffer processBuffer = new StringBuffer();
File file = null;
try {
File file = multipartFileToFile(multipartFile);
file = multipartFileToFile(multipartFile);
if (file == null || !file.exists())
return Translator.get("incorrect_format");
JsonRootBean root = XmindParser.parseObject(file);
file.delete();
// 获取思维导图内容
String content = XmindParser.parseJson(file);
if (StringUtils.isEmpty(content) || content.split("(?:tc:|tc)").length == 1) {
return Translator.get("import_xmind_not_found");
}
if (!StringUtils.isEmpty(content) && content.split("(?:tc:|tc)").length > 500) {
return Translator.get("import_xmind_count_error");
}
JsonRootBean root = JSON.parseObject(content, JsonRootBean.class);
if (root != null && root.getRootTopic() != null && root.getRootTopic().getChildren() != null) {
// 判断是模块还是用例
root.getRootTopic().getChildren().getAttached().forEach(item -> {
@ -246,6 +260,8 @@ public class XmindToTestCaseParser {
LogUtil.error(ex.getMessage());
ex.printStackTrace();
} finally {
if (file != null)
file.delete();
testCaseWithBLOBs.clear();
}
return process.toString();

View File

@ -153,3 +153,5 @@ quota_duration_excess_workspace=The stress test duration exceeds the work space
quota_duration_excess_organization=The stress test duration exceeds the organization quota
email_subject=Metersphere timing task result notification
import_xmind_count_error=The number of use cases imported into the mind map cannot exceed 500
import_xmind_not_found=Test case not found

View File

@ -152,6 +152,8 @@ quota_max_threads_excess_organization=最大并发数超过组织限额
quota_duration_excess_workspace=压测时长超过工作空间限额
quota_duration_excess_organization=压测时长超过组织限额
email_subject=MeterSphere定时任务结果通知
import_xmind_count_error=思维导图导入用例数量不能超过 500 条
import_xmind_not_found=未找到测试用例

View File

@ -156,3 +156,5 @@ license_valid_license_code=授權碼已經存在
email_subject=MeterSphere定時任務結果通知
import_xmind_count_error=思維導圖導入用例數量不能超過 500 條
import_xmind_not_found=未找到测试用例