This is an automated email from the ASF dual-hosted git repository.
crazyhzm pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 78a8276 Fill ListBoolMatch code and optimize code for
DubboAttachmentMatch (#8448)
78a8276 is described below
commit 78a82760f26104946e0d1106751c9e94ab17e478
Author: 灼华 <[email protected]>
AuthorDate: Sun Oct 17 22:22:26 2021 +0800
Fill ListBoolMatch code and optimize code for DubboAttachmentMatch (#8448)
* Fill ListBoolMatch code and optimize code for DubboAttachmentMatch
* Modify method name
---
.../virtualservice/match/DubboAttachmentMatch.java | 26 +++++------
.../rule/virtualservice/match/ListBoolMatch.java | 22 ++++++++++
.../virtualservice/match/ListBoolMatchTest.java | 51 ++++++++++++++++++++++
3 files changed, 83 insertions(+), 16 deletions(-)
diff --git
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboAttachmentMatch.java
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboAttachmentMatch.java
index b368e5b..dd9c56e 100644
---
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboAttachmentMatch.java
+++
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboAttachmentMatch.java
@@ -41,27 +41,22 @@ public class DubboAttachmentMatch {
}
public static boolean isMatch(DubboAttachmentMatch dubboAttachmentMatch,
Map<String, String> eagleeyeContext, Map<String, String> dubboContext) {
- if (dubboAttachmentMatch.getDubbocontext() != null) {
- for (Map.Entry<String, StringMatch> stringStringMatchEntry :
dubboAttachmentMatch.getDubbocontext().entrySet()) {
- String key = stringStringMatchEntry.getKey();
- StringMatch stringMatch = stringStringMatchEntry.getValue();
+ boolean result = isMatch(dubboAttachmentMatch.getDubbocontext(),
dubboContext);
- String dubboContextValue = dubboContext.get(key);
- if (dubboContextValue == null) {
- return false;
- }
- if (!StringMatch.isMatch(stringMatch, dubboContextValue)) {
- return false;
- }
- }
+ if (result) {
+ result = isMatch(dubboAttachmentMatch.getEagleeyecontext(),
eagleeyeContext);
}
- if (dubboAttachmentMatch.getEagleeyecontext() != null) {
- for (Map.Entry<String, StringMatch> stringStringMatchEntry :
dubboAttachmentMatch.getEagleeyecontext().entrySet()) {
+ return result;
+ }
+
+ private static boolean isMatch(Map<String, StringMatch> map, Map<String,
String> input) {
+ if (map != null) {
+ for (Map.Entry<String, StringMatch> stringStringMatchEntry :
map.entrySet()) {
String key = stringStringMatchEntry.getKey();
StringMatch stringMatch = stringStringMatchEntry.getValue();
- String eagleeyeContextValue = eagleeyeContext.get(key);
+ String eagleeyeContextValue = input.get(key);
if (eagleeyeContextValue == null) {
return false;
}
@@ -70,7 +65,6 @@ public class DubboAttachmentMatch {
}
}
}
-
return true;
}
}
diff --git
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/ListBoolMatch.java
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/ListBoolMatch.java
index 9418bdf..a426d29 100644
---
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/ListBoolMatch.java
+++
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/ListBoolMatch.java
@@ -18,5 +18,27 @@
package org.apache.dubbo.rpc.cluster.router.mesh.rule.virtualservice.match;
+import java.util.List;
+
public class ListBoolMatch {
+ private List<BoolMatch> oneof;
+
+ public List<BoolMatch> getOneof() {
+ return oneof;
+ }
+
+ public void setOneof(List<BoolMatch> oneof) {
+ this.oneof = oneof;
+ }
+
+ public static boolean isMatch(ListBoolMatch listBoolMatch, boolean input) {
+
+ for (BoolMatch boolMatch : listBoolMatch.getOneof()) {
+ if (BoolMatch.isMatch(boolMatch, input)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
+
diff --git
a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/ListBoolMatchTest.java
b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/ListBoolMatchTest.java
new file mode 100644
index 0000000..5f1e1d8
--- /dev/null
+++
b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/ListBoolMatchTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dubbo.rpc.cluster.router.mesh.rule.virtualservice.match;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+
+public class ListBoolMatchTest {
+
+ @Test
+ public void isMatch() {
+ ListBoolMatch listBoolMatch = new ListBoolMatch();
+ List<BoolMatch> oneof = new ArrayList<>();
+
+ BoolMatch boolMatch1 = new BoolMatch();
+ boolMatch1.setExact(true);
+ oneof.add(boolMatch1);
+ listBoolMatch.setOneof(oneof);
+
+ assertTrue(ListBoolMatch.isMatch(listBoolMatch, true));
+ assertFalse(ListBoolMatch.isMatch(listBoolMatch, false));
+
+ BoolMatch boolMatch2 = new BoolMatch();
+ boolMatch2.setExact(false);
+ oneof.add(boolMatch2);
+ listBoolMatch.setOneof(oneof);
+
+ assertTrue(ListBoolMatch.isMatch(listBoolMatch, false));
+ }
+}