Skip to content

Commit

Permalink
feat: coverage event ext
Browse files Browse the repository at this point in the history
  • Loading branch information
QizhengMo committed Sep 18, 2024
1 parent 0912ac2 commit b567e59
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public class CoverageMockerHandler implements MockerHandler {
private InvalidRecordService invalidRecordService;
private DefaultApplicationConfig defaultApplicationConfig;
private CacheProvider cacheProvider;
public final List<MetricListener> metricListeners;
private final List<MetricListener> 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";
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
}
}

0 comments on commit b567e59

Please sign in to comment.