Copilot commented on code in PR #7366: URL: https://github.com/apache/hbase/pull/7366#discussion_r2410467954
########## hbase-common/src/test/java/org/apache/hadoop/hbase/JUnitResourceCheckers.java: ########## @@ -0,0 +1,141 @@ +/* + * 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 java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.hadoop.hbase.ResourceChecker.Phase; +import org.apache.hadoop.hbase.util.JVM; + +/** + * ResourceCheckers when running JUnit tests. + */ +public final class JUnitResourceCheckers { + + private JUnitResourceCheckers() { + } + + private static class ThreadResourceAnalyzer extends ResourceChecker.ResourceAnalyzer { + private static Set<String> initialThreadNames = new HashSet<>(); + private static List<String> stringsToLog = null; Review Comment: The static fields `initialThreadNames` and `stringsToLog` are not thread-safe and could cause race conditions when multiple tests run concurrently. Consider using thread-local variables or synchronization mechanisms. ```suggestion private Set<String> initialThreadNames = new HashSet<>(); private List<String> stringsToLog = null; ``` ########## hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseJupiterExtension.java: ########## @@ -60,14 +62,17 @@ * the tag. * <p> * It also controls the timeout for the whole test class running, while the timeout annotation in - * JUnit5 can only enforce the timeout for each test method. + * JUnit5 can only enforce the timeout for each test method. When a test is timed out, a thread dump + * will be printed to log output. * <p> - * Finally, it also forbid System.exit call in tests. TODO: need to find a new way as - * SecurityManager has been removed since Java 21. + * It also implements resource check for each test method, using the {@link ResourceChecker} class. + * <p> + * Finally, it also forbid System.exit call in tests. <br> + * TODO: need to find a new way as SecurityManager has been disabled since Java 24. Review Comment: Corrected version information - SecurityManager was deprecated in Java 17 and removed/disabled by default in Java 18, not Java 24. ```suggestion * TODO: need to find a new way as SecurityManager was deprecated in Java 17 and removed/disabled by default in Java 18. ``` -- 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]
