Skip to content

Commit 6628de0

Browse files
committed
fix: map properties error
1 parent b367c39 commit 6628de0

File tree

10 files changed

+43
-17
lines changed

10 files changed

+43
-17
lines changed

arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public class ArexMocker implements Mocker {
3535
public ArexMocker() {
3636
}
3737

38-
public ArexMocker(MockCategoryType categoryType) {
38+
public ArexMocker(MockCategoryType categoryType, Map<String, String> arexMockerTags) {
3939
this.categoryType = categoryType;
4040
this.appId = System.getProperty(ConfigConstants.SERVICE_NAME);
4141
this.recordVersion = System.getProperty(ConfigConstants.AGENT_VERSION);
42-
this.tags = (Map<String, String>) System.getProperties().getOrDefault(ConfigConstants.MOCKER_TAGS, Collections.emptyMap());
42+
this.tags = arexMockerTags == null ? Collections.emptyMap() : arexMockerTags;
4343
}
4444

4545
/**

arex-instrumentation-api/src/main/java/io/arex/inst/runtime/config/Config.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static Config get() {
4747
private final String recordVersion;
4848
private final Set<String> includeServiceOperations;
4949
private final Set<String> coveragePackages = new ConcurrentHashSet<>();
50+
private Map<String, String> arexMockerTags;
5051

5152
Config(boolean enableDebug, String serviceName, List<DynamicClassEntity> dynamicClassList,
5253
Map<String, String> properties,
@@ -107,6 +108,14 @@ private void buildDynamicClassInfo() {
107108
this.dynamicAbstractClassList = list.toArray(StringUtil.EMPTY_STRING_ARRAY);
108109
}
109110

111+
public void setArexMockerTags(Map<String, String> arexMockerTags) {
112+
this.arexMockerTags = arexMockerTags;
113+
}
114+
115+
public Map<String, String> getArexMockerTags() {
116+
return arexMockerTags;
117+
}
118+
110119
public Set<String> getCoveragePackages() {
111120
return coveragePackages;
112121
}

arex-instrumentation-api/src/main/java/io/arex/inst/runtime/util/MockUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static ArexMocker createNettyProvider(String pattern) {
7777
}
7878

7979
public static ArexMocker create(MockCategoryType categoryType, String operationName) {
80-
ArexMocker mocker = new ArexMocker(categoryType);
80+
ArexMocker mocker = new ArexMocker(categoryType, Config.get().getArexMockerTags());
8181
long createTime = System.currentTimeMillis();
8282
ArexContext context = ContextManager.currentContext();
8383
if (context != null) {

arex-instrumentation-api/src/test/java/io/arex/inst/runtime/config/ConfigTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.arex.inst.runtime.model.ArexConstants;
88
import io.arex.inst.runtime.model.DynamicClassEntity;
99
import java.util.Arrays;
10+
import java.util.HashMap;
1011
import java.util.HashSet;
1112
import java.util.List;
1213

@@ -20,6 +21,7 @@
2021
import org.mockito.MockedStatic;
2122
import org.mockito.Mockito;
2223

24+
import java.util.Map;
2325
import java.util.function.Predicate;
2426
import java.util.stream.Stream;
2527

@@ -147,4 +149,16 @@ void buildCoveragePackages() {
147149
System.clearProperty(ArexConstants.SPRING_SCAN_PACKAGES);
148150

149151
}
152+
153+
@Test
154+
void arexMockerTags() {
155+
ConfigBuilder configBuilder = ConfigBuilder.create("mock");
156+
configBuilder.build();
157+
Config.get().setArexMockerTags(null);
158+
assertNull(Config.get().getArexMockerTags());
159+
Map<String, String> tags = new HashMap<>();
160+
tags.put("key1", "value1");
161+
Config.get().setArexMockerTags(tags);
162+
assertEquals("value1", Config.get().getArexMockerTags().get("key1"));
163+
}
150164
}

arex-instrumentation-api/src/test/java/io/arex/inst/runtime/match/ReplayMatcherTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void tearDown() {
3636

3737
@Test
3838
void match() {
39-
ArexMocker requestMocker = new ArexMocker(MockCategoryType.DYNAMIC_CLASS);
39+
ArexMocker requestMocker = new ArexMocker(MockCategoryType.DYNAMIC_CLASS, Collections.emptyMap());
4040
requestMocker.setOperationName("mock");
4141
requestMocker.setTargetRequest(new Mocker.Target());
4242
requestMocker.setTargetResponse(new Mocker.Target());
@@ -57,4 +57,4 @@ void match() {
5757
Mockito.when(MockUtils.methodRequestTypeHash(requestMocker)).thenReturn(2);
5858
assertNull(ReplayMatcher.match(requestMocker, MockStrategyEnum.FIND_LAST));
5959
}
60-
}
60+
}

arex-instrumentation-api/src/test/java/io/arex/inst/runtime/util/MergeRecordUtilTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void setUp() {
4949
Mockito.mockStatic(ContextManager.class);
5050
Mockito.mockStatic(Config.class);
5151
Mockito.when(Config.get()).thenReturn(Mockito.mock(Config.class));
52-
requestMocker = new ArexMocker(MockCategoryType.DYNAMIC_CLASS);
52+
requestMocker = new ArexMocker(MockCategoryType.DYNAMIC_CLASS, Collections.emptyMap());
5353
requestMocker.setOperationName("mock");
5454
requestMocker.setTargetRequest(new Mocker.Target());
5555
requestMocker.setTargetResponse(new Mocker.Target());
@@ -141,4 +141,4 @@ static Stream<Arguments> recordRemainCase() {
141141
arguments(contextSupplier2.get(), asserts2)
142142
);
143143
}
144-
}
144+
}

arex-instrumentation-api/src/test/java/io/arex/inst/runtime/util/MockUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void methodSignatureHash() {
199199

200200
@Test
201201
void methodRequestTypeHash() {
202-
ArexMocker mocker = new ArexMocker(MockCategoryType.DYNAMIC_CLASS);
202+
ArexMocker mocker = new ArexMocker(MockCategoryType.DYNAMIC_CLASS, Collections.emptyMap());
203203
mocker.setTargetRequest(new Mocker.Target());
204204
mocker.getTargetRequest().setBody("mock");
205205
assertTrue(MockUtils.methodRequestTypeHash(mocker) > 0);

arex-instrumentation-api/src/test/java/io/arex/inst/runtime/util/ReplayUtilTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static void setUp() {
3434
Mockito.mockStatic(ContextManager.class);
3535
Mockito.mockStatic(Config.class);
3636
Mockito.when(Config.get()).thenReturn(Mockito.mock(Config.class));
37-
requestMocker = new ArexMocker(MockCategoryType.DYNAMIC_CLASS);
37+
requestMocker = new ArexMocker(MockCategoryType.DYNAMIC_CLASS, Collections.emptyMap());
3838
requestMocker.setOperationName("mock");
3939
requestMocker.setTargetRequest(new Mocker.Target());
4040
requestMocker.setTargetResponse(new Mocker.Target());
@@ -56,15 +56,15 @@ void replayAllMocker(Runnable mocker) {
5656
}
5757

5858
static Stream<Arguments> replayAllMockerCase() {
59-
ArexMocker recordMocker1 = new ArexMocker(MockCategoryType.DYNAMIC_CLASS);
59+
ArexMocker recordMocker1 = new ArexMocker(MockCategoryType.DYNAMIC_CLASS, Collections.emptyMap());
6060
recordMocker1.setOperationName(ArexConstants.MERGE_RECORD_NAME);
6161
recordMocker1.setRecordId("mock");
6262
recordMocker1.setReplayId("mock");
6363
recordMocker1.setTargetRequest(new Mocker.Target());
6464
recordMocker1.setTargetResponse(new Mocker.Target());
6565
recordMocker1.getTargetResponse().setBody("mock");
6666
recordMocker1.setCreationTime(System.currentTimeMillis());
67-
ArexMocker recordMocker2 = new ArexMocker(MockCategoryType.DYNAMIC_CLASS);
67+
ArexMocker recordMocker2 = new ArexMocker(MockCategoryType.DYNAMIC_CLASS, Collections.emptyMap());
6868
recordMocker2.setOperationName(ArexConstants.MERGE_RECORD_NAME);
6969
recordMocker2.setRecordId("mock");
7070
recordMocker2.setReplayId("mock");
@@ -99,4 +99,4 @@ static Stream<Arguments> replayAllMockerCase() {
9999
arguments(mocker2)
100100
);
101101
}
102-
}
102+
}

arex-instrumentation-foundation/src/main/java/io/arex/foundation/services/ConfigService.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.arex.foundation.util.httpclient.AsyncHttpClientUtil;
1111
import io.arex.foundation.util.NetUtils;
1212
import io.arex.agent.bootstrap.util.StringUtil;
13+
import io.arex.inst.runtime.config.Config;
1314

1415
import java.util.Collections;
1516
import java.util.HashMap;
@@ -28,6 +29,7 @@ public class ConfigService {
2829

2930
private static final AgentLogger LOGGER = AgentLoggerFactory.getAgentLogger(ConfigService.class);
3031
private static final Map<String, String> TAGS_PROPERTIES = new HashMap<>();
32+
private static final Map<String, String> AREX_MOCKER_TAGS = new HashMap<>();
3133

3234
public static final ConfigService INSTANCE = new ConfigService();
3335
private static final String TAGS_PREFIX = "arex.tags.";
@@ -84,6 +86,7 @@ public void loadAgentConfig() {
8486
return;
8587
}
8688
ConfigManager.INSTANCE.updateConfigFromService(configResponse.getBody());
89+
Config.get().setArexMockerTags(Collections.unmodifiableMap(AREX_MOCKER_TAGS));
8790
} catch (Throwable e) {
8891
LOGGER.warn("[AREX] Load agent config error, pause recording. exception message: {}", e.getMessage(), e);
8992
ConfigManager.INSTANCE.setConfigInvalid();
@@ -129,24 +132,22 @@ AgentStatusEnum getAgentStatus() {
129132
public Map<String, String> getSystemProperties() {
130133
Properties properties = System.getProperties();
131134
Map<String, String> map = MapUtils.newHashMapWithExpectedSize(properties.size());
132-
Map<String, String> mockerTags = new HashMap<>();
133135
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
134136
String key = String.valueOf(entry.getKey());
135137
String value = String.valueOf(entry.getValue());
136138
map.put(key, value);
137-
buildTags(mockerTags, key, value);
139+
buildTags(key, value);
138140
}
139-
properties.put(ConfigConstants.MOCKER_TAGS, Collections.unmodifiableMap(mockerTags));
140141
return map;
141142
}
142143

143144
/**
144145
* ex: -Darex.tags.xxx=xxx
145146
*/
146-
private void buildTags(Map<String, String> mockerTags, String key, String value) {
147+
private void buildTags(String key, String value) {
147148
if (StringUtil.startWith(key, TAGS_PREFIX)) {
148149
TAGS_PROPERTIES.put(key, value);
149-
mockerTags.put(key.substring(TAGS_PREFIX.length()), value);
150+
AREX_MOCKER_TAGS.put(key.substring(TAGS_PREFIX.length()), value);
150151
}
151152
}
152153

arex-instrumentation/httpclient/arex-httpclient-feign/src/test/java/io/arex/inst/httpclient/feign/FeignClientInstrumentationTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import feign.Response;
77
import io.arex.agent.bootstrap.model.MockResult;
88
import io.arex.inst.httpclient.common.HttpClientExtractor;
9+
import io.arex.inst.runtime.config.ConfigBuilder;
910
import io.arex.inst.runtime.context.ContextManager;
1011
import io.arex.inst.runtime.context.RepeatedCollectManager;
1112
import io.arex.inst.runtime.util.IgnoreUtils;
@@ -24,6 +25,7 @@ static void setUp() {
2425
Mockito.mockStatic(IgnoreUtils.class);
2526
Mockito.mockStatic(ContextManager.class);
2627
Mockito.mockStatic(RepeatedCollectManager.class);
28+
ConfigBuilder.create("test").build();
2729
}
2830

2931
@AfterAll

0 commit comments

Comments
 (0)