refactor(测试计划): 计划关联关系更新方法事务调整

This commit is contained in:
fit2-zhao 2023-05-17 18:05:25 +08:00 committed by fit2-zhao
parent 9aa325e512
commit ae675915fe
2 changed files with 18 additions and 11 deletions

View File

@ -7,7 +7,6 @@ import io.metersphere.base.mapper.ApiScenarioMapper;
import io.metersphere.base.mapper.TestPlanApiCaseMapper;
import io.metersphere.base.mapper.TestPlanApiScenarioMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@ -22,18 +21,18 @@ public class TestPlanResourceService {
private ApiScenarioMapper apiScenarioMapper;
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updatePlanScenario(TestPlanApiScenario testPlanApiScenario){
@Transactional(rollbackFor = Exception.class)
public void updatePlanScenario(TestPlanApiScenario testPlanApiScenario) {
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updatePlanCase(TestPlanApiCase testPlanApiCase){
@Transactional(rollbackFor = Exception.class)
public void updatePlanCase(TestPlanApiCase testPlanApiCase) {
tstPlanApiCaseMapper.updateByPrimaryKeySelective(testPlanApiCase);
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateScenario(ApiScenario apiScenario){
@Transactional(rollbackFor = Exception.class)
public void updateScenario(ApiScenario apiScenario) {
apiScenarioMapper.updateByPrimaryKey(apiScenario);
}

View File

@ -5,17 +5,25 @@ import io.metersphere.api.jmeter.FixedCapacityUtils;
import io.metersphere.cache.JMeterEngineCache;
import io.metersphere.commons.constants.APITestStatus;
import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.dto.JmeterRunRequestDTO;
import io.metersphere.dto.ResultDTO;
import io.metersphere.utils.LoggerUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
@Service
public class RemakeReportService {
@Resource
@Lazy
private ApiExecutionQueueService apiExecutionQueueService;
@Resource
@Lazy
private TestResultService testResultService;
public void testEnded(JmeterRunRequestDTO request, String errorMsg) {
try {
ResultDTO dto = new ResultDTO();
@ -37,15 +45,15 @@ public class RemakeReportService {
String consoleMsg = FixedCapacityUtils.getJmeterLogger(dto.getReportId(), true);
dto.setConsole(consoleMsg + "\n" + errorMsg);
// 整体执行结束更新资源状态
CommonBeanFactory.getBean(TestResultService.class).testEnded(dto);
testResultService.testEnded(dto);
if (StringUtils.isNotEmpty(dto.getQueueId())) {
CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto);
apiExecutionQueueService.queueNext(dto);
}
// 更新测试计划报告
if (StringUtils.isNotEmpty(dto.getTestPlanReportId())) {
LoggerUtil.info("Check Processing Test Plan report status" + dto.getQueueId() + "" + dto.getTestId(), dto.getReportId());
CommonBeanFactory.getBean(ApiExecutionQueueService.class).testPlanReportTestEnded(dto.getTestPlanReportId());
apiExecutionQueueService.testPlanReportTestEnded(dto.getTestPlanReportId());
}
} catch (Exception e) {
LoggerUtil.error("回归报告异常", request.getReportId(), e);