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


##########
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionReconnect.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.client;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+import java.util.EnumSet;
+import java.util.stream.Stream;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.ClusterMetrics.Option;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.testclassification.ClientTests;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
+
+/**
+ * Test of that unmanaged HConnections are able to reconnect properly (see 
HBASE-5058)
+ */
+@Tag(MediumTests.TAG)
+@Tag(ClientTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: registryImpl={0}")
+public class TestConnectionReconnect {
+
+  private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
+
+  private static TableName NAME = TableName.valueOf("reconnect");
+
+  private Class<? extends ConnectionRegistry> registryImpl;
+
+  public TestConnectionReconnect(Class<? extends ConnectionRegistry> 
registryImpl) {
+    this.registryImpl = registryImpl;
+  }
+
+  @SuppressWarnings("deprecation")
+  public static Stream<Arguments> parameters() {
+    return Stream.of(Arguments.of(RpcConnectionRegistry.class),
+      Arguments.of(ZKConnectionRegistry.class));
+  }
+
+  @BeforeAll
+  public static void setUpBeforeAll() throws Exception {
+    UTIL.startMiniCluster(1);
+    UTIL.createTable(NAME, HConstants.CATALOG_FAMILY);
+    UTIL.waitTableAvailable(NAME);
+  }
+
+  public static void tearDownAfterAll() throws Exception {
+    UTIL.shutdownMiniCluster();
+  }

Review Comment:
   `tearDownAfterAll()` is missing an `@AfterAll` annotation, so the mini 
cluster will not be shut down after the test class finishes. This can leak 
resources and interfere with subsequent tests (ports, threads, etc.). Add 
`@AfterAll` on the method (and keep it `static`).



##########
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionReconnect.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.client;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+import java.util.EnumSet;
+import java.util.stream.Stream;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.ClusterMetrics.Option;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.testclassification.ClientTests;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
+
+/**
+ * Test of that unmanaged HConnections are able to reconnect properly (see 
HBASE-5058)
+ */
+@Tag(MediumTests.TAG)
+@Tag(ClientTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: registryImpl={0}")
+public class TestConnectionReconnect {
+
+  private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
+
+  private static TableName NAME = TableName.valueOf("reconnect");
+
+  private Class<? extends ConnectionRegistry> registryImpl;
+
+  public TestConnectionReconnect(Class<? extends ConnectionRegistry> 
registryImpl) {
+    this.registryImpl = registryImpl;
+  }
+
+  @SuppressWarnings("deprecation")
+  public static Stream<Arguments> parameters() {
+    return Stream.of(Arguments.of(RpcConnectionRegistry.class),
+      Arguments.of(ZKConnectionRegistry.class));
+  }
+
+  @BeforeAll
+  public static void setUpBeforeAll() throws Exception {
+    UTIL.startMiniCluster(1);
+    UTIL.createTable(NAME, HConstants.CATALOG_FAMILY);

Review Comment:
   `UTIL.createTable(NAME, ...)` returns a `Table` which should be closed to 
avoid leaking client resources. Wrap the call in try-with-resources (or 
explicitly close the returned `Table`) after creation.
   ```suggestion
       try (Table table = UTIL.createTable(NAME, HConstants.CATALOG_FAMILY)) {
       }
   ```



##########
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableScanMetrics.java:
##########
@@ -112,7 +113,7 @@ public static void setUp() throws Exception {
     NUM_REGIONS = TEST_UTIL.getHBaseCluster().getRegions(TABLE_NAME).size();
   }
 
-  @AfterClass
+  @AfterAll
   public static void tearDown() throws Exception {

Review Comment:
   `CONN` is created in `setUp()` but never closed. Relying on 
`shutdownMiniCluster()` to clean this up can leak threads/sockets and flake 
later tests. Close `CONN` in `@AfterAll tearDown()` (ideally before shutting 
down the mini cluster).
   ```suggestion
     public static void tearDown() throws Exception {
       if (CONN != null) {
         CONN.close();
         CONN = null;
       }
   ```



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