Skip to content

feat: add unit test #592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f3b0f72
feat: batch save and query
lucas-myx May 15, 2024
df626c0
feat: optimize dataService init
lucas-myx May 15, 2024
c8c8039
feat: build match key
lucas-myx Jun 8, 2024
8d2ad76
feat: add compare module
lucas-myx Jun 9, 2024
e84d742
feat: add eigen calculate and match
lucas-myx Jun 23, 2024
014a485
feat: add compare module shade jackson
lucas-myx Jun 26, 2024
a03e6d7
feat: add sql parse switch
lucas-myx Jun 26, 2024
79651ed
feat: log compare call missing mocker
lucas-myx Jul 2, 2024
79715d3
feat: add eigen exclude config
lucas-myx Jul 15, 2024
9d9511a
feat: remove sql parse error log
lucas-myx Jul 23, 2024
b7d8a43
feat: modify ReplayCompareResultDTO field
lucas-myx Aug 5, 2024
b5a9805
feat: add http header arex-agent-version
lucas-myx Aug 5, 2024
2f0e331
feat: add database compare relation message
lucas-myx Aug 6, 2024
04708bc
refactor: QMQConsumer categoryType skip comparison
yanwuqiu Aug 12, 2024
92b596b
feat: new call record msg null
lucas-myx Aug 12, 2024
1dc80c0
feat: main entry message not calculate same
lucas-myx Aug 20, 2024
ceb1c7a
feat: log saveReplayCompareResult
lucas-myx Aug 20, 2024
342b20c
feat: add saveReplayCompareResult response log
lucas-myx Aug 20, 2024
3190b57
feat: update from main
lucas-myx Aug 22, 2024
85b0bce
feat: add context clear
lucas-myx Aug 27, 2024
e2328d6
feat: optimize sqlparse
lucas-myx Aug 28, 2024
e6a22b9
feat: replay match synchronize lock context
lucas-myx Aug 28, 2024
6c910ec
feat: add saveRemainCompareResult mdc log
lucas-myx Aug 28, 2024
fe62d91
feat: modify parse sql only on replay
lucas-myx Sep 23, 2024
3d52db7
feat: update from main
lucas-myx Oct 31, 2024
b9d1d51
feat: compatible fixed case
lucas-myx Nov 18, 2024
a7259a3
feat: add unit test
lucas-myx Dec 7, 2024
9570fd4
feat: exclude compare module for sonar
lucas-myx Dec 8, 2024
ff1c728
feat: fix sonar
lucas-myx Dec 8, 2024
d21182e
feat: fix sonar
lucas-myx Dec 9, 2024
87f417c
fix: the issue that the httpclient type fails to be built to match th…
pangdayuan1 Feb 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ public class ArexMocker implements Mocker {
private long creationTime;
private Mocker.Target targetRequest;
private Mocker.Target targetResponse;
private transient boolean needMerge;
private String operationName;
private Map<String, String> tags;
private transient boolean needMerge;
private final transient AtomicBoolean matched = new AtomicBoolean(false);
/**
* replay match need
*/
private transient int fuzzyMatchKey;
/**
* replay match need
*/
private transient int accurateMatchKey;
private transient Map<Integer, Long> eigenMap;
private Map<String, String> tags;

// original compressed text for request
private transient String request;
// original compressed text for response
private transient String response;

/**
* The default constructor is for deserialization
Expand Down Expand Up @@ -103,6 +103,7 @@ public String getOperationName() {
return this.operationName;
}


public void setId(String id) {
this.id = id;
}
Expand Down Expand Up @@ -178,4 +179,30 @@ public int getFuzzyMatchKey() {
public void setFuzzyMatchKey(int fuzzyMatchKey) {
this.fuzzyMatchKey = fuzzyMatchKey;
}

@Override
public Map<Integer, Long> getEigenMap() {
return eigenMap;
}

@Override
public void setEigenMap(Map<Integer, Long> eigenMap) {
this.eigenMap = eigenMap;
}

public String getRequest() {
return request;
}

public void setRequest(String request) {
this.request = request;
}

public String getResponse() {
return response;
}

public void setResponse(String response) {
this.response = response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MockCategoryType implements Serializable {
public static final MockCategoryType DYNAMIC_CLASS = createSkipComparison("DynamicClass");
public static final MockCategoryType REDIS = createSkipComparison("Redis");
public static final MockCategoryType MESSAGE_PRODUCER = createDependency("QMessageProducer");
public static final MockCategoryType MESSAGE_CONSUMER = createEntryPoint("QMessageConsumer");
public static final MockCategoryType MESSAGE_CONSUMER = create("QMessageConsumer",true,true);
public static final MockCategoryType DUBBO_CONSUMER = createDependency("DubboConsumer");
public static final MockCategoryType DUBBO_PROVIDER = createEntryPoint("DubboProvider");
public static final MockCategoryType DUBBO_STREAM_PROVIDER = createDependency("DubboStreamProvider");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

public interface Mocker extends Serializable {

void setAppId(String appId);

String getAppId();

String getReplayId();
Expand All @@ -33,10 +35,16 @@ public interface Mocker extends Serializable {

String getOperationName();

void setOperationName(String operationName);

Target getTargetRequest();

Target getTargetResponse();

void setTargetRequest(Target targetRequest);

void setTargetResponse(Target targetResponse);

public static class Target implements Serializable {

private String body;
Expand Down Expand Up @@ -132,4 +140,16 @@ default String replayLogTitle() {
int getFuzzyMatchKey();

void setFuzzyMatchKey(int fuzzyMatchKey);

Map<Integer, Long> getEigenMap();

void setEigenMap(Map<Integer, Long> eigenMap);

String getRequest();

void setRequest(String request);

String getResponse();

void setResponse(String response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ public static String[] splitByLastSeparator(String str, char separator) {
return new String[]{str.substring(0, index), str.substring(index + 1)};
}

public static int encodeAndHash(String str){
if (isBlank(str)) {
public static int encodeAndHash(String... str){
if (ArrayUtils.isEmpty(str)) {
return 0;
}
return Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8)).hashCode();
return Base64.getEncoder().encodeToString(String.join("_", str).getBytes(StandardCharsets.UTF_8)).hashCode();
}

public static String replace(final String text, final String searchString, final String replacement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private void initDependentComponents() {
initDataCollector();
}
private void initDataCollector() {
List<DataCollector> collectorList = ServiceLoader.load(DataCollector.class, getClassLoader());
List<DataCollector> collectorList = ServiceLoader.load(DataCollector.class, Thread.currentThread().getContextClassLoader());
DataService.setDataCollector(collectorList);
}

Expand Down
4 changes: 4 additions & 0 deletions arex-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>arex-third-party</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>arex-compare</artifactId>
</dependency>

<!--Agent instrumentation start-->
<dependency>
Expand Down
63 changes: 63 additions & 0 deletions arex-compare/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>arex-agent-parent</artifactId>
<groupId>io.arex</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>arex-compare</artifactId>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>arex-agent-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.fasterxml.jackson</pattern>
<shadedPattern>io.arex.shaded.com.fasterxml.jackson</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
<configuration>
<artifactSet>
<includes>
<include>com.fasterxml.jackson.core:**</include>
<include>io.arex:arex-compare</include>
</includes>
</artifactSet>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.arex.agent.compare.eigen;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.arex.agent.bootstrap.model.MockCategoryType;
import io.arex.agent.compare.handler.parse.JSONParse;
import io.arex.agent.compare.handler.parse.ObjectParse;
import io.arex.agent.compare.handler.parse.sqlparse.SqlParse;
import io.arex.agent.compare.model.RulesConfig;
import io.arex.agent.compare.model.eigen.EigenResult;

import java.util.Objects;

public class EigenCalculateHandler {
private static ObjectParse objectParse = new ObjectParse();
private static JSONParse jsonParse = new JSONParse();
private static SqlParse sqlParse = new SqlParse();

private static EigenMapCalculate eigenMapCalculate = new EigenMapCalculate();

public EigenResult doHandler(RulesConfig rulesConfig) {
Object obj;
try {
// if it is not json, it will return null
obj = objectParse.msgToObj(rulesConfig.getBaseMsg());

if (obj instanceof JsonNode) {
jsonParse.getJSONParseResult(obj, rulesConfig);
}

if (Objects.equals(rulesConfig.getCategoryType(), MockCategoryType.DATABASE.getName())
&& obj instanceof ObjectNode) {
sqlParse.sqlParse((ObjectNode) obj, rulesConfig.isNameToLower());
}
} catch (Throwable e) {
obj = null;
}

return eigenMapCalculate.doCalculate(obj, rulesConfig);
}
}
Loading