diff --git a/arex-storage-web-api/src/main/java/com/arextest/storage/service/handler/mocker/coverage/CoverageEventListener.java b/arex-storage-web-api/src/main/java/com/arextest/storage/service/handler/mocker/coverage/CoverageEventListener.java new file mode 100644 index 00000000..2bd2df59 --- /dev/null +++ b/arex-storage-web-api/src/main/java/com/arextest/storage/service/handler/mocker/coverage/CoverageEventListener.java @@ -0,0 +1,12 @@ +package com.arextest.storage.service.handler.mocker.coverage; + +import com.arextest.model.mock.Mocker; + +/** + * @author: QizhengMo + * @date: 2024/9/18 18:58 + */ +public interface CoverageEventListener { + void onNewCaseRecorded(Mocker coverageMocker); + void onExistingCaseRecorded(Mocker coverageMocker); +} diff --git a/arex-storage-web-api/src/main/java/com/arextest/storage/service/handler/mocker/coverage/CoverageMockerHandler.java b/arex-storage-web-api/src/main/java/com/arextest/storage/service/handler/mocker/coverage/CoverageMockerHandler.java index 46ef8f1b..70df0158 100644 --- a/arex-storage-web-api/src/main/java/com/arextest/storage/service/handler/mocker/coverage/CoverageMockerHandler.java +++ b/arex-storage-web-api/src/main/java/com/arextest/storage/service/handler/mocker/coverage/CoverageMockerHandler.java @@ -43,7 +43,9 @@ public class CoverageMockerHandler implements MockerHandler { private InvalidRecordService invalidRecordService; private DefaultApplicationConfig defaultApplicationConfig; private CacheProvider cacheProvider; - public final List metricListeners; + private final List metricListeners; + private final CoverageEventListener coverageEventListener; + // coverage metric constants private static final String METRIC_NAME_RECORD_COVERAGE = "coverage.recording"; private static final String METRIC_NAME_REPLAY_COVERAGE = "coverage.replay"; @@ -290,6 +292,8 @@ public void run() { mockSourceEditionService.removeByRecordId(ProviderNames.DEFAULT, coverageMocker.getRecordId()); LOGGER.info("{}CoverageMockerHandler received existing case, recordId: {}, pathKey: {}", TITLE_RECORD_TASK, coverageMocker.getRecordId(), coverageMocker.getOperationName()); + + coverageEventListener.onExistingCaseRecorded(coverageMocker); } else { op = NEW_SCENE_OP; // new scene: extend mocker expiration and insert scene @@ -301,6 +305,8 @@ public void run() { defaultApplicationConfig.getConfigAsLong(COVERAGE_EXPIRATION_DAYS_KEY, COVERAGE_EXPIRATION_DAYS)); LOGGER.info("{}CoverageMockerHandler received new case, recordId: {}, pathKey: {}", TITLE_RECORD_TASK, coverageMocker.getRecordId(), coverageMocker.getOperationName()); + + coverageEventListener.onNewCaseRecorded(coverageMocker); } recordCoverageHandle(appId, op, METRIC_NAME_RECORD_COVERAGE); diff --git a/arex-storage-web-api/src/main/java/com/arextest/storage/service/handler/mocker/coverage/DefaultCoverageEventListener.java b/arex-storage-web-api/src/main/java/com/arextest/storage/service/handler/mocker/coverage/DefaultCoverageEventListener.java new file mode 100644 index 00000000..7da5c989 --- /dev/null +++ b/arex-storage-web-api/src/main/java/com/arextest/storage/service/handler/mocker/coverage/DefaultCoverageEventListener.java @@ -0,0 +1,21 @@ +package com.arextest.storage.service.handler.mocker.coverage; + +import com.arextest.model.mock.Mocker; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.stereotype.Service; + +/** + * @author: QizhengMo + * @date: 2024/9/18 19:00 + */ +@Service +@ConditionalOnMissingBean(CoverageEventListener.class) +public class DefaultCoverageEventListener implements CoverageEventListener { + @Override + public void onNewCaseRecorded(Mocker coverageMocker) { + } + + @Override + public void onExistingCaseRecorded(Mocker coverageMocker) { + } +}