Skip to content

Commit 0db8158

Browse files
committed
rename
1 parent e6b66b6 commit 0db8158

File tree

10 files changed

+129
-129
lines changed

10 files changed

+129
-129
lines changed

polaris-common/polaris-model/src/main/java/com/tencent/polaris/api/utils/RuleUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static boolean matchStringValue(MatchStringType matchType, String actualV
9393
switch (matchType) {
9494
case EXACT: {
9595
if (useTrieNode && trieNodeFunction != null) {
96-
return ApiTrieUtil.checkSimple(trieNodeFunction.apply(matchValue), actualValue);
96+
return TrieUtil.checkSimpleApi(trieNodeFunction.apply(matchValue), actualValue);
9797
}
9898
return StringUtils.equalsIgnoreCase(actualValue, matchValue);
9999
}
@@ -104,15 +104,15 @@ public static boolean matchStringValue(MatchStringType matchType, String actualV
104104
}
105105
case NOT_EQUALS: {
106106
if (useTrieNode && trieNodeFunction != null) {
107-
return !ApiTrieUtil.checkSimple(trieNodeFunction.apply(matchValue), actualValue);
107+
return !TrieUtil.checkSimpleApi(trieNodeFunction.apply(matchValue), actualValue);
108108
}
109109
return !StringUtils.equalsIgnoreCase(actualValue, matchValue);
110110
}
111111
case IN: {
112112
String[] tokens = matchValue.split(",");
113113
for (String token : tokens) {
114114
if (useTrieNode && trieNodeFunction != null) {
115-
if (ApiTrieUtil.checkSimple(trieNodeFunction.apply(matchValue), actualValue)) {
115+
if (TrieUtil.checkSimpleApi(trieNodeFunction.apply(matchValue), actualValue)) {
116116
return true;
117117
}
118118
} else {
@@ -127,7 +127,7 @@ public static boolean matchStringValue(MatchStringType matchType, String actualV
127127
String[] tokens = matchValue.split(",");
128128
for (String token : tokens) {
129129
if (useTrieNode && trieNodeFunction != null) {
130-
if (ApiTrieUtil.checkSimple(trieNodeFunction.apply(matchValue), actualValue)) {
130+
if (TrieUtil.checkSimpleApi(trieNodeFunction.apply(matchValue), actualValue)) {
131131
return false;
132132
}
133133
} else {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@
2020
import com.tencent.polaris.api.pojo.HttpElement;
2121
import com.tencent.polaris.api.pojo.TrieNode;
2222

23-
public class ApiTrieUtil {
23+
public class TrieUtil {
2424

2525
/**
2626
* @param apiPath
2727
* @return TrieNode
2828
*/
29-
public static TrieNode<String> buildSimpleTrieNode(String apiPath) {
29+
public static TrieNode<String> buildSimpleApiTrieNode(String apiPath) {
3030
if (StringUtils.isEmpty(apiPath)) {
3131
return null;
3232
}
33-
return buildSimpleTrieNode(new String[]{apiPath});
33+
return buildSimpleApiTrieNode(new String[]{apiPath});
3434
}
3535

36-
public static TrieNode<String> buildSimpleTrieNode(String[] apiPathInfoList) {
36+
public static TrieNode<String> buildSimpleApiTrieNode(String[] apiPathInfoList) {
3737
if (apiPathInfoList.length == 0) {
3838
return null;
3939
}
@@ -72,7 +72,7 @@ public static TrieNode<String> buildSimpleTrieNode(String[] apiPathInfoList) {
7272
return root;
7373
}
7474

75-
public static boolean checkSimple(TrieNode<String> root, String apiPathInfo) {
75+
public static boolean checkSimpleApi(TrieNode<String> root, String apiPathInfo) {
7676
if (root == null) {
7777
return false;
7878
}

polaris-common/polaris-model/src/test/java/com/tencent/polaris/api/utils/ApiTrieUtilTest.java

Lines changed: 0 additions & 109 deletions
This file was deleted.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package com.tencent.polaris.api.utils;
19+
20+
import com.tencent.polaris.api.pojo.TrieNode;
21+
import org.junit.Test;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* Test for {@link TrieUtil}.
27+
*/
28+
public class TrieUtilTest {
29+
30+
@Test
31+
public void testCheckSimple() {
32+
TrieNode<String> rootWithMethod = TrieUtil.buildSimpleApiTrieNode("/echo/{param}-GET");
33+
TrieNode<String> rootWithoutMethod = TrieUtil.buildSimpleApiTrieNode("/echo/{param}-GET");
34+
assertThat(TrieUtil.checkSimpleApi(rootWithMethod, "/echo/test")).isTrue();
35+
assertThat(TrieUtil.checkSimpleApi(rootWithoutMethod, "/echo/test")).isTrue();
36+
assertThat(TrieUtil.checkSimpleApi(rootWithoutMethod, "/echoo/test")).isFalse();
37+
assertThat(TrieUtil.checkSimpleApi(rootWithoutMethod, "/echo/")).isFalse();
38+
assertThat(TrieUtil.checkSimpleApi(rootWithMethod, "/echo/test-GET")).isTrue();
39+
assertThat(TrieUtil.checkSimpleApi(rootWithoutMethod, "/echo/test-GET")).isTrue();
40+
assertThat(TrieUtil.checkSimpleApi(rootWithoutMethod, "/echo/test-POST")).isTrue();
41+
assertThat(TrieUtil.checkSimpleApi(rootWithoutMethod, "/echo/test-POST")).isTrue();
42+
assertThat(TrieUtil.checkSimpleApi(rootWithoutMethod, "/echoo/test-GET")).isFalse();
43+
assertThat(TrieUtil.checkSimpleApi(rootWithoutMethod, "/echo/-GET")).isFalse();
44+
}
45+
46+
@Test
47+
public void testCheckConfig() {
48+
TrieNode<String> root1 = TrieUtil.buildConfigTrieNode("provider.config");
49+
assertThat(TrieUtil.checkConfig(root1, "provider.config.test")).isTrue();
50+
assertThat(TrieUtil.checkConfig(root1, "provider.config.test.aaa")).isTrue();
51+
assertThat(TrieUtil.checkConfig(root1, "provider.config2.test")).isFalse();
52+
assertThat(TrieUtil.checkConfig(root1, "provider")).isFalse();
53+
assertThat(TrieUtil.checkConfig(root1, "provider.config")).isTrue();
54+
assertThat(TrieUtil.checkConfig(root1, "provider.config.nameList[1]")).isTrue();
55+
assertThat(TrieUtil.checkConfig(root1, null)).isFalse();
56+
57+
TrieNode<String> root2 = TrieUtil.buildConfigTrieNode("provider.conf");
58+
assertThat(TrieUtil.checkConfig(root2, "provider.conf.test")).isTrue();
59+
assertThat(TrieUtil.checkConfig(root2, "provider.conf.test.aaa")).isTrue();
60+
assertThat(TrieUtil.checkConfig(root2, "provider.config2.test")).isFalse();
61+
assertThat(TrieUtil.checkConfig(root2, "provider")).isFalse();
62+
assertThat(TrieUtil.checkConfig(root2, "provider.config")).isFalse();
63+
assertThat(TrieUtil.checkConfig(root2, "provider.conf")).isTrue();
64+
assertThat(TrieUtil.checkConfig(root2, "provider.conf.nameList[1]")).isTrue();
65+
66+
TrieNode<String> root3 = new TrieNode<>(TrieNode.ROOT_PATH);
67+
assertThat(TrieUtil.checkConfig(root3, "provider.config.test")).isFalse();
68+
}
69+
70+
@Test
71+
public void testCheckConfig2() {
72+
TrieNode<String> root1 = TrieUtil.buildConfigTrieNode("provider.config.list");
73+
assertThat(TrieUtil.checkConfig(root1, "provider.config.list[1]")).isTrue();
74+
assertThat(TrieUtil.checkConfig(root1, "provider.config.list[1].name")).isTrue();
75+
assertThat(TrieUtil.checkConfig(root1, "provider.config.name")).isFalse();
76+
77+
TrieNode<String> root2 = TrieUtil.buildConfigTrieNode("provider.config.map");
78+
assertThat(TrieUtil.checkConfig(root2, "provider.config.map.key1")).isTrue();
79+
assertThat(TrieUtil.checkConfig(root2, "provider.config.map.key2")).isTrue();
80+
assertThat(TrieUtil.checkConfig(root1, "provider.config.name")).isFalse();
81+
82+
TrieNode<String> root3 = new TrieNode<>(TrieNode.ROOT_PATH);
83+
assertThat(TrieUtil.checkConfig(root3, "provider.config.test")).isFalse();
84+
}
85+
86+
@Test
87+
public void testCheckConfigMergeRoot() {
88+
TrieNode<String> root = new TrieNode<>(TrieNode.ROOT_PATH);
89+
90+
TrieUtil.buildConfigTrieNode("provider.config", root);
91+
TrieUtil.buildConfigTrieNode("provider.conf", root);
92+
93+
assertThat(TrieUtil.checkConfig(root, "provider.config.test")).isTrue();
94+
assertThat(TrieUtil.checkConfig(root, "provider.config.test.aaa")).isTrue();
95+
assertThat(TrieUtil.checkConfig(root, "provider.config2.test")).isFalse();
96+
assertThat(TrieUtil.checkConfig(root, "provider")).isFalse();
97+
assertThat(TrieUtil.checkConfig(root, "provider.config")).isTrue();
98+
assertThat(TrieUtil.checkConfig(root, "provider.config.nameList[1]")).isTrue();
99+
100+
101+
assertThat(TrieUtil.checkConfig(root, "provider.conf.test")).isTrue();
102+
assertThat(TrieUtil.checkConfig(root, "provider.conf.test.aaa")).isTrue();
103+
assertThat(TrieUtil.checkConfig(root, "provider.config2.test")).isFalse();
104+
assertThat(TrieUtil.checkConfig(root, "provider")).isFalse();
105+
assertThat(TrieUtil.checkConfig(root, "provider.config")).isTrue();
106+
assertThat(TrieUtil.checkConfig(root, "provider.conf")).isTrue();
107+
assertThat(TrieUtil.checkConfig(root, "provider.conf.nameList[1]")).isTrue();
108+
}
109+
}

polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/cache/FlowCacheUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.tencent.polaris.api.plugin.cache;
1919

20-
import com.tencent.polaris.api.utils.ApiTrieUtil;
20+
import com.tencent.polaris.api.utils.TrieUtil;
2121
import com.tencent.polaris.specification.api.v1.model.ModelProto;
2222

2323
import static com.tencent.polaris.api.plugin.cache.CacheConstants.API_ID;
@@ -31,12 +31,12 @@ public static void saveApiTrie(ModelProto.MatchString matchString, FlowCache flo
3131
if (matchString != null && matchString.getType() != ModelProto.MatchString.MatchStringType.REGEX) {
3232
if (matchString.getType() == ModelProto.MatchString.MatchStringType.EXACT || matchString.getType() == ModelProto.MatchString.MatchStringType.NOT_EQUALS) {
3333
flowCache.loadPluginCacheObject(API_ID, matchString.getValue().getValue(),
34-
path -> ApiTrieUtil.buildSimpleTrieNode((String) path));
34+
path -> TrieUtil.buildSimpleApiTrieNode((String) path));
3535
} else if (matchString.getType() == ModelProto.MatchString.MatchStringType.IN || matchString.getType() == ModelProto.MatchString.MatchStringType.NOT_IN) {
3636
String[] apis = matchString.getValue().getValue().split(",");
3737
for (String api : apis) {
3838
flowCache.loadPluginCacheObject(API_ID, api,
39-
path -> ApiTrieUtil.buildSimpleTrieNode((String) path));
39+
path -> TrieUtil.buildSimpleApiTrieNode((String) path));
4040
}
4141
}
4242
}

polaris-plugins/polaris-plugins-auth/auth-block-allow-list/src/main/java/com/tencent/polaris/plugins/auth/blockallowlist/BlockAllowListAuthenticator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import com.tencent.polaris.api.plugin.compose.Extensions;
3030
import com.tencent.polaris.api.pojo.*;
3131
import com.tencent.polaris.api.rpc.RequestBaseEntity;
32-
import com.tencent.polaris.api.utils.ApiTrieUtil;
32+
import com.tencent.polaris.api.utils.TrieUtil;
3333
import com.tencent.polaris.api.utils.CollectionUtils;
3434
import com.tencent.polaris.api.utils.RuleUtils;
3535
import com.tencent.polaris.api.utils.StringUtils;
@@ -221,7 +221,7 @@ public void postContextInit(Extensions ctx) throws PolarisException {
221221
return null;
222222
}
223223
FlowCache flowCache = extensions.getFlowCache();
224-
return flowCache.loadPluginCacheObject(API_ID, key, path -> ApiTrieUtil.buildSimpleTrieNode((String) path));
224+
return flowCache.loadPluginCacheObject(API_ID, key, path -> TrieUtil.buildSimpleApiTrieNode((String) path));
225225
};
226226
}
227227

polaris-plugins/polaris-plugins-circuitbreaker/circuitbreaker-composite/src/main/java/com/tencent/polaris/plugins/circuitbreaker/composite/PolarisCircuitBreaker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import com.tencent.polaris.api.plugin.compose.Extensions;
3838
import com.tencent.polaris.api.plugin.detect.HealthChecker;
3939
import com.tencent.polaris.api.pojo.*;
40-
import com.tencent.polaris.api.utils.ApiTrieUtil;
40+
import com.tencent.polaris.api.utils.TrieUtil;
4141
import com.tencent.polaris.api.utils.CollectionUtils;
4242
import com.tencent.polaris.client.flow.DefaultServiceResourceProvider;
4343
import com.tencent.polaris.client.util.NamedThreadFactory;
@@ -348,7 +348,7 @@ public void init(InitContext ctx) throws PolarisException {
348348
return null;
349349
}
350350
FlowCache flowCache = extensions.getFlowCache();
351-
return flowCache.loadPluginCacheObject(API_ID, key, path -> ApiTrieUtil.buildSimpleTrieNode((String) path));
351+
return flowCache.loadPluginCacheObject(API_ID, key, path -> TrieUtil.buildSimpleApiTrieNode((String) path));
352352
};
353353
}
354354

polaris-plugins/polaris-plugins-circuitbreaker/circuitbreaker-composite/src/main/java/com/tencent/polaris/plugins/circuitbreaker/composite/ResourceCounters.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import com.tencent.polaris.api.pojo.*;
3535
import com.tencent.polaris.api.pojo.CircuitBreakerStatus.FallbackInfo;
3636
import com.tencent.polaris.api.pojo.CircuitBreakerStatus.Status;
37-
import com.tencent.polaris.api.utils.ApiTrieUtil;
37+
import com.tencent.polaris.api.utils.TrieUtil;
3838
import com.tencent.polaris.api.utils.CollectionUtils;
3939
import com.tencent.polaris.api.utils.StringUtils;
4040
import com.tencent.polaris.client.flow.BaseFlow;
@@ -113,7 +113,7 @@ public ResourceCounters(Resource resource, CircuitBreakerRule currentActiveRule,
113113
return null;
114114
}
115115
FlowCache flowCache = polarisCircuitBreaker.getExtensions().getFlowCache();
116-
return flowCache.loadPluginCacheObject(API_ID, key, path -> ApiTrieUtil.buildSimpleTrieNode((String) path));
116+
return flowCache.loadPluginCacheObject(API_ID, key, path -> TrieUtil.buildSimpleApiTrieNode((String) path));
117117
};
118118
circuitBreakerStatusReference
119119
.set(new CircuitBreakerStatus(currentActiveRule.getName(), Status.CLOSE, System.currentTimeMillis()));

polaris-plugins/polaris-plugins-router/router-rule/src/main/java/com/tencent/polaris/plugins/router/rule/RuleBasedRouter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private boolean matchSource(List<RoutingProto.Source> sources, Service sourceSer
155155

156156
matched = RuleUtils.matchMetadata(source.getMetadataMap(), trafficLabels, metadataContainerGroup, true,
157157
multiEnvRouterParamMap, globalVariablesConfig,
158-
key -> flowCache.loadPluginCacheObject(API_ID, key, path -> ApiTrieUtil.buildSimpleTrieNode((String) path)));
158+
key -> flowCache.loadPluginCacheObject(API_ID, key, path -> TrieUtil.buildSimpleApiTrieNode((String) path)));
159159
if (matched) {
160160
break;
161161
}

0 commit comments

Comments
 (0)