refactor(测试计划): 执行部分代码优化

This commit is contained in:
fit2-zhao 2022-01-19 16:42:54 +08:00 committed by fit2-zhao
parent 003db4118e
commit 34a2b6351e
3 changed files with 13 additions and 5 deletions

View File

@ -64,7 +64,6 @@ public class GenerateHashTreeUtil {
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e);
LogUtil.error(e);
} }
} }

View File

@ -15,6 +15,9 @@ import org.apache.commons.lang3.StringUtils;
import java.util.Map; import java.util.Map;
public class APISingleResultListener extends MsExecListener { public class APISingleResultListener extends MsExecListener {
private ApiExecutionQueueService apiExecutionQueueService;
@Override @Override
public void handleTeardownTest(ResultDTO dto, Map<String, Object> kafkaConfig) { public void handleTeardownTest(ResultDTO dto, Map<String, Object> kafkaConfig) {
LoggerUtil.info("处理单条执行结果报告【" + dto.getReportId() + " 】,资源【 " + dto.getTestId() + ""); LoggerUtil.info("处理单条执行结果报告【" + dto.getReportId() + " 】,资源【 " + dto.getTestId() + "");
@ -39,14 +42,17 @@ public class APISingleResultListener extends MsExecListener {
// 整体执行结束更新资源状态 // 整体执行结束更新资源状态
CommonBeanFactory.getBean(TestResultService.class).testEnded(dto); CommonBeanFactory.getBean(TestResultService.class).testEnded(dto);
if (apiExecutionQueueService == null) {
apiExecutionQueueService = CommonBeanFactory.getBean(ApiExecutionQueueService.class);
}
LoggerUtil.info("执行队列处理:" + dto.getQueueId()); LoggerUtil.info("执行队列处理:" + dto.getQueueId());
if (StringUtils.isNotEmpty(dto.getQueueId())) { if (StringUtils.isNotEmpty(dto.getQueueId())) {
CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto); apiExecutionQueueService.queueNext(dto);
} }
// 更新测试计划报告 // 更新测试计划报告
if (StringUtils.isNotEmpty(dto.getTestPlanReportId())) { if (StringUtils.isNotEmpty(dto.getTestPlanReportId())) {
LoggerUtil.info("Check Processing Test Plan report status" + dto.getQueueId() + "" + dto.getTestId()); LoggerUtil.info("Check Processing Test Plan report status" + dto.getQueueId() + "" + dto.getTestId());
CommonBeanFactory.getBean(ApiExecutionQueueService.class).testPlanReportTestEnded(dto.getTestPlanReportId()); apiExecutionQueueService.testPlanReportTestEnded(dto.getTestPlanReportId());
} }
} catch (Exception e) { } catch (Exception e) {
LoggerUtil.error(e); LoggerUtil.error(e);

View File

@ -22,6 +22,8 @@ import javax.annotation.Resource;
@Service @Service
public class MsKafkaListener { public class MsKafkaListener {
public static final String CONSUME_ID = "ms-api-exec-consume"; public static final String CONSUME_ID = "ms-api-exec-consume";
@Resource
private ApiExecutionQueueService apiExecutionQueueService;
@KafkaListener(id = CONSUME_ID, topics = KafkaConfig.TOPICS, groupId = "${spring.kafka.consumer.group-id}") @KafkaListener(id = CONSUME_ID, topics = KafkaConfig.TOPICS, groupId = "${spring.kafka.consumer.group-id}")
public void consume(ConsumerRecord<?, String> record) { public void consume(ConsumerRecord<?, String> record) {
@ -30,14 +32,15 @@ public class MsKafkaListener {
if (testResult != null && testResult.getArbitraryData() != null && testResult.getArbitraryData().containsKey("TEST_END") && (Boolean) testResult.getArbitraryData().get("TEST_END")) { if (testResult != null && testResult.getArbitraryData() != null && testResult.getArbitraryData().containsKey("TEST_END") && (Boolean) testResult.getArbitraryData().get("TEST_END")) {
LoggerUtil.info("报告 【 " + testResult.getReportId() + " 】资源 " + testResult.getTestId() + " 整体执行完成"); LoggerUtil.info("报告 【 " + testResult.getReportId() + " 】资源 " + testResult.getTestId() + " 整体执行完成");
testResultService.testEnded(testResult); testResultService.testEnded(testResult);
LoggerUtil.info("执行队列处理:" + testResult.getQueueId()); LoggerUtil.info("执行队列处理:" + testResult.getQueueId());
CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(testResult); apiExecutionQueueService.queueNext(testResult);
// 全局并发队列 // 全局并发队列
PoolExecBlockingQueueUtil.offer(testResult.getReportId()); PoolExecBlockingQueueUtil.offer(testResult.getReportId());
// 更新测试计划报告 // 更新测试计划报告
if (StringUtils.isNotEmpty(testResult.getTestPlanReportId())) { if (StringUtils.isNotEmpty(testResult.getTestPlanReportId())) {
LoggerUtil.info("Check Processing Test Plan report status" + testResult.getQueueId() + "" + testResult.getTestId()); LoggerUtil.info("Check Processing Test Plan report status" + testResult.getQueueId() + "" + testResult.getTestId());
CommonBeanFactory.getBean(ApiExecutionQueueService.class).testPlanReportTestEnded(testResult.getTestPlanReportId()); apiExecutionQueueService.testPlanReportTestEnded(testResult.getTestPlanReportId());
} }
} else { } else {
// 更新报告最后接收到请求的时间 // 更新报告最后接收到请求的时间