This is an automated email from the ASF dual-hosted git repository.
likeguo 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 f36157ce3 [type:fix] plugn-dubbo-common fix selector update gray
remove cache(… (#4762)
f36157ce3 is described below
commit f36157ce300bfaba985c9cd77c5290277fa99ee1
Author: Kakk22 <[email protected]>
AuthorDate: Wed Jul 5 10:00:20 2023 +0800
[type:fix] plugn-dubbo-common fix selector update gray remove cache(…
(#4762)
* [type:fix] plugn-dubbo-common fix selector update gray remove
cache(#4665)
* test: checkstyle [4665]
---------
Co-authored-by: xiaoyu <[email protected]>
Co-authored-by: 陈一锋 <[email protected]>
---
.../common/handler/AbstractDubboPluginDataHandler.java | 3 +++
.../handler/AbstractDubboPluginDataHandlerTest.java | 17 +++++++++++++++++
2 files changed, 20 insertions(+)
diff --git
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandler.java
index d851bee0f..0e97b721a 100644
---
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandler.java
+++
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandler.java
@@ -87,6 +87,9 @@ public abstract class AbstractDubboPluginDataHandler
implements PluginDataHandle
if (CollectionUtils.isNotEmpty(graySelectorHandle)) {
SELECTOR_CACHED_HANDLE.get().cachedHandle(selectorData.getId(),
graySelectorHandle);
UpstreamCacheManager.getInstance().submit(selectorData.getId(),
convertUpstreamList(graySelectorHandle));
+ } else {
+ // if update gray selector is empty, remove cache
+ removeSelector(selectorData);
}
}
diff --git
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/test/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandlerTest.java
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/test/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandlerTest.java
index 86a9dd9a7..e9f04a234 100644
---
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/test/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandlerTest.java
+++
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/test/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandlerTest.java
@@ -31,6 +31,8 @@ import org.mockito.quality.Strictness;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
/**
* AbstractDubboPluginDataHandler test.
@@ -67,7 +69,22 @@ public class AbstractDubboPluginDataHandlerTest {
selectorData.setId("1");
selectorData.setHandle("[{\"appName\": \"name\", \"upstreamUrl\":
\"http://192.168.55.113/dubbo\", \"gray\":true}]");
handler.handlerSelector(selectorData);
+
assertEquals(AbstractDubboPluginDataHandler.SELECTOR_CACHED_HANDLE.get().obtainHandle("1").size(),
1);
+
+ selectorData.setHandle("[{\"appName\": \"name\", \"upstreamUrl\":
\"http://192.168.55.113/dubbo\", \"gray\":false}]");
+ handler.handlerSelector(selectorData);
+
assertNull(AbstractDubboPluginDataHandler.SELECTOR_CACHED_HANDLE.get().obtainHandle("1"));
+ // when gray update false
+ selectorData.setHandle("[{\"appName\": \"name\", \"upstreamUrl\":
\"http://192.168.55.113/dubbo\", \"gray\":true},{\"appName\": \"name\",
\"upstreamUrl\": \"http://192.168.55.114/dubbo\", \"gray\":true}]");
+ handler.handlerSelector(selectorData);
+
assertEquals(AbstractDubboPluginDataHandler.SELECTOR_CACHED_HANDLE.get().obtainHandle("1").size(),
2);
+
+ selectorData.setHandle("[{\"appName\": \"name\", \"upstreamUrl\":
\"http://192.168.55.113/dubbo\", \"gray\":true},{\"appName\": \"name\",
\"upstreamUrl\": \"http://192.168.55.114/dubbo\", \"gray\":false}]");
+ handler.handlerSelector(selectorData);
+
assertEquals(AbstractDubboPluginDataHandler.SELECTOR_CACHED_HANDLE.get().obtainHandle("1").size(),
1);
+
handler.removeSelector(selectorData);
+
assertNull(AbstractDubboPluginDataHandler.SELECTOR_CACHED_HANDLE.get().obtainHandle("1"));
}
@Test