feat(性能测试): 修复性能测试的报告

修复性能测试执行成功后的回掉函数,采用异步事件处理kafka的消费
This commit is contained in:
song-tianyang 2022-04-21 10:50:46 +08:00 committed by TIanyang
parent 9a0db1e2af
commit 1a5ac05302
3 changed files with 40 additions and 10 deletions

View File

@ -2,7 +2,6 @@ package io.metersphere.commons.consumer;
import com.alibaba.fastjson.JSON;
import io.metersphere.Application;
import io.metersphere.api.service.ApiExecutionQueueService;
import io.metersphere.base.domain.LoadTestReport;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil;
@ -12,7 +11,6 @@ import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Set;
@Service
@ -20,9 +18,6 @@ import java.util.Set;
public class LoadTestConsumer {
public static final String CONSUME_ID = "load-test-data";
@Resource
ApiExecutionQueueService apiExecutionQueueService;
@KafkaListener(id = CONSUME_ID, topics = "${kafka.test.topic}", groupId = "${spring.kafka.consumer.group-id}")
public void consume(ConsumerRecord<?, String> record) {
LoadTestReport loadTestReport = JSON.parseObject(record.value(), LoadTestReport.class);
@ -35,7 +30,5 @@ public class LoadTestConsumer {
LogUtil.error(e);
}
});
//删除性能测试在执行队列中的数据 在测试计划执行中会将性能测试执行添加到执行队列用于判断整个测试计划到执行进度
apiExecutionQueueService.checkExecutionQueneByLoadTest(loadTestReport);
}
}

View File

@ -0,0 +1,35 @@
package io.metersphere.performance.notice;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.api.service.ApiExecutionQueueService;
import io.metersphere.base.domain.LoadTestReport;
import io.metersphere.commons.consumer.LoadTestFinishEvent;
import io.metersphere.commons.utils.LogUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
public class PerformanceQueueEvent implements LoadTestFinishEvent {
@Resource
ApiExecutionQueueService apiExecutionQueueService;
public void sendNotice(LoadTestReport loadTestReport) {
//删除性能测试在执行队列中的数据 在测试计划执行中会将性能测试执行添加到执行队列用于判断整个测试计划到执行进度
try {
apiExecutionQueueService.checkExecutionQueneByLoadTest(loadTestReport);
} catch (Exception e) {
LogUtil.error("PerformanceQueueEvent error. id:" + loadTestReport.getId());
}
}
@Override
public void execute(LoadTestReport loadTestReport) {
LogUtil.info("PerformanceQueueEvent start. id:" + loadTestReport.getId() + ", DATA:" + JSONObject.toJSONString(loadTestReport));
if (StringUtils.isNotEmpty(loadTestReport.getId())) {
sendNotice(loadTestReport);
}
LogUtil.info("PerformanceQueueEvent OVER. id:" + loadTestReport.getId());
}
}

View File

@ -1088,10 +1088,12 @@ public class TestPlanService {
}
}
if(MapUtils.isNotEmpty(loadCaseReportMap)){
//将性能测试加入到队列中
apiExecutionQueueService.add(loadCaseReportMap, null, ApiRunMode.TEST_PLAN_PERFORMANCE_TEST.name(),
planReportId, null, null, new RunModeConfigDTO());
}
//将性能测试加入到队列中
apiExecutionQueueService.add(loadCaseReportMap, null, ApiRunMode.TEST_PLAN_PERFORMANCE_TEST.name(),
planReportId, null, null, new RunModeConfigDTO());
return loadCaseReportMap;
}