-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The eigenvalues are recalculated through configuration (#125)
* feat: The eigenvalues are recalculated through configuration
- Loading branch information
1 parent
2df1a6e
commit 7ff3935
Showing
8 changed files
with
164 additions
and
9 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...orage-config/src/main/java/com/arextest/config/model/vo/QueryConfigOfCategoryRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.arextest.config.model.vo; | ||
|
||
import lombok.Data; | ||
|
||
import javax.validation.constraints.NotEmpty; | ||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* created by xinyuan_wang on 2023/12/4 | ||
*/ | ||
@Data | ||
public class QueryConfigOfCategoryRequest { | ||
|
||
@NotNull | ||
private String appId; | ||
|
||
private String operationName; | ||
|
||
private String categoryName; | ||
|
||
@NotEmpty | ||
private Boolean entryPoint; | ||
} |
22 changes: 22 additions & 0 deletions
22
...rage-config/src/main/java/com/arextest/config/model/vo/QueryConfigOfCategoryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.arextest.config.model.vo; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import lombok.Data; | ||
|
||
/** | ||
* created by xinyuan_wang on 2023/12/4 | ||
*/ | ||
@Data | ||
public class QueryConfigOfCategoryResponse { | ||
private QueryConfigOfCategory body; | ||
|
||
@Data | ||
public static class QueryConfigOfCategory { | ||
private String operationName; | ||
|
||
private Set<List<String>> exclusionList; | ||
|
||
private Set<String> ignoreNodeSet; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
arex-storage-web-api/src/main/java/com/arextest/storage/service/QueryConfigService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.arextest.storage.service; | ||
|
||
import com.arextest.common.cache.CacheProvider; | ||
import com.arextest.config.model.vo.QueryConfigOfCategoryResponse.QueryConfigOfCategory; | ||
import com.arextest.config.model.vo.QueryConfigOfCategoryRequest; | ||
import com.arextest.config.model.vo.QueryConfigOfCategoryResponse; | ||
import com.arextest.model.mock.Mocker; | ||
import com.arextest.storage.cache.CacheKeyUtils; | ||
import com.arextest.storage.client.HttpWepServiceApiClient; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.annotation.Resource; | ||
|
||
import static com.arextest.diff.utils.JacksonHelperUtil.objectMapper; | ||
|
||
/** | ||
* query config service | ||
* created by xinyuan_wang on 2023/11/5 | ||
*/ | ||
@Service | ||
@Slf4j | ||
public class QueryConfigService { | ||
private static final String CONFIG_PREFIX = "config_"; | ||
@Value("${arex.query.config.url}") | ||
private String queryConfigOfCategoryUrl; | ||
@Value("${arex.query.config.cache.expired.seconds:600}") | ||
private long cacheExpiredSeconds; | ||
@Resource | ||
private HttpWepServiceApiClient httpWepServiceApiClient; | ||
@Resource | ||
private CacheProvider redisCacheProvider; | ||
|
||
public QueryConfigOfCategory queryConfigOfCategory(Mocker mocker) { | ||
if (mocker.getCategoryType().isSkipComparison()) { | ||
return null; | ||
} | ||
String categoryName = mocker.getCategoryType().getName(); | ||
String appId = mocker.getAppId(); | ||
String operationName = mocker.getOperationName(); | ||
|
||
QueryConfigOfCategory configCache = getConfigCache(appId, categoryName, | ||
operationName); | ||
if (configCache != null) { | ||
return configCache; | ||
} | ||
|
||
QueryConfigOfCategoryRequest queryConfigOfCategoryRequest = new QueryConfigOfCategoryRequest(); | ||
queryConfigOfCategoryRequest.setCategoryName(categoryName); | ||
queryConfigOfCategoryRequest.setAppId(appId); | ||
queryConfigOfCategoryRequest.setEntryPoint(mocker.getCategoryType().isEntryPoint()); | ||
queryConfigOfCategoryRequest.setOperationName(operationName); | ||
QueryConfigOfCategoryResponse queryConfigOfCategoryResponse = | ||
httpWepServiceApiClient.jsonPost(queryConfigOfCategoryUrl, queryConfigOfCategoryRequest, QueryConfigOfCategoryResponse.class); | ||
if (queryConfigOfCategoryResponse != null && queryConfigOfCategoryResponse.getBody() != null) { | ||
putConfigCache(appId, categoryName, operationName, queryConfigOfCategoryResponse.getBody()); | ||
return queryConfigOfCategoryResponse.getBody(); | ||
} | ||
return null; | ||
} | ||
|
||
public boolean putConfigCache(String appId, String categoryName, String operationName, | ||
QueryConfigOfCategory response) { | ||
try { | ||
byte[] key = CacheKeyUtils.toUtf8Bytes(CONFIG_PREFIX + appId + categoryName + operationName); | ||
byte[] values = CacheKeyUtils.toUtf8Bytes(objectMapper.writeValueAsString(response)); | ||
redisCacheProvider.put(key, cacheExpiredSeconds, values); | ||
return true; | ||
} catch (Exception e) { | ||
LOGGER.error("putConfigCache failed!", e); | ||
return false; | ||
} | ||
} | ||
|
||
public QueryConfigOfCategory getConfigCache(String appId, String categoryName, String operationName) { | ||
try { | ||
byte[] key = CacheKeyUtils.toUtf8Bytes(CONFIG_PREFIX + appId + categoryName + operationName); | ||
byte[] values = redisCacheProvider.get(key); | ||
if (values == null) { | ||
return null; | ||
} | ||
return objectMapper.readValue(new String(values), QueryConfigOfCategory.class); | ||
} catch (Exception e) { | ||
LOGGER.error("getConfigCache failed!", e); | ||
return null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters