feat(接口测试): 添加执行完成后通知测试计划处理相关状态及报告聚合
This commit is contained in:
parent
3a59afebfa
commit
28fc68f13d
|
@ -22,4 +22,5 @@ public class ApiNoticeDTO implements java.io.Serializable {
|
||||||
private String projectId;
|
private String projectId;
|
||||||
private List<String> environmentIds;
|
private List<String> environmentIds;
|
||||||
private String reportId;
|
private String reportId;
|
||||||
|
private String queueId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class TaskRequest implements Serializable {
|
||||||
private String kafkaConfig;
|
private String kafkaConfig;
|
||||||
private String minioConfig;
|
private String minioConfig;
|
||||||
private String poolId;
|
private String poolId;
|
||||||
|
private String queueId;
|
||||||
/**
|
/**
|
||||||
* 是否需要实时接收单个步骤的结果
|
* 是否需要实时接收单个步骤的结果
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package io.metersphere.api.listener;
|
package io.metersphere.api.listener;
|
||||||
|
|
||||||
|
import io.metersphere.api.event.ApiEventSource;
|
||||||
import io.metersphere.api.service.ApiReportSendNoticeService;
|
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.constants.KafkaTopicConstants;
|
||||||
import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO;
|
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.JSON;
|
||||||
import io.metersphere.sdk.util.LogUtils;
|
import io.metersphere.sdk.util.LogUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
@ -18,17 +21,28 @@ public class MessageListener {
|
||||||
@Resource
|
@Resource
|
||||||
private ApiReportSendNoticeService apiReportSendNoticeService;
|
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)
|
@KafkaListener(id = MESSAGE_CONSUME_ID, topics = KafkaTopicConstants.API_REPORT_TASK_TOPIC, groupId = MESSAGE_CONSUME_ID)
|
||||||
public void messageConsume(ConsumerRecord<?, String> record) {
|
public void messageConsume(ConsumerRecord<?, String> record) {
|
||||||
try {
|
try {
|
||||||
if (apiReportSendNoticeService == null) {
|
|
||||||
apiReportSendNoticeService = CommonBeanFactory.getBean(ApiReportSendNoticeService.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
LogUtils.info("接收到发送通知信息:", record.key());
|
LogUtils.info("接收到发送通知信息:", record.key());
|
||||||
if (ObjectUtils.isNotEmpty(record.value())) {
|
if (ObjectUtils.isNotEmpty(record.value())) {
|
||||||
ApiNoticeDTO dto = JSON.parseObject(record.value(), ApiNoticeDTO.class);
|
ApiNoticeDTO dto = JSON.parseObject(record.value(), ApiNoticeDTO.class);
|
||||||
apiReportSendNoticeService.sendNotice(dto);
|
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) {
|
} catch (Exception e) {
|
||||||
LogUtils.error("接收到发送通知信息:", e);
|
LogUtils.error("接收到发送通知信息:", e);
|
||||||
|
|
|
@ -4,11 +4,11 @@ import io.metersphere.sdk.constants.ApiExecuteResourceType;
|
||||||
import io.metersphere.sdk.constants.KafkaTopicConstants;
|
import io.metersphere.sdk.constants.KafkaTopicConstants;
|
||||||
import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO;
|
import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
import org.junit.jupiter.api.MethodOrderer;
|
import org.junit.jupiter.api.MethodOrderer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.mockito.InjectMocks;
|
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import java.util.ArrayList;
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
public class MessageListenerTest {
|
public class MessageListenerTest {
|
||||||
|
|
||||||
@InjectMocks
|
@Resource
|
||||||
private MessageListener messageListener;
|
private MessageListener messageListener;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue