feat(接口测试): 添加执行完成后通知测试计划处理相关状态及报告聚合

This commit is contained in:
fit2-zhao 2024-01-10 10:53:01 +08:00 committed by Craftsman
parent 3a59afebfa
commit 28fc68f13d
4 changed files with 23 additions and 7 deletions

View File

@ -22,4 +22,5 @@ public class ApiNoticeDTO implements java.io.Serializable {
private String projectId;
private List<String> environmentIds;
private String reportId;
private String queueId;
}

View File

@ -21,6 +21,7 @@ public class TaskRequest implements Serializable {
private String kafkaConfig;
private String minioConfig;
private String poolId;
private String queueId;
/**
* 是否需要实时接收单个步骤的结果
*/

View File

@ -1,9 +1,12 @@
package io.metersphere.api.listener;
import io.metersphere.api.event.ApiEventSource;
import io.metersphere.api.service.ApiReportSendNoticeService;
import io.metersphere.api.service.queue.ApiExecutionQueueService;
import io.metersphere.sdk.constants.ApplicationScope;
import io.metersphere.sdk.constants.KafkaTopicConstants;
import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO;
import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.dto.queue.ExecutionQueueDetail;
import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import jakarta.annotation.Resource;
@ -18,17 +21,28 @@ public class MessageListener {
@Resource
private ApiReportSendNoticeService apiReportSendNoticeService;
@Resource
private ApiEventSource apiEventSource;
@Resource
private ApiExecutionQueueService apiExecutionQueueService;
@KafkaListener(id = MESSAGE_CONSUME_ID, topics = KafkaTopicConstants.API_REPORT_TASK_TOPIC, groupId = MESSAGE_CONSUME_ID)
public void messageConsume(ConsumerRecord<?, String> record) {
try {
if (apiReportSendNoticeService == null) {
apiReportSendNoticeService = CommonBeanFactory.getBean(ApiReportSendNoticeService.class);
}
LogUtils.info("接收到发送通知信息:", record.key());
if (ObjectUtils.isNotEmpty(record.value())) {
ApiNoticeDTO dto = JSON.parseObject(record.value(), ApiNoticeDTO.class);
apiReportSendNoticeService.sendNotice(dto);
// TODO 通知测试计划处理后续
LogUtils.info("发送通知给测试计划:", record.key());
apiEventSource.fireEvent(ApplicationScope.API_TEST, record.value());
// TODO 串行触发下次执行
ExecutionQueueDetail detail = apiExecutionQueueService.getNextDetail(dto.getQueueId());
// TODO 调用执行方法
}
} catch (Exception e) {
LogUtils.error("接收到发送通知信息:", e);

View File

@ -4,11 +4,11 @@ import io.metersphere.sdk.constants.ApiExecuteResourceType;
import io.metersphere.sdk.constants.KafkaTopicConstants;
import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO;
import io.metersphere.sdk.util.JSON;
import jakarta.annotation.Resource;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.mockito.InjectMocks;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
@ -19,7 +19,7 @@ import java.util.ArrayList;
@AutoConfigureMockMvc
public class MessageListenerTest {
@InjectMocks
@Resource
private MessageListener messageListener;
@Test