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


##########
hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestModifyTableWhileMerging.java:
##########
@@ -98,8 +94,8 @@ public void test() throws Exception {
     long proc = executor.submitProcedure(mergeTableRegionsProcedure);
     UTIL.waitFor(3000000, () -> 
UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor()
       .isFinished(procModify));
-    Assert.assertEquals("Modify Table procedure should success!",
-      ProcedureProtos.ProcedureState.SUCCESS, modifyTableProcedure.getState());
+    assertEquals(modifyTableProcedure.getState(), 
ProcedureProtos.ProcedureState.SUCCESS,

Review Comment:
   `assertEquals` argument order is reversed for JUnit Jupiter. The first 
argument should be the expected value and the second the actual value; 
otherwise assertion failure output will be misleading.
   ```suggestion
       assertEquals(ProcedureProtos.ProcedureState.SUCCESS, 
modifyTableProcedure.getState(),
   ```



##########
hbase-common/src/test/java/org/apache/hadoop/hbase/TableNameTestExtension.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/**
+ * Returns a {@code TableName} based on currently running test method name.
+ */
+public class TableNameTestExtension implements BeforeEachCallback {
+
+  private TableName tableName;
+
+  /**
+   * Helper to handle parameterized method names. Unlike regular test methods, 
parameterized method
+   * names look like 'foo[x]'. This is problematic for tests that use this 
name for HBase tables.
+   * This helper strips out the parameter suffixes.
+   * @return current test method name with out parameterized suffixes.

Review Comment:
   Typo in Javadoc: "with out" should be "without" ("without parameterized 
suffixes").
   ```suggestion
      * @return current test method name without parameterized suffixes.
   ```



##########
hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestExceptionInAssignRegion.java:
##########
@@ -98,14 +95,14 @@ public void testExceptionInAssignRegion() {
     long prodId = procedureExecutor.submitProcedure(assignRegionProcedure);
     ProcedureTestingUtility.waitProcedure(procedureExecutor, prodId);
 
-    Assert.assertEquals("Should be two RS since other is aborted", 2,
-      UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size());
-    Assert.assertNull("RIT Map doesn't have correct value",
-      
getRegionServer(0).getRegionsInTransitionInRS().get(hri.getEncodedNameAsBytes()));
-    Assert.assertNull("RIT Map doesn't have correct value",
-      
getRegionServer(1).getRegionsInTransitionInRS().get(hri.getEncodedNameAsBytes()));
-    Assert.assertNull("RIT Map doesn't have correct value",
-      
getRegionServer(2).getRegionsInTransitionInRS().get(hri.getEncodedNameAsBytes()));
+    
assertEquals(UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size(), 2,

Review Comment:
   `assertEquals` argument order is reversed for JUnit Jupiter. Use 
`assertEquals(expected, actual, message)` so the failure diff reports the 
correct expected/actual values.
   ```suggestion
       assertEquals(2, 
UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size(),
   ```



##########
hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRogueRSAssignment.java:
##########
@@ -158,10 +153,10 @@ public void testReportRSWithWrongRegion() throws 
Exception {
 
     // sending fake request to master
     // TODO: replace YouAreDeadException with appropriate exception as and 
when necessary
-    exception.expect(ServiceException.class);
-    exception.expectCause(isA(YouAreDeadException.class));
-    RegionServerStatusProtos.RegionServerReportResponse response =
-      master.getMasterRpcServices().regionServerReport(null, request.build());
+    ServiceException exception = assertThrows(ServiceException.class,
+      () -> master.getMasterRpcServices().regionServerReport(null, 
request.build()));
+    org.hamcrest.MatcherAssert.assertThat((YouAreDeadException) 
exception.getCause(),
+      isA(YouAreDeadException.class));

Review Comment:
   Avoid casting `exception.getCause()` to `YouAreDeadException` before 
asserting its type. The cast can throw `ClassCastException` and obscure the 
real failure; assert against the raw cause (or use `assertInstanceOf`) instead.



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