From fb01646f2353dce81267b7c54f4f84062ff3ebb3 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 2 Aug 2023 18:15:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BF=AE=E6=94=B9=E5=85=AC?= =?UTF-8?q?=E5=85=B1=E8=A7=A6=E5=8F=91=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/metersphere/sdk/listener/Event.java | 16 +--------------- .../io/metersphere/sdk/listener/EventSource.java | 6 ++---- .../api/controller/EventSourceTests.java | 3 ++- .../plan/listener/ExecEventListener.java | 2 +- 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/listener/Event.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/listener/Event.java index ec340e472f..c6d934ffb6 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/listener/Event.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/listener/Event.java @@ -1,19 +1,5 @@ package io.metersphere.sdk.listener; -public class Event { - private String message; - private String module; +public record Event(String module, String message) { - public Event(String module, String message) { - this.module = module; - this.message = message; - } - - public String getMessage() { - return message; - } - - public String getModule() { - return module; - } } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/listener/EventSource.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/listener/EventSource.java index 90eae7532c..b40cd26aba 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/listener/EventSource.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/listener/EventSource.java @@ -2,14 +2,12 @@ package io.metersphere.sdk.listener; public interface EventSource { /** - * @param listener + * 注册监听 */ void addListener(EventListener listener); /** - * @param module - * @param message + * 触发事件 */ void fireEvent(String module, String message); - } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/EventSourceTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/EventSourceTests.java index 12f8cc0286..055d87166c 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/EventSourceTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/EventSourceTests.java @@ -24,10 +24,11 @@ public class EventSourceTests { // 注册所有监听源 LogUtils.info("初始化接口事件源"); APIEventSource apiEventSource = CommonBeanFactory.getBean(APIEventSource.class); + assert apiEventSource != null; apiEventSource.addListener(new EventListener() { @Override public void onEvent(Event event) { - LogUtils.info("ExecEventListener: " + event.getModule() + ":" + event.getMessage()); + LogUtils.info("ExecEventListener: " + event.module() + ":" + event.message()); } }); // 触发事件 diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/listener/ExecEventListener.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/listener/ExecEventListener.java index 0d2f480374..6d9cdb1109 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/listener/ExecEventListener.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/listener/ExecEventListener.java @@ -10,6 +10,6 @@ public class ExecEventListener implements EventListener { @Override public void onEvent(Event event) { // todo: 测试计划事件处理逻辑 - LogUtils.info("ExecEventListener: " + event.getModule() + ":" + event.getMessage()); + LogUtils.info("ExecEventListener: " + event.module() + ":" + event.message()); } }