cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [cassandra] dcapwell commented on a change in pull request #428: CASSANDRA-15505
Date Thu, 23 Jan 2020 01:50:55 GMT
dcapwell commented on a change in pull request #428: CASSANDRA-15505 
URL: https://github.com/apache/cassandra/pull/428#discussion_r369898305
 
 

 ##########
 File path: test/distributed/org/apache/cassandra/distributed/impl/MessageFilters.java
 ##########
 @@ -86,65 +69,77 @@ public boolean equals(Object that)
 
         public boolean equals(Filter that)
         {
-            return Arrays.equals(from, that.from)
-                    && Arrays.equals(to, that.to)
-                    && Arrays.equals(verbs, that.verbs);
+            return that.matchers.equals(matchers);
         }
 
-        public boolean matches(int from, int to, int verb)
-        {
-            return (this.from == null || Arrays.binarySearch(this.from, from) >= 0)
-                    && (this.to == null || Arrays.binarySearch(this.to, to) >=
0)
-                    && (this.verbs == null || Arrays.binarySearch(this.verbs, verb)
>= 0);
-        }
-
-        public Filter restore()
+        public Filter off()
         {
             filters.remove(this);
             return this;
         }
 
-        public Filter drop()
+        public Filter on()
         {
             filters.add(this);
             return this;
         }
+
+        public boolean matches(int from, int to, IMessage message)
+        {
+            // Compose matchers using logical AND
+            for (IMatcher matcher : matchers)
+            {
+                if (!matcher.matches(from, to, message))
+                    return false;
+            }
+            return true;
+        }
     }
 
     public class Builder implements IMessageFilters.Builder
     {
-        int[] from;
-        int[] to;
-        int[] verbs;
+        final List<IMatcher> matchers;
+
+        private Builder(int... verbs)
+        {
+            this((from, to, msg) -> Arrays.binarySearch(verbs, msg.verb()) >= 0);
+        }
 
-        private Builder(int[] verbs)
+        private Builder(IMatcher matcher)
         {
-            this.verbs = verbs;
+            this.matchers = new ArrayList<>(2);
+            this.matchers.add(matcher);
         }
 
         public Builder from(int ... nums)
         {
-            from = nums;
+            this.matchers.add((from, to, msg) -> Arrays.binarySearch(nums, from) >=
0);
 
 Review comment:
   this assumes the input is sorted, but the test case is what calls this; its very possible
that the test defined them in non-sorted order

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Mime
View raw message