Copilot commented on code in PR #7397:
URL: https://github.com/apache/hbase/pull/7397#discussion_r2571984493


##########
hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestFiltersWithComparatorException.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.hadoop.hbase.filter;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CompareOperator;
+import org.apache.hadoop.hbase.HBaseIOException;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(SmallTests.class)
+public class TestFiltersWithComparatorException {
+
+  /**
+   * Tests that filters which take a ByteArrayComparable comparator handle 
runtime exceptions in the
+   * comparator layer, see HBASE-29672
+   */
+
+  byte[] cf = Bytes.toBytes("cf");
+  byte[] row = Bytes.toBytes("row1");
+  byte[] cq = Bytes.toBytes("q");
+  long ts = 12345L;
+  byte[] value = Bytes.toBytes("value");
+  Cell testCell = new KeyValue(row, cf, cq, ts, value);
+
+  @FunctionalInterface
+  interface FilterFunctionThrowable {
+    void run(Filter filter) throws IOException;
+  }
+
+  // Every filterX method that Filter implements to test
+  List<FilterFunctionThrowable> filterFunctionsToTest = Arrays.asList((Filter 
filter) -> {

Review Comment:
   [nitpick] The `filterFunctionsToTest` field should be declared as `final` 
since it's never reassigned. This makes the code more maintainable and clearly 
communicates intent.
   ```suggestion
     final List<FilterFunctionThrowable> filterFunctionsToTest = 
Arrays.asList((Filter filter) -> {
   ```



##########
hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestFiltersWithComparatorException.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.hadoop.hbase.filter;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CompareOperator;
+import org.apache.hadoop.hbase.HBaseIOException;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(SmallTests.class)
+public class TestFiltersWithComparatorException {
+
+  /**
+   * Tests that filters which take a ByteArrayComparable comparator handle 
runtime exceptions in the
+   * comparator layer, see HBASE-29672
+   */
+
+  byte[] cf = Bytes.toBytes("cf");
+  byte[] row = Bytes.toBytes("row1");
+  byte[] cq = Bytes.toBytes("q");
+  long ts = 12345L;
+  byte[] value = Bytes.toBytes("value");
+  Cell testCell = new KeyValue(row, cf, cq, ts, value);
+
+  @FunctionalInterface
+  interface FilterFunctionThrowable {
+    void run(Filter filter) throws IOException;
+  }
+
+  // Every filterX method that Filter implements to test
+  List<FilterFunctionThrowable> filterFunctionsToTest = Arrays.asList((Filter 
filter) -> {
+    filter.filterRowKey(testCell);
+  }, (Filter filter) -> {
+    filter.filterAllRemaining();
+  }, (Filter filter) -> {
+    filter.filterCell(testCell);
+  }, (Filter filter) -> {
+    filter.filterRowCells(new 
ArrayList<>(Collections.singletonList(testCell)));
+  }, (Filter filter) -> {
+    filter.filterRow();
+  });
+
+  /**
+   * Comparator which throws RuntimeException for every `compareTo` method that
+   * `ByteArrayComparable` implements + keeps a counter for number of 
compareTo invocations /
+   * RuntimeExceptions thrown
+   */
+  static class BadComparator extends ByteArrayComparable {
+
+    public int compareToInvocations = 0;

Review Comment:
   [nitpick] The field `compareToInvocations` should be private with a getter 
method to follow proper encapsulation practices. Making it public exposes the 
internal state unnecessarily.



##########
hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestFiltersWithComparatorException.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.hadoop.hbase.filter;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CompareOperator;
+import org.apache.hadoop.hbase.HBaseIOException;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(SmallTests.class)
+public class TestFiltersWithComparatorException {
+
+  /**
+   * Tests that filters which take a ByteArrayComparable comparator handle 
runtime exceptions in the
+   * comparator layer, see HBASE-29672
+   */
+
+  byte[] cf = Bytes.toBytes("cf");
+  byte[] row = Bytes.toBytes("row1");
+  byte[] cq = Bytes.toBytes("q");
+  long ts = 12345L;
+  byte[] value = Bytes.toBytes("value");
+  Cell testCell = new KeyValue(row, cf, cq, ts, value);

Review Comment:
   [nitpick] Test instance fields (cf, row, cq, ts, value, testCell) should be 
declared as `final` since they are never reassigned and are used in lambdas. 
This makes the code more maintainable and clearly communicates intent.
   ```suggestion
     final byte[] cf = Bytes.toBytes("cf");
     final byte[] row = Bytes.toBytes("row1");
     final byte[] cq = Bytes.toBytes("q");
     final long ts = 12345L;
     final byte[] value = Bytes.toBytes("value");
     final Cell testCell = new KeyValue(row, cf, cq, ts, value);
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to