Skip to content

Commit

Permalink
feat: no data de-duplication if request with arex-force-record (#187)
Browse files Browse the repository at this point in the history
* feat: no data de-duplication if request with arex-force-record
  • Loading branch information
pangdayuan1 authored Mar 22, 2024
1 parent 6265856 commit a612c51
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion arex-storage-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<parent>
<artifactId>arex-storage-service</artifactId>
<groupId>com.arextest</groupId>
<version>1.1.21</version>
<version>1.1.22</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion arex-storage-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>arex-storage-service</artifactId>
<groupId>com.arextest</groupId>
<version>1.1.21</version>
<version>1.1.22</version>
</parent>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down
2 changes: 1 addition & 1 deletion arex-storage-web-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<parent>
<artifactId>arex-storage-service</artifactId>
<groupId>com.arextest</groupId>
<version>1.1.21</version>
<version>1.1.22</version>
</parent>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -264,7 +263,6 @@ public void calculateEigen(Mocker item, boolean queryConfig) {
Map<Integer, Long> calculateEigen = EigenProcessor.calculateEigen(eigenBody,
item.getCategoryType().getName(), exclusions, ignoreNodes);
if (MapUtils.isEmpty(calculateEigen)) {
LOGGER.warn("calculate eigen is null");
return;
}
item.setEigenMap(calculateEigen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -52,16 +50,13 @@ public class ScheduleReplayingService {
private final MockResultProvider mockResultProvider;
private final RepositoryProviderFactory repositoryProviderFactory;
private final ConfigRepositoryProvider<ApplicationOperationConfiguration> serviceOperationRepository;
private final ScenePoolService scenePoolService;

public ScheduleReplayingService(MockResultProvider mockResultProvider,
RepositoryProviderFactory repositoryProviderFactory,
ConfigRepositoryProvider<ApplicationOperationConfiguration> serviceOperationRepository,
ScenePoolService scenePoolService) {
ConfigRepositoryProvider<ApplicationOperationConfiguration> serviceOperationRepository) {
this.mockResultProvider = mockResultProvider;
this.repositoryProviderFactory = repositoryProviderFactory;
this.serviceOperationRepository = serviceOperationRepository;
this.scenePoolService = scenePoolService;
}

public List<ListResultHolder> queryReplayResult(String recordId, String replayResultId) {
Expand Down Expand Up @@ -134,14 +129,13 @@ private List<AREXMocker> queryRecordListInner(ViewRecordRequestType requestType)

// request category list
Set<MockCategoryType> 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);
Expand All @@ -152,17 +146,9 @@ private List<AREXMocker> queryRecordListInner(ViewRecordRequestType requestType)
}
}

List<AREXMocker> 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<AREXMocker> splitMergedMockers(List<AREXMocker> mockerList) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -419,5 +419,5 @@
<url>https://github.com/arextest/arex-storage</url>
</scm>
<url>https://github.com/arextest/arex-storage</url>
<version>1.1.21</version>
<version>1.1.22</version>
</project>

0 comments on commit a612c51

Please sign in to comment.