chore: 删除未使用的监听事件

This commit is contained in:
fit2-zhao 2024-09-10 16:09:39 +08:00 committed by Craftsman
parent ad7ed4a392
commit 34f98bbb80
8 changed files with 0 additions and 196 deletions

View File

@ -1,14 +1,11 @@
package io.metersphere.listener; package io.metersphere.listener;
import io.metersphere.api.event.ApiEventSource;
import io.metersphere.functional.domain.ExportTask; import io.metersphere.functional.domain.ExportTask;
import io.metersphere.functional.domain.ExportTaskExample; import io.metersphere.functional.domain.ExportTaskExample;
import io.metersphere.functional.mapper.ExportTaskMapper; import io.metersphere.functional.mapper.ExportTaskMapper;
import io.metersphere.plan.listener.ExecEventListener;
import io.metersphere.sdk.constants.StorageType; import io.metersphere.sdk.constants.StorageType;
import io.metersphere.sdk.file.FileCenter; import io.metersphere.sdk.file.FileCenter;
import io.metersphere.sdk.file.MinioRepository; import io.metersphere.sdk.file.MinioRepository;
import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.constants.ExportConstants; import io.metersphere.system.constants.ExportConstants;
import io.metersphere.system.service.BaseScheduleService; import io.metersphere.system.service.BaseScheduleService;
@ -53,21 +50,6 @@ public class AppStartListener implements ApplicationRunner {
ExportTask exportTask = new ExportTask(); ExportTask exportTask = new ExportTask();
exportTask.setState(ExportConstants.ExportState.STOP.name()); exportTask.setState(ExportConstants.ExportState.STOP.name());
exportTaskMapper.updateByExampleSelective(exportTask, exportTaskExample); exportTaskMapper.updateByExampleSelective(exportTask, exportTaskExample);
// 注册所有监听源
LogUtils.info("初始化接口事件源");
ApiEventSource apiEventSource = CommonBeanFactory.getBean(ApiEventSource.class);
LogUtils.info("初始化用例管理事件源");
//todo: 注册其他事件源
// 创建监听器对象并注册到多个事件源
ExecEventListener listener = CommonBeanFactory.getBean(ExecEventListener.class);
apiEventSource.addListener(listener);
//todo: 注册其他监听器
// 触发事件
apiEventSource.fireEvent("API", "Event after removing the listener test.");
// 加载插件 // 加载插件
pluginLoadService.loadPlugins(); pluginLoadService.loadPlugins();
} }

View File

@ -1,36 +0,0 @@
package io.metersphere.sdk.listener;
import lombok.Data;
import java.util.Map;
@Data
public class Event {
private String module;
private String message;
private Map<String, Object> paramMap;
public Event(String module, String message) {
this.module = module;
this.message = message;
}
public Event(String module, String message, Map<String, Object> paramMap) {
this.module = module;
this.message = message;
this.paramMap = paramMap;
}
public String module() {
return this.module;
}
public String message() {
return this.message;
}
public Map<String, Object> paramMap() {
return this.paramMap;
}
}

View File

@ -1,10 +0,0 @@
package io.metersphere.sdk.listener;
/**
* 监听所有执行结果
*
* @param <T>
*/
public interface EventListener<T> {
void onEvent(T event);
}

View File

@ -1,20 +0,0 @@
package io.metersphere.sdk.listener;
import java.util.Map;
public interface EventSource {
/**
* 注册监听
*/
void addListener(EventListener<Event> listener);
/**
* 触发事件
*/
void fireEvent(String module, String message);
/**
* 触发事件带有参数
*/
void fireEvent(String module, String message, Map<String, Object> paramMap);
}

View File

@ -1,33 +0,0 @@
package io.metersphere.api.event;
import io.metersphere.sdk.listener.Event;
import io.metersphere.sdk.listener.EventListener;
import io.metersphere.sdk.listener.EventSource;
import io.metersphere.sdk.util.LogUtils;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
public class ApiEventSource implements EventSource {
private EventListener<Event> listener;
@Override
public void addListener(EventListener<Event> listener) {
this.listener = listener;
}
@Override
public void fireEvent(String module, String message) {
Event event = new Event("API", message);
listener.onEvent(event);
}
@Override
public void fireEvent(String module, String message, Map<String, Object> paramMap) {
Event event = new Event("API", message, paramMap);
listener.onEvent(event);
LogUtils.info("带有参数的监听事件");
}
}

View File

@ -1,41 +0,0 @@
package io.metersphere.api.controller;
import io.metersphere.api.event.ApiEventSource;
import io.metersphere.sdk.listener.Event;
import io.metersphere.sdk.listener.EventListener;
import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.LogUtils;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.HashMap;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureMockMvc
public class EventSourceTests {
@Test
@Order(0)
public void eventSourceTest() throws Exception {
// 注册所有监听源
LogUtils.info("初始化接口事件源");
ApiEventSource apiEventSource = CommonBeanFactory.getBean(ApiEventSource.class);
assert apiEventSource != null;
apiEventSource.addListener(new EventListener<Event>() {
@Override
public void onEvent(Event event) {
LogUtils.info("ExecEventListener: " + event.module() + "" + event.message());
}
});
// 触发事件
apiEventSource.fireEvent("API", "Event after removing the listener test.");
// 触发事件待参数
apiEventSource.fireEvent("API", "Event after removing the listener test.",new HashMap<>());
}
}

View File

@ -1,15 +0,0 @@
package io.metersphere.plan.listener;
import io.metersphere.sdk.listener.Event;
import io.metersphere.sdk.listener.EventListener;
import io.metersphere.sdk.util.LogUtils;
import org.springframework.stereotype.Component;
@Component
public class ExecEventListener implements EventListener<Event> {
@Override
public void onEvent(Event event) {
// todo: 测试计划事件处理逻辑
LogUtils.info("ExecEventListener: " + event.module() + "" + event.message());
}
}

View File

@ -1,23 +0,0 @@
package io.metersphere.plan.controller;
import io.metersphere.plan.listener.ExecEventListener;
import io.metersphere.sdk.listener.Event;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureMockMvc
public class EventListenerTests {
@Test
@Order(0)
public void eventSourceTest() throws Exception {
new ExecEventListener().onEvent(new Event("TEST", "Event after removing the listener test."));
}
}