From a612c51badf9bf63c8f62d98afd42ac41e671cc2 Mon Sep 17 00:00:00 2001
From: pangdayuan1 <116159079+pangdayuan1@users.noreply.github.com>
Date: Fri, 22 Mar 2024 20:22:03 +0800
Subject: [PATCH] feat: no data de-duplication if request with
arex-force-record (#187)
* feat: no data de-duplication if request with arex-force-record
---
arex-storage-config/pom.xml | 2 +-
arex-storage-model/pom.xml | 2 +-
.../model/constants/MockAttributeNames.java | 1 +
arex-storage-web-api/pom.xml | 2 +-
.../beans/StorageAutoConfiguration.java | 5 ++---
.../impl/DefaultMockResultProviderImpl.java | 2 --
.../scenepool/ScenePoolProviderImpl.java | 5 +++--
.../service/ScheduleReplayingService.java | 20 +++----------------
.../coverage/CoverageMockerHandler.java | 12 +++++++++++
pom.xml | 2 +-
10 files changed, 25 insertions(+), 28 deletions(-)
diff --git a/arex-storage-config/pom.xml b/arex-storage-config/pom.xml
index f8358844..c0439a9f 100644
--- a/arex-storage-config/pom.xml
+++ b/arex-storage-config/pom.xml
@@ -45,7 +45,7 @@
arex-storage-service
com.arextest
- 1.1.21
+ 1.1.22
diff --git a/arex-storage-model/pom.xml b/arex-storage-model/pom.xml
index d964b693..62ea49b9 100644
--- a/arex-storage-model/pom.xml
+++ b/arex-storage-model/pom.xml
@@ -7,7 +7,7 @@
arex-storage-service
com.arextest
- 1.1.21
+ 1.1.22
diff --git a/arex-storage-model/src/main/java/com/arextest/model/constants/MockAttributeNames.java b/arex-storage-model/src/main/java/com/arextest/model/constants/MockAttributeNames.java
index 916edcdd..19775eb8 100644
--- a/arex-storage-model/src/main/java/com/arextest/model/constants/MockAttributeNames.java
+++ b/arex-storage-model/src/main/java/com/arextest/model/constants/MockAttributeNames.java
@@ -24,6 +24,7 @@ public final class MockAttributeNames {
public static final String CONSUMER_GROUP_NAME = "consumerGroupName";
public static final String MESSAGE_ID = "messageId";
public static final String SUBJECT = "subject";
+ public static final String FORCE_RECORD = "arex-force-record";
private MockAttributeNames() {
}
diff --git a/arex-storage-web-api/pom.xml b/arex-storage-web-api/pom.xml
index 98664e14..c278e377 100644
--- a/arex-storage-web-api/pom.xml
+++ b/arex-storage-web-api/pom.xml
@@ -123,7 +123,7 @@
arex-storage-service
com.arextest
- 1.1.21
+ 1.1.22
diff --git a/arex-storage-web-api/src/main/java/com/arextest/storage/beans/StorageAutoConfiguration.java b/arex-storage-web-api/src/main/java/com/arextest/storage/beans/StorageAutoConfiguration.java
index 60c41e26..8247f3cf 100644
--- a/arex-storage-web-api/src/main/java/com/arextest/storage/beans/StorageAutoConfiguration.java
+++ b/arex-storage-web-api/src/main/java/com/arextest/storage/beans/StorageAutoConfiguration.java
@@ -184,10 +184,9 @@ public ScheduleReplayQueryController scheduleReplayQueryController(
@ConditionalOnMissingBean(ScheduleReplayingService.class)
public ScheduleReplayingService scheduleReplayingService(MockResultProvider mockResultProvider,
RepositoryProviderFactory repositoryProviderFactory,
- ApplicationOperationConfigurationRepositoryImpl serviceOperationRepository,
- ScenePoolService scenePoolService) {
+ ApplicationOperationConfigurationRepositoryImpl serviceOperationRepository) {
return new ScheduleReplayingService(mockResultProvider, repositoryProviderFactory,
- serviceOperationRepository, scenePoolService);
+ serviceOperationRepository);
}
@Bean
diff --git a/arex-storage-web-api/src/main/java/com/arextest/storage/mock/impl/DefaultMockResultProviderImpl.java b/arex-storage-web-api/src/main/java/com/arextest/storage/mock/impl/DefaultMockResultProviderImpl.java
index 3bc280b6..ba80da4b 100644
--- a/arex-storage-web-api/src/main/java/com/arextest/storage/mock/impl/DefaultMockResultProviderImpl.java
+++ b/arex-storage-web-api/src/main/java/com/arextest/storage/mock/impl/DefaultMockResultProviderImpl.java
@@ -245,7 +245,6 @@ public void calculateEigen(Mocker item, boolean queryConfig) {
}
String eigenBody = matchKeyFactory.getEigenBody(item);
if (StringUtils.isEmpty(eigenBody)) {
- LOGGER.warn("record eigen body is null");
return;
}
@@ -264,7 +263,6 @@ public void calculateEigen(Mocker item, boolean queryConfig) {
Map calculateEigen = EigenProcessor.calculateEigen(eigenBody,
item.getCategoryType().getName(), exclusions, ignoreNodes);
if (MapUtils.isEmpty(calculateEigen)) {
- LOGGER.warn("calculate eigen is null");
return;
}
item.setEigenMap(calculateEigen);
diff --git a/arex-storage-web-api/src/main/java/com/arextest/storage/repository/scenepool/ScenePoolProviderImpl.java b/arex-storage-web-api/src/main/java/com/arextest/storage/repository/scenepool/ScenePoolProviderImpl.java
index ad08410e..8eb215a0 100644
--- a/arex-storage-web-api/src/main/java/com/arextest/storage/repository/scenepool/ScenePoolProviderImpl.java
+++ b/arex-storage-web-api/src/main/java/com/arextest/storage/repository/scenepool/ScenePoolProviderImpl.java
@@ -51,14 +51,15 @@ public void upsertOne(Scene scene) {
private Bson getUpdate(Scene scene) {
Date expire = Date.from(LocalDateTime.now().plusDays(EXPIRATION_DAYS).atZone(ZoneId.systemDefault()).toInstant());
+ Date now = new Date();
return Updates.combine(
Updates.set(Fields.appId, scene.getAppId()),
Updates.set(Fields.sceneKey, scene.getSceneKey()),
Updates.set(Fields.recordId, scene.getRecordId()),
Updates.set(Fields.executionPath, scene.getExecutionPath()),
- Updates.setOnInsert(Fields.creationTime, new Date()),
- Updates.set(Fields.updateTime, new Date()),
+ Updates.setOnInsert(Fields.creationTime, now),
+ Updates.set(Fields.updateTime, now),
Updates.set(Fields.expirationTime, expire)
);
}
diff --git a/arex-storage-web-api/src/main/java/com/arextest/storage/service/ScheduleReplayingService.java b/arex-storage-web-api/src/main/java/com/arextest/storage/service/ScheduleReplayingService.java
index 53adf85c..e847ac11 100644
--- a/arex-storage-web-api/src/main/java/com/arextest/storage/service/ScheduleReplayingService.java
+++ b/arex-storage-web-api/src/main/java/com/arextest/storage/service/ScheduleReplayingService.java
@@ -18,7 +18,6 @@
import com.arextest.storage.trace.MDCTracer;
import com.arextest.storage.utils.JsonUtil;
import com.fasterxml.jackson.core.type.TypeReference;
-import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -28,7 +27,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@@ -52,16 +50,13 @@ public class ScheduleReplayingService {
private final MockResultProvider mockResultProvider;
private final RepositoryProviderFactory repositoryProviderFactory;
private final ConfigRepositoryProvider serviceOperationRepository;
- private final ScenePoolService scenePoolService;
public ScheduleReplayingService(MockResultProvider mockResultProvider,
RepositoryProviderFactory repositoryProviderFactory,
- ConfigRepositoryProvider serviceOperationRepository,
- ScenePoolService scenePoolService) {
+ ConfigRepositoryProvider serviceOperationRepository) {
this.mockResultProvider = mockResultProvider;
this.repositoryProviderFactory = repositoryProviderFactory;
this.serviceOperationRepository = serviceOperationRepository;
- this.scenePoolService = scenePoolService;
}
public List queryReplayResult(String recordId, String replayResultId) {
@@ -134,14 +129,13 @@ private List queryRecordListInner(ViewRecordRequestType requestType)
// request category list
Set mockCategoryTypes;
- boolean includeCoverage = false;
if (requestType.getCategoryTypes() == null) {
mockCategoryTypes = repositoryProviderFactory.getCategoryTypes();
} else {
mockCategoryTypes = new HashSet<>(requestType.getCategoryTypes().size());
for (String category : requestType.getCategoryTypes()) {
if (StringUtils.equals(category, MockCategoryType.COVERAGE.getName())) {
- includeCoverage = true;
+ mockCategoryTypes.add(MockCategoryType.COVERAGE);
continue;
}
MockCategoryType findCategory = repositoryProviderFactory.findCategory(category);
@@ -152,17 +146,9 @@ private List queryRecordListInner(ViewRecordRequestType requestType)
}
}
- List arexMockerList = mockCategoryTypes.stream()
+ return mockCategoryTypes.stream()
.flatMap(category -> queryRecordList(repositoryReader, category, recordId).stream())
.collect(Collectors.toList());
-
- if (includeCoverage) {
- AREXMocker coverageMocker = scenePoolService.getCoverageMocker(requestType.getRecordId());
- if (coverageMocker != null) {
- arexMockerList.add(coverageMocker);
- }
- }
- return arexMockerList;
}
private List splitMergedMockers(List mockerList) {
diff --git a/arex-storage-web-api/src/main/java/com/arextest/storage/service/mockerhandlers/coverage/CoverageMockerHandler.java b/arex-storage-web-api/src/main/java/com/arextest/storage/service/mockerhandlers/coverage/CoverageMockerHandler.java
index d7172ead..3cb105ca 100644
--- a/arex-storage-web-api/src/main/java/com/arextest/storage/service/mockerhandlers/coverage/CoverageMockerHandler.java
+++ b/arex-storage-web-api/src/main/java/com/arextest/storage/service/mockerhandlers/coverage/CoverageMockerHandler.java
@@ -1,5 +1,6 @@
package com.arextest.storage.service.mockerhandlers.coverage;
+import com.arextest.model.constants.MockAttributeNames;
import com.arextest.model.mock.MockCategoryType;
import com.arextest.model.mock.Mocker;
import com.arextest.model.mock.Mocker.Target;
@@ -61,6 +62,17 @@ public void handle(Mocker coverageMocker) {
coverageMocker.getRecordId());
return;
}
+
+ // force record data insert to coverage mocker
+ Target targetRequest = coverageMocker.getTargetRequest();
+ if (targetRequest != null &&
+ Boolean.parseBoolean(targetRequest.attributeAsString(MockAttributeNames.FORCE_RECORD))) {
+ mockSourceEditionService.add(ProviderNames.DEFAULT, coverageMocker);
+ LOGGER.info("CoverageMockerHandler received force record case, recordId: {}, pathKey: {}",
+ coverageMocker.getRecordId(), coverageMocker.getOperationName());
+ return;
+ }
+
// if replayId is empty, meaning this coverage mocker is received during record phase
if (StringUtils.isEmpty(coverageMocker.getReplayId()) && handlerSwitch.allowRecordTask(appId)) {
scenePoolProvider = scenePoolFactory.getProvider(ScenePoolFactory.RECORDING_SCENE_POOL);
diff --git a/pom.xml b/pom.xml
index d1d80059..32f128b8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -419,5 +419,5 @@
https://github.com/arextest/arex-storage
https://github.com/arextest/arex-storage
- 1.1.21
+ 1.1.22