This is an automated email from the ASF dual-hosted git repository.
hefengen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 18b3ac1bf [type:refactor] refactor some trie ruler codes. (#4414)
18b3ac1bf is described below
commit 18b3ac1bfe19cbe26650e13d9cb1ad3ec1011a48
Author: DamonXue <[email protected]>
AuthorDate: Wed Mar 1 15:31:34 2023 +0800
[type:refactor] refactor some trie ruler codes. (#4414)
* refactor some trie ruler codes.
* resolve ci.
* merge upstream master.
* fix ci.
* fix ci.
* fix ci.
* add some spec match test.
* add some spec match test.
* add some spec match test + 1.
* fix.
---------
Co-authored-by: xiaoyu <[email protected]>
---
.../shenyu/plugin/base/AbstractShenyuPlugin.java | 3 +-
.../shenyu/plugin/base/cache/MatchDataCache.java | 7 -
.../apache/shenyu/plugin/base/trie/ShenyuTrie.java | 74 +++++++----
.../plugin/base/trie/ShenyuTrieRuleListener.java | 13 +-
.../shenyu/plugin/base/trie/ShenyuTrieTest.java | 141 ++++++++++++++-------
.../web/controller/LocalPluginController.java | 9 +-
6 files changed, 152 insertions(+), 95 deletions(-)
diff --git
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/AbstractShenyuPlugin.java
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/AbstractShenyuPlugin.java
index 334d2715c..8d84659ab 100644
---
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/AbstractShenyuPlugin.java
+++
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/AbstractShenyuPlugin.java
@@ -234,9 +234,8 @@ public abstract class AbstractShenyuPlugin implements
ShenyuPlugin {
Pair<Boolean, RuleData> genericMatchRule = this.matchRule(exchange,
rules);
if (genericMatchRule.getLeft()) {
return genericMatchRule.getRight();
- } else {
- return null;
}
+ return null;
}
private Pair<Boolean, RuleData> matchRule(final ServerWebExchange
exchange, final Collection<RuleData> rules) {
diff --git
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MatchDataCache.java
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MatchDataCache.java
index e47a8709c..eafb2face 100644
---
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MatchDataCache.java
+++
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MatchDataCache.java
@@ -19,7 +19,6 @@ package org.apache.shenyu.plugin.base.cache;
import com.google.common.collect.Maps;
import org.apache.shenyu.common.cache.MemorySafeWindowTinyLFUMap;
-import org.apache.shenyu.common.dto.RuleData;
import org.apache.shenyu.common.dto.SelectorData;
import org.apache.shenyu.common.utils.MapUtils;
@@ -40,12 +39,6 @@ public final class MatchDataCache {
*/
private static final ConcurrentMap<String, Map<String, SelectorData>>
SELECTOR_DATA_MAP = Maps.newConcurrentMap();
- /**
- * plugin name -> LRU Map.
- * LRU Map: path -> rule data.
- */
- private static final ConcurrentMap<String, Map<String, RuleData>>
RULE_DATA_MAP = Maps.newConcurrentMap();
-
private MatchDataCache() {
}
diff --git
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java
index 08f84055e..9f4ff82f8 100644
---
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java
+++
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java
@@ -29,7 +29,6 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
-import java.util.stream.Collectors;
public class ShenyuTrie {
@@ -44,8 +43,6 @@ public class ShenyuTrie {
private final Long pathRuleCacheSize;
private final Long pathVariableSize;
-
- private final Object lock = new Object();
/**
* the mode includes antPathMatch and pathPattern, please see {@linkplain
TrieMatchModeEvent}.
@@ -82,6 +79,19 @@ public class ShenyuTrie {
&& Objects.isNull(this.root.getPathVariableNode());
}
+ /**
+ * put node to trie.
+ *
+ * @param uriPaths uri path
+ * @param ruleData rule data
+ * @param bizInfo biz info
+ */
+ public void putNode(final List<String> uriPaths, final RuleData ruleData,
final Object bizInfo) {
+ if (CollectionUtils.isNotEmpty(uriPaths)) {
+ uriPaths.forEach(path -> putNode(path, ruleData, bizInfo));
+ }
+ }
+
/**
* put node to trie.
*
@@ -109,10 +119,10 @@ public class ShenyuTrie {
List<RuleData> ruleDataList = getVal(node.getPathRuleCache(),
ruleData.getSelectorId());
if (CollectionUtils.isNotEmpty(ruleDataList)) {
// synchronized list
- synchronized (lock) {
+ synchronized (ruleData.getSelectorId()) {
ruleDataList.add(ruleData);
- final List<RuleData> collect =
ruleDataList.stream().sorted(Comparator.comparing(RuleData::getSort)).collect(Collectors.toList());
- node.getPathRuleCache().put(ruleData.getSelectorId(),
collect);
+
ruleDataList.sort(Comparator.comparing(RuleData::getSort));
+ node.getPathRuleCache().put(ruleData.getSelectorId(),
ruleDataList);
}
} else {
node.getPathRuleCache().put(ruleData.getSelectorId(),
Lists.newArrayList(ruleData));
@@ -155,7 +165,7 @@ public class ShenyuTrie {
}
}
// dynamic route
- if (segment.startsWith("{") && segment.endsWith("}")) {
+ if (isPathVariable(segment)) {
ShenyuTrieNode childNode;
// contains key, get current pathVariable node
if (containsKey(shenyuTrieNode.getPathVariablesSet(), segment)) {
@@ -223,12 +233,7 @@ public class ShenyuTrie {
continue;
}
// include path variable node, general node, wildcard
node
- if (endPath && checkPathRuleNotNull(currentNode)
- &&
CollectionUtils.isNotEmpty(getVal(currentNode.getPathRuleCache(), selectorId)))
{
- return currentNode;
- }
- // path is end and the match str is **, means match all
- if (isMatchAll(currentNode.getMatchStr()) &&
currentNode.getEndOfPath()
+ if ((endPath || (isMatchAll(currentNode.getMatchStr())
&& currentNode.getEndOfPath()))
&& checkPathRuleNotNull(currentNode)
&&
CollectionUtils.isNotEmpty(getVal(currentNode.getPathRuleCache(), selectorId)))
{
return currentNode;
@@ -253,14 +258,16 @@ public class ShenyuTrie {
private ShenyuTrieNode matchNode(final String segment, final
ShenyuTrieNode node) {
if (Objects.nonNull(node)) {
// node exist in children,first find path, avoid A plug have
/http/**, B plug have /http/order/**
- if (checkChildrenNotNull(node) && containsKey(node.getChildren(),
segment)) {
- return getVal(node.getChildren(), segment);
- }
- if (checkChildrenNotNull(node) && containsKey(node.getChildren(),
WILDCARD)) {
- return getVal(node.getChildren(), WILDCARD);
- }
- if (checkChildrenNotNull(node) && containsKey(node.getChildren(),
MATCH_ALL)) {
- return getVal(node.getChildren(), MATCH_ALL);
+ if (checkChildrenNotNull(node)) {
+ if (containsKey(node.getChildren(), segment)) {
+ return getVal(node.getChildren(), segment);
+ }
+ if (containsKey(node.getChildren(), WILDCARD)) {
+ return getVal(node.getChildren(), WILDCARD);
+ }
+ if (containsKey(node.getChildren(), MATCH_ALL)) {
+ return getVal(node.getChildren(), MATCH_ALL);
+ }
}
// if node is path variable node
if (Objects.nonNull(node.getPathVariableNode())) {
@@ -270,6 +277,23 @@ public class ShenyuTrie {
return null;
}
+ /**
+ * remove trie node.
+ * remove rules: query node of the current path, if the node exists,
+ * checks whether the current node is mapped to multiple plug-in rules.
+ * if the plug-in rules have only on mapping, remove the node from parent.
+ * if current node exists multi mappings, remove the mapping.
+ *
+ * @param paths paths
+ * @param selectorId selectorId
+ * @param ruleId ruleId
+ */
+ public void remove(final List<String> paths, final String selectorId,
final String ruleId) {
+ if (CollectionUtils.isNotEmpty(paths)) {
+ paths.forEach(path -> remove(path, selectorId, ruleId));
+ }
+ }
+
/**
* remove trie node.
* remove rules: query node of the current path, if the node exists,
@@ -303,7 +327,7 @@ public class ShenyuTrie {
// remove plugin mapping
List<RuleData> delRuleData =
getVal(currentNode.getPathRuleCache(), selectorId);
if (CollectionUtils.isNotEmpty(delRuleData)) {
- synchronized (lock) {
+ synchronized (selectorId) {
delRuleData.removeIf(rule ->
rule.getId().equals(ruleId));
}
}
@@ -327,9 +351,8 @@ public class ShenyuTrie {
} else {
return null;
}
- } else {
- return null;
}
+ return null;
}
/**
@@ -432,9 +455,8 @@ public class ShenyuTrie {
private static <V> V getVal(final Cache<String, V> cache, final String
key) {
if (Objects.nonNull(cache)) {
return cache.getIfPresent(key);
- } else {
- return null;
}
+ return null;
}
private static <V> void cleanup(final Cache<String, V> cache) {
diff --git
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrieRuleListener.java
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrieRuleListener.java
index 591688627..562445a67 100644
---
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrieRuleListener.java
+++
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrieRuleListener.java
@@ -49,22 +49,21 @@ public class ShenyuTrieRuleListener implements
ApplicationListener<RuleTrieEvent
final ShenyuTrie shenyuTrie =
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class);
switch (eventEnum) {
case INSERT:
- uriPaths.forEach(path -> shenyuTrie.putNode(path,
ruleData, null));
+ shenyuTrie.putNode(uriPaths, ruleData, ruleData.getId());
break;
case UPDATE:
final List<ConditionData> beforeConditionDataList =
ruleData.getBeforeConditionDataList();
- List<ConditionData> beforeFilterConditions =
beforeConditionDataList.stream()
+ List<String> beforeUriPaths =
beforeConditionDataList.stream()
.filter(conditionData ->
ParamTypeEnum.URI.getName().equals(conditionData.getParamType()))
+ .map(ConditionData::getParamValue)
.collect(Collectors.toList());
- List<String> beforeUriPaths =
beforeFilterConditions.stream().map(ConditionData::getParamValue).collect(Collectors.toList());
// old condition remove
- beforeUriPaths.forEach(path -> shenyuTrie.remove(path,
ruleData.getSelectorId(), ruleData.getId()));
- // new condition insert
- uriPaths.forEach(path -> shenyuTrie.putNode(path,
ruleData, null));
+ shenyuTrie.remove(beforeUriPaths,
ruleData.getSelectorId(), ruleData.getId());
+ shenyuTrie.putNode(uriPaths, ruleData, ruleData.getId());
break;
case REMOVE:
- uriPaths.forEach(path -> shenyuTrie.remove(path,
ruleData.getSelectorId(), ruleData.getId()));
+ shenyuTrie.remove(uriPaths, ruleData.getSelectorId(),
ruleData.getId());
break;
default:
throw new IllegalStateException("Unexpected value: " +
event.getRuleTrieEvent());
diff --git
a/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/trie/ShenyuTrieTest.java
b/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/trie/ShenyuTrieTest.java
index 7cf508b29..ad0a86a36 100644
---
a/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/trie/ShenyuTrieTest.java
+++
b/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/trie/ShenyuTrieTest.java
@@ -23,10 +23,13 @@ import org.apache.shenyu.common.enums.OperatorEnum;
import org.apache.shenyu.common.enums.ParamTypeEnum;
import org.apache.shenyu.common.enums.TrieMatchModeEvent;
import org.apache.shenyu.plugin.api.utils.SpringBeanUtils;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.ConfigurableApplicationContext;
+import java.util.Arrays;
import java.util.Collections;
import static org.mockito.Mockito.mock;
@@ -34,27 +37,30 @@ import static org.mockito.Mockito.when;
class ShenyuTrieTest {
- @Test
- public void clear() {
- this.mockAntPathShenyuTrie();
- SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).clear();
-
Assertions.assertTrue(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).isEmpty());
+ private ShenyuTrie shenyuTrie;
+
+ @BeforeEach
+ public void mockAntPathShenyuTrie() {
+ ConfigurableApplicationContext context =
mock(ConfigurableApplicationContext.class);
+ when(context.getBean(ShenyuTrie.class)).thenReturn(new
ShenyuTrie(100L, 100L, 100L, TrieMatchModeEvent.ANT_PATH_MATCH.getMatchMode()));
+ SpringBeanUtils.getInstance().setApplicationContext(context);
+ shenyuTrie = SpringBeanUtils.getInstance().getBean(ShenyuTrie.class);
}
- @Test
- public void isEmpty() {
- this.mockAntPathShenyuTrie();
-
Assertions.assertTrue(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).isEmpty());
+ @AfterEach
+ public void clear() {
+ shenyuTrie.clear();
+ Assertions.assertTrue(shenyuTrie.isEmpty());
}
@Test
public void putNode() {
- this.mockAntPathShenyuTrie();
+ final String uri = "/a/b/c/**";
ConditionData conditionData = new ConditionData();
conditionData.setParamType(ParamTypeEnum.URI.getName());
conditionData.setOperator(OperatorEnum.MATCH.getAlias());
conditionData.setParamName("/");
- conditionData.setParamValue("/a/b/c/**");
+ conditionData.setParamValue(uri);
RuleData ruleData = RuleData.builder()
.id("1")
.pluginName("test")
@@ -63,13 +69,12 @@ class ShenyuTrieTest {
.enabled(true)
.conditionDataList(Collections.singletonList(conditionData))
.build();
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("/a/b/c/**",
ruleData, null);
-
Assertions.assertNotNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class));
+ shenyuTrie.putNode(uri, ruleData, null);
+ Assertions.assertNotNull(shenyuTrie.getNode(uri));
}
@Test
public void match() {
- this.mockAntPathShenyuTrie();
ConditionData conditionData = new ConditionData();
conditionData.setParamType(ParamTypeEnum.URI.getName());
conditionData.setOperator(OperatorEnum.MATCH.getAlias());
@@ -83,8 +88,8 @@ class ShenyuTrieTest {
.enabled(true)
.conditionDataList(Collections.singletonList(conditionData))
.build();
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("/a/b/c/**",
ruleData, null);
-
Assertions.assertNotNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).match("/a/b/c/d/e/f",
"1"));
+ shenyuTrie.putNode("/a/b/c/**", ruleData, null);
+ Assertions.assertNotNull(shenyuTrie.match("/a/b/c/d/e/f", "1"));
RuleData ruleData2 = RuleData.builder()
.id("2")
@@ -94,22 +99,68 @@ class ShenyuTrieTest {
.enabled(true)
.conditionDataList(Collections.singletonList(conditionData))
.build();
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("/a/*/b/c",
ruleData2, null);
-
Assertions.assertNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).match("/a/m/b/c",
"1"));
-
Assertions.assertNotNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).match("/a/m/b/c",
"2"));
+ shenyuTrie.putNode("/a/*/b/c", ruleData2, null);
+ Assertions.assertNull(shenyuTrie.match("/a/m/b/c", "1"));
+ Assertions.assertNotNull(shenyuTrie.match("/a/m/b/c", "2"));
+
+ shenyuTrie.putNode("/path1/{name}/{age}", ruleData, null);
+ Assertions.assertNotNull(shenyuTrie.match("/path1/111/222",
"1").getFullPath(), "/path1/{name}/{age}");
+ Assertions.assertNull(shenyuTrie.match("/path1/111/222/333", "1"));
+
+ shenyuTrie.putNode("path1/name/age", ruleData, null);
+ Assertions.assertNotNull(shenyuTrie.match("path1/name/age", "1"));
+ Assertions.assertEquals(shenyuTrie.match("path1/name/age",
"1").getFullPath(), "path1/name/age");
+ }
+
+ @Test
+ public void matchSpec() {
+ final String uriPath = "/a/b/c/**";
+ final String uriPath1 = "/a/*/c/**";
+ final String uriPath2 = "/a/*/*/{d}";
+ final String uriPath3 = "/a/*/{c}/{d}";
+ ConditionData conditionData = new ConditionData();
+ conditionData.setParamType(ParamTypeEnum.URI.getName());
+ conditionData.setOperator(OperatorEnum.MATCH.getAlias());
+ conditionData.setParamName("/");
+ conditionData.setParamValue(uriPath);
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("/path1/{name}/{age}",
ruleData, null);
-
Assertions.assertNotNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).match("/path1/111/222",
"1"));
-
Assertions.assertNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).match("/path1/111/222/333",
"1"));
+ ConditionData conditionData1 = new ConditionData();
+ conditionData1.setParamType(ParamTypeEnum.URI.getName());
+ conditionData1.setOperator(OperatorEnum.MATCH.getAlias());
+ conditionData1.setParamName("/");
+ conditionData1.setParamValue(uriPath1);
+
+ ConditionData conditionData2 = new ConditionData();
+ conditionData2.setParamType(ParamTypeEnum.URI.getName());
+ conditionData2.setOperator(OperatorEnum.MATCH.getAlias());
+ conditionData2.setParamName("/");
+ conditionData2.setParamValue(uriPath2);
+
+ ConditionData conditionData3 = new ConditionData();
+ conditionData3.setParamType(ParamTypeEnum.URI.getName());
+ conditionData3.setOperator(OperatorEnum.MATCH.getAlias());
+ conditionData3.setParamName("/");
+ conditionData3.setParamValue(uriPath3);
+
+ RuleData ruleData = RuleData.builder()
+ .id("1")
+ .pluginName("test")
+ .selectorId("1")
+ .name("test-plugin-rule")
+ .enabled(true)
+ .conditionDataList(Arrays.asList(conditionData,
conditionData1, conditionData2, conditionData3))
+ .build();
+ shenyuTrie.putNode(Arrays.asList(uriPath, uriPath1, uriPath2,
uriPath3), ruleData, null);
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("path1/name/age",
ruleData, null);
-
Assertions.assertNotNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).match("path1/name/age",
"1"));
-
Assertions.assertEquals(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).match("path1/name/age",
"1").getFullPath(), "path1/name/age");
+ Assertions.assertEquals(shenyuTrie.match("/a/b/c/d/e/f",
"1").getFullPath(), uriPath);
+ Assertions.assertEquals(shenyuTrie.match("/a/g/c/e/ef/hi",
"1").getFullPath(), uriPath1);
+ Assertions.assertEquals(shenyuTrie.match("/a/g/hi/def",
"1").getFullPath(), uriPath2);
+ Assertions.assertEquals(shenyuTrie.match("/a/gh/ij/klm",
"1").getFullPath(), uriPath2);
+ Assertions.assertNotEquals(shenyuTrie.match("/a/egh/fij/klm",
"1").getFullPath(), uriPath3);
}
@Test
public void remove() {
- this.mockAntPathShenyuTrie();
ConditionData conditionData = new ConditionData();
conditionData.setParamType(ParamTypeEnum.URI.getName());
conditionData.setOperator(OperatorEnum.MATCH.getAlias());
@@ -133,10 +184,10 @@ class ShenyuTrieTest {
.sort(2)
.conditionDataList(Collections.singletonList(conditionData))
.build();
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("/a/b/c/**",
ruleData, null);
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("/a/b/c/**",
ruleData2, null);
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).remove("/a/b/c/**",
"2", "2");
-
Assertions.assertNotNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).getNode("/a/b/c/**"));
+ shenyuTrie.putNode("/a/b/c/**", ruleData, null);
+ shenyuTrie.putNode("/a/b/c/**", ruleData2, null);
+ shenyuTrie.remove("/a/b/c/**", "2", "2");
+ Assertions.assertNotNull(shenyuTrie.getNode("/a/b/c/**"));
RuleData ruleData3 = RuleData.builder()
.id("3")
@@ -147,14 +198,13 @@ class ShenyuTrieTest {
.sort(2)
.conditionDataList(Collections.singletonList(conditionData))
.build();
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("/path1/path2",
ruleData3, null);
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).remove("/path1/path2",
"3", "3");
-
Assertions.assertNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).getNode("/path1/path2"));
+ shenyuTrie.putNode("/path1/path2", ruleData3, null);
+ shenyuTrie.remove("/path1/path2", "3", "3");
+ Assertions.assertNull(shenyuTrie.getNode("/path1/path2"));
}
@Test
public void getNode() {
- this.mockAntPathShenyuTrie();
ConditionData conditionData = new ConditionData();
conditionData.setParamType(ParamTypeEnum.URI.getName());
conditionData.setOperator(OperatorEnum.MATCH.getAlias());
@@ -178,20 +228,15 @@ class ShenyuTrieTest {
.sort(2)
.conditionDataList(Collections.singletonList(conditionData))
.build();
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("/a/b/c/**",
ruleData, null);
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("/a/b/c/**",
ruleData2, null);
-
Assertions.assertNotNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).getNode("/a/b/c/**"));
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("/path1/{age}/{name}",
ruleData2, null);
-
Assertions.assertNotNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).getNode("/path1/{age}/{name}"));
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("/aaa/bbb/ccc",
ruleData2, null);
-
Assertions.assertNotNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).getNode("/aaa/bbb/ccc"));
-
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).putNode("/aa/*/cc",
ruleData2, null);
-
Assertions.assertNotNull(SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).getNode("/aa/*/cc"));
+ shenyuTrie.putNode("/a/b/c/**", ruleData, null);
+ shenyuTrie.putNode("/a/b/c/**", ruleData2, null);
+ Assertions.assertNotNull(shenyuTrie.getNode("/a/b/c/**"));
+ shenyuTrie.putNode("/path1/{age}/{name}", ruleData2, null);
+ Assertions.assertNotNull(shenyuTrie.getNode("/path1/{age}/{name}"));
+ shenyuTrie.putNode("/aaa/bbb/ccc", ruleData2, null);
+ Assertions.assertNotNull(shenyuTrie.getNode("/aaa/bbb/ccc"));
+ shenyuTrie.putNode("/aa/*/cc", ruleData2, null);
+ Assertions.assertNotNull(shenyuTrie.getNode("/aa/*/cc"));
}
- private void mockAntPathShenyuTrie() {
- ConfigurableApplicationContext context =
mock(ConfigurableApplicationContext.class);
- when(context.getBean(ShenyuTrie.class)).thenReturn(new
ShenyuTrie(100L, 100L, 100L, TrieMatchModeEvent.ANT_PATH_MATCH.getMatchMode()));
- SpringBeanUtils.getInstance().setApplicationContext(context);
- }
}
diff --git
a/shenyu-web/src/main/java/org/apache/shenyu/web/controller/LocalPluginController.java
b/shenyu-web/src/main/java/org/apache/shenyu/web/controller/LocalPluginController.java
index 6acf9a52d..5c823a172 100644
---
a/shenyu-web/src/main/java/org/apache/shenyu/web/controller/LocalPluginController.java
+++
b/shenyu-web/src/main/java/org/apache/shenyu/web/controller/LocalPluginController.java
@@ -100,9 +100,8 @@ public class LocalPluginController {
MatchDataCache.getInstance().removeSelectorData(name);
for (String selectorId : selectorIds) {
BaseDataCache.getInstance().removeRuleDataBySelectorId(selectorId);
- }
- selectorIds.forEach(item -> {
- List<RuleData> ruleDataList =
BaseDataCache.getInstance().obtainRuleData(item);
+
+ List<RuleData> ruleDataList =
BaseDataCache.getInstance().obtainRuleData(selectorId);
if (CollectionUtils.isNotEmpty(ruleDataList)) {
ruleDataList.forEach(rule -> {
List<ConditionData> conditionDataList =
rule.getConditionDataList();
@@ -111,11 +110,11 @@ public class LocalPluginController {
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(filterConditions)) {
List<String> uriPaths =
filterConditions.stream().map(ConditionData::getParamValue).collect(Collectors.toList());
- uriPaths.forEach(path ->
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).remove(path, item,
rule.getId()));
+ uriPaths.forEach(path ->
SpringBeanUtils.getInstance().getBean(ShenyuTrie.class).remove(path,
selectorId, rule.getId()));
}
});
}
- });
+ }
return Mono.just(Constants.SUCCESS);
}