diff --git a/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseSerialService.java b/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseSerialService.java index ffec7d9ab2..f91d62d214 100644 --- a/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseSerialService.java +++ b/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseSerialService.java @@ -38,7 +38,6 @@ import io.metersphere.dto.JmeterRunRequestDTO; import io.metersphere.dto.ResultDTO; import io.metersphere.plugin.core.MsTestElement; import io.metersphere.utils.LoggerUtil; -import io.metersphere.xpack.api.dto.MsRetryLoopController; import org.apache.commons.lang3.StringUtils; import org.apache.jorphan.collections.HashTree; import org.springframework.data.redis.core.RedisTemplate; @@ -134,13 +133,6 @@ public class ApiCaseSerialService { } if (caseWithBLOBs != null) { String data = caseWithBLOBs.getRequest(); - // 失败重试 - if (runRequest.isRetryEnable() && runRequest.getRetryNum() > 0) { - ApiRetryOnFailureService apiRetryOnFailureService = CommonBeanFactory.getBean(ApiRetryOnFailureService.class); - String retryData = apiRetryOnFailureService.retry(data, runRequest.getRetryNum(), true); - data = StringUtils.isNotEmpty(retryData) ? retryData : data; - } - HashTree jmeterHashTree = new HashTree(); MsTestPlan testPlan = new MsTestPlan(); testPlan.setHashTree(new LinkedList<>()); @@ -151,13 +143,16 @@ public class ApiCaseSerialService { group.setProjectId(caseWithBLOBs.getProjectId()); MsTestElement testElement = null; if (runRequest.isRetryEnable() && runRequest.getRetryNum() > 0) { - MsRetryLoopController controller = JSON.parseObject(data, MsRetryLoopController.class); - GenerateHashTreeUtil.parse(data, controller); - MsTestElement element = parse(JSON.toJSONString(controller.getHashTree().get(0)), testId, envId, caseWithBLOBs.getProjectId()); - controller.setHashTree(new LinkedList<>() {{ + // 失败重试 + ApiRetryOnFailureService apiRetryOnFailureService = CommonBeanFactory.getBean(ApiRetryOnFailureService.class); + String retryData = apiRetryOnFailureService.retry(data, runRequest.getRetryNum(), true); + data = StringUtils.isNotEmpty(retryData) ? retryData : data; + // 格式化数据 + testElement = apiRetryOnFailureService.retryParse(data); + MsTestElement element = parse(JSON.toJSONString(testElement.getHashTree().get(0)), testId, envId, caseWithBLOBs.getProjectId()); + testElement.setHashTree(new LinkedList<>() {{ this.add(element); }}); - testElement = controller; } else { testElement = parse(data, testId, envId, caseWithBLOBs.getProjectId()); } diff --git a/backend/src/main/java/io/metersphere/api/exec/api/ApiRetryOnFailureService.java b/backend/src/main/java/io/metersphere/api/exec/api/ApiRetryOnFailureService.java index 164bdd5815..aab54ba66e 100644 --- a/backend/src/main/java/io/metersphere/api/exec/api/ApiRetryOnFailureService.java +++ b/backend/src/main/java/io/metersphere/api/exec/api/ApiRetryOnFailureService.java @@ -1,5 +1,10 @@ package io.metersphere.api.exec.api; +import io.metersphere.plugin.core.MsTestElement; + public interface ApiRetryOnFailureService { public String retry(String data, long retryNum, boolean isCase); + + public MsTestElement retryParse(String retryCase); + } diff --git a/backend/src/main/java/io/metersphere/api/exec/utils/GenerateHashTreeUtil.java b/backend/src/main/java/io/metersphere/api/exec/utils/GenerateHashTreeUtil.java index 3ee3b13555..8bafaed3c7 100644 --- a/backend/src/main/java/io/metersphere/api/exec/utils/GenerateHashTreeUtil.java +++ b/backend/src/main/java/io/metersphere/api/exec/utils/GenerateHashTreeUtil.java @@ -27,7 +27,6 @@ import io.metersphere.plugin.core.MsTestElement; import io.metersphere.service.EnvironmentGroupProjectService; import io.metersphere.utils.LoggerUtil; import io.metersphere.vo.BooleanPool; -import io.metersphere.xpack.api.dto.MsRetryLoopController; import org.apache.commons.lang3.StringUtils; import org.apache.jorphan.collections.HashTree; @@ -72,23 +71,6 @@ public class GenerateHashTreeUtil { } } - public static void parse(String retryCase, MsRetryLoopController retryObj) { - try { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - JSONObject element = JSON.parseObject(retryCase, Feature.DisableSpecialKeyDetect); - ElementUtil.dataFormatting(element); - if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) { - LinkedList elements = mapper.readValue(element.getString("hashTree"), - new TypeReference>() { - }); - retryObj.setHashTree(elements); - } - } catch (Exception e) { - LogUtil.error(e); - } - } - public static LinkedList getScenarioHashTree(String definition) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);