This is an automated email from the ASF dual-hosted git repository.
Apache9 pushed a commit to branch branch-3
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-3 by this push:
new 33f54ee614b HBASE-30200 Cleanup all junit4 references in hbase code
base (#8320)
33f54ee614b is described below
commit 33f54ee614bb762cc64d2664c2591e277be66c58
Author: Duo Zhang <[email protected]>
AuthorDate: Mon Jun 8 10:38:37 2026 +0800
HBASE-30200 Cleanup all junit4 references in hbase code base (#8320)
(cherry picked from commit adc1b9a326c4f8729ec025062c9f0745ce87156f)
Signed-off-by: Xiao Liu <[email protected]>
---
hbase-assembly/pom.xml | 5 -
hbase-asyncfs/pom.xml | 5 +
.../apache/hadoop/hbase/backup/BackupTestUtil.java | 2 +-
.../TestIncrementalBackupMergeWithBulkLoad.java | 6 +-
...ochasticLoadBalancerRegionReplicaSameHosts.java | 4 +-
hbase-common/pom.xml | 5 -
.../org/apache/hadoop/hbase/ClassTestFinder.java | 53 ++---
.../apache/hadoop/hbase/HBaseClassTestRule.java | 168 --------------
.../hadoop/hbase/HBaseClassTestRuleChecker.java | 66 ------
.../apache/hadoop/hbase/HBaseJupiterExtension.java | 2 +-
.../hadoop/hbase/ResourceCheckerJUnitListener.java | 77 -------
.../org/apache/hadoop/hbase/SystemExitRule.java | 56 -----
.../org/apache/hadoop/hbase/TableNameTestRule.java | 59 -----
.../hbase/TestBuildThreadDiagnosticString.java | 2 +-
.../hadoop/hbase/TestHBaseClassTestRule.java | 150 ------------
.../apache/hadoop/hbase/TestSecurityManager.java | 8 +-
.../apache/hadoop/hbase/TestSystemExitInTest.java | 36 ---
...ner.java => TimedOutTestsThreadDumpHelper.java} | 32 +--
.../apache/hadoop/hbase/logging/TestJul2Slf4j.java | 1 -
.../hadoop/hbase/logging/TestLog4jUtils.java | 1 -
hbase-common/src/test/java/org/junit/Assert.java | 255 +++++++++++++++++++++
.../zstd/TestZstdDictionarySplitMerge.java | 27 ++-
hbase-dev-generate-classpath/pom.xml | 5 -
.../hadoop/hbase/coprocessor/TestSecureExport.java | 3 +-
.../row/stats/TestRowStatisticsEventHandler.java | 8 +-
hbase-it/pom.xml | 5 +
.../hbase/IntegrationTestDDLMasterFailover.java | 55 +++--
.../IntegrationTestRegionReplicaReplication.java | 13 +-
.../hadoop/hbase/IntegrationTestsDriver.java | 35 ++-
.../StripeCompactionsPerformanceEvaluation.java | 5 +-
.../actions/UnbalanceKillAndRebalanceAction.java | 7 +-
.../IntegrationTestTableSnapshotInputFormat.java | 12 +-
hbase-mapreduce/pom.xml | 5 +
hbase-rest/pom.xml | 5 +
.../hbase/rest/model/TestColumnSchemaModel.java | 11 +-
hbase-server/pom.xml | 5 -
.../hbase/ClearUserNamespacesAndTablesRule.java | 152 ------------
.../org/apache/hadoop/hbase/ConnectionRule.java | 136 -----------
.../org/apache/hadoop/hbase/MiniClusterRule.java | 158 -------------
.../apache/hadoop/hbase/TestCheckTestClasses.java | 62 -----
.../client/TestRegionLocatorPagedScanRpcCount.java | 36 ++-
.../io/hfile/bucket/TestBucketCacheRefCnt.java | 3 +-
.../org/apache/hadoop/hbase/ipc/QosTestBase.java | 6 +-
.../hadoop/hbase/mob/MobStressToolRunner.java | 4 +-
.../AbstractTestDateTieredCompactionPolicy.java | 2 +-
.../hadoop/hbase/trace/OpenTelemetryClassRule.java | 126 ----------
.../hadoop/hbase/trace/OpenTelemetryTestRule.java | 39 ----
.../hadoop/hbase/util/HFileArchiveTestingUtil.java | 8 +-
.../apache/hadoop/hbase/util/HFileTestUtil.java | 6 +-
.../hadoop/hbase/util/TestServerHttpUtils.java | 2 +-
.../hadoop/hbase/util/hbck/HbckTestingUtil.java | 2 +-
hbase-shaded/hbase-shaded-check-invariants/pom.xml | 5 -
.../hbase-shaded-testing-util-tester/pom.xml | 5 -
.../shaded/TestShadedHBaseTestingUtility.java | 24 +-
.../pom.xml | 5 -
.../hbase/thrift/TestThriftHttpServerBase.java | 22 +-
.../thrift2/TestThriftHBaseServiceHandler.java | 3 +-
pom.xml | 50 ++--
58 files changed, 490 insertions(+), 1560 deletions(-)
diff --git a/hbase-assembly/pom.xml b/hbase-assembly/pom.xml
index 7d5a1bf8c71..dcd81ebf260 100644
--- a/hbase-assembly/pom.xml
+++ b/hbase-assembly/pom.xml
@@ -408,11 +408,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>compile</scope>
</dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>compile</scope>
- </dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
diff --git a/hbase-asyncfs/pom.xml b/hbase-asyncfs/pom.xml
index ef501e3f29d..f149dec3bd2 100644
--- a/hbase-asyncfs/pom.xml
+++ b/hbase-asyncfs/pom.xml
@@ -83,6 +83,11 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
diff --git
a/hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/BackupTestUtil.java
b/hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/BackupTestUtil.java
index 3665eeb7a76..5d49ed574d5 100644
---
a/hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/BackupTestUtil.java
+++
b/hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/BackupTestUtil.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.backup;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
diff --git
a/hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestIncrementalBackupMergeWithBulkLoad.java
b/hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestIncrementalBackupMergeWithBulkLoad.java
index 4d4076f28c0..702ecbb5a3b 100644
---
a/hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestIncrementalBackupMergeWithBulkLoad.java
+++
b/hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestIncrementalBackupMergeWithBulkLoad.java
@@ -22,9 +22,9 @@ import static
org.apache.hadoop.hbase.backup.BackupTestUtil.enableBackup;
import static org.apache.hadoop.hbase.backup.BackupTestUtil.verifyBackup;
import static org.apache.hadoop.hbase.backup.BackupType.FULL;
import static org.apache.hadoop.hbase.backup.BackupType.INCREMENTAL;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.nio.ByteBuffer;
diff --git
a/hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerRegionReplicaSameHosts.java
b/hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerRegionReplicaSameHosts.java
index 0e1e8a1e52c..648346d8bee 100644
---
a/hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerRegionReplicaSameHosts.java
+++
b/hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerRegionReplicaSameHosts.java
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hbase.master.balancer;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -34,8 +35,7 @@ public class TestStochasticLoadBalancerRegionReplicaSameHosts
extends Stochastic
@Test
public void testRegionReplicationOnMidClusterSameHosts() {
- conf.setLong(StochasticLoadBalancer.MAX_STEPS_KEY, 2000000L);
- loadBalancer.onConfigurationChange(conf);
+ setMaxRunTime(Duration.ofSeconds(10));
int numHosts = 30;
int numRegions = 30 * 30;
int replication = 3; // 3 replicas per region
diff --git a/hbase-common/pom.xml b/hbase-common/pom.xml
index ea58c0327c7..e357efc0332 100644
--- a/hbase-common/pom.xml
+++ b/hbase-common/pom.xml
@@ -125,11 +125,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java
index dc51187e3cf..998b1fa4eb0 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java
@@ -22,9 +22,7 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
-import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
-import org.junit.runners.Suite;
/**
* ClassFinder that is pre-configured with filters that will only allow test
classes. The name is
@@ -36,26 +34,24 @@ public class ClassTestFinder extends ClassFinder {
super(new TestFileNameFilter(), new TestFileNameFilter(), new
TestClassFilter());
}
- public ClassTestFinder(Class<?> category) {
- super(new TestFileNameFilter(), new TestFileNameFilter(), new
TestClassFilter(category));
+ public ClassTestFinder(Class<?> tag) {
+ super(new TestFileNameFilter(), new TestFileNameFilter(), new
TestClassFilter(tag));
}
- public static Class<?>[] getCategoryAnnotations(Class<?> c) {
- Category category = c.getAnnotation(Category.class);
- if (category != null) {
- return category.value();
- }
- return new Class<?>[0];
- }
-
- public static String[] getTagAnnotations(Class<?> c) {
+ public static Class<?>[] getTagAnnotations(Class<?> c) {
// TODO handle optional Tags annotation
Tag[] tags = c.getAnnotationsByType(Tag.class);
- List<String> values = new ArrayList<>();
- for (Tag tag : tags) {
- values.add(tag.value());
+ List<Class<?>> values = new ArrayList<>();
+ if (tags != null) {
+ for (Tag tag : tags) {
+ try {
+ values.add(Class.forName(tag.value()));
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
- return values.toArray(new String[values.size()]);
+ return values.toArray(new Class<?>[values.size()]);
}
/** Filters both test classes and anything in the hadoop-compat modules */
@@ -79,10 +75,10 @@ public class ClassTestFinder extends ClassFinder {
* is annotated with org.junit.Test OR - the class is annotated with
Suite.SuiteClasses
*/
public static class TestClassFilter implements ClassFilter {
- private Class<?> categoryAnnotation = null;
+ private Class<?> tagAnnotation = null;
public TestClassFilter(Class<?> categoryAnnotation) {
- this.categoryAnnotation = categoryAnnotation;
+ this.tagAnnotation = categoryAnnotation;
}
public TestClassFilter() {
@@ -91,7 +87,7 @@ public class ClassTestFinder extends ClassFinder {
@Override
public boolean isCandidateClass(Class<?> c) {
- return isTestClass(c) && isCategorizedClass(c);
+ return isTestClass(c) && isTagedClass(c);
}
private boolean isTestClass(Class<?> c) {
@@ -99,15 +95,8 @@ public class ClassTestFinder extends ClassFinder {
return false;
}
- if (c.getAnnotation(Suite.SuiteClasses.class) != null) {
- return true;
- }
-
for (Method met : c.getMethods()) {
- if (
- met.getAnnotation(org.junit.Test.class) != null
- || met.getAnnotation(org.junit.jupiter.api.Test.class) != null
- ) {
+ if (met.getAnnotation(org.junit.jupiter.api.Test.class) != null) {
return true;
}
}
@@ -115,12 +104,12 @@ public class ClassTestFinder extends ClassFinder {
return false;
}
- private boolean isCategorizedClass(Class<?> c) {
- if (this.categoryAnnotation == null) {
+ private boolean isTagedClass(Class<?> c) {
+ if (this.tagAnnotation == null) {
return true;
}
- for (Class<?> cc : getCategoryAnnotations(c)) {
- if (cc.equals(this.categoryAnnotation)) {
+ for (Class<?> cc : getTagAnnotations(c)) {
+ if (cc.equals(this.tagAnnotation)) {
return true;
}
}
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRule.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRule.java
deleted file mode 100644
index 73f5442b6a7..00000000000
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRule.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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 edu.umd.cs.findbugs.annotations.NonNull;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-import org.apache.hadoop.hbase.testclassification.IntegrationTests;
-import org.apache.hadoop.hbase.testclassification.LargeTests;
-import org.apache.hadoop.hbase.testclassification.MediumTests;
-import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.apache.yetus.audience.InterfaceAudience;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestRule;
-import org.junit.rules.Timeout;
-import org.junit.runner.Description;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-import org.junit.runners.model.Statement;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;
-import org.apache.hbase.thirdparty.com.google.common.collect.Sets;
-
-/**
- * The class level TestRule for all the tests. Every test class should have a
{@code ClassRule} with
- * it.
- * <p>
- * For now it only sets a test method timeout based off the test categories
small, medium, large.
- * Based on junit Timeout TestRule; see
https://github.com/junit-team/junit/wiki/Rules
- */
[email protected]
-public final class HBaseClassTestRule implements TestRule {
- private static final Logger LOG =
LoggerFactory.getLogger(HBaseClassTestRule.class);
- public static final Set<Class<?>> UNIT_TEST_CLASSES =
Collections.unmodifiableSet(
- Sets.<Class<?>> newHashSet(SmallTests.class, MediumTests.class,
LargeTests.class));
-
- // Each unit test has this timeout.
- private static long PER_UNIT_TEST_TIMEOUT_MINS = 13;
-
- private final Class<?> clazz;
-
- private final Timeout timeout;
-
- private final SystemExitRule systemExitRule = new SystemExitRule();
-
- private HBaseClassTestRule(Class<?> clazz, Timeout timeout) {
- this.clazz = clazz;
- this.timeout = timeout;
- }
-
- /**
- * Mainly used for {@link HBaseClassTestRuleChecker} to confirm that we use
the correct class to
- * generate timeout ClassRule.
- */
- public Class<?> getClazz() {
- return clazz;
- }
-
- private static long getTimeoutInSeconds(Class<?> clazz) {
- Category[] categories = clazz.getAnnotationsByType(Category.class);
- // Starting JUnit 4.13, it appears that the timeout is applied across all
the parameterized
- // runs. So the timeout is multiplied by number of parameterized runs.
- int numParams = getNumParameters(clazz);
- // @Category is not repeatable -- it is only possible to get an array of
length zero or one.
- if (categories.length == 1) {
- for (Class<?> c : categories[0].value()) {
- if (UNIT_TEST_CLASSES.contains(c)) {
- long timeout = numParams * PER_UNIT_TEST_TIMEOUT_MINS;
- LOG.info("Test {} timeout: {} mins", clazz, timeout);
- return TimeUnit.MINUTES.toSeconds(timeout);
- }
- if (c == IntegrationTests.class) {
- return TimeUnit.MINUTES.toSeconds(Long.MAX_VALUE);
- }
- }
- }
- throw new IllegalArgumentException(
- clazz.getName() + " does not have SmallTests/MediumTests/LargeTests in
@Category");
- }
-
- /**
- * @param clazz Test class that is running.
- * @return the number of parameters for this given test class. If the test
is not parameterized or
- * if there is any issue determining the number of parameters,
returns 1.
- */
- static int getNumParameters(Class<?> clazz) {
- RunWith[] runWiths = clazz.getAnnotationsByType(RunWith.class);
- boolean testParameterized = runWiths != null
- && Arrays.stream(runWiths).anyMatch((r) ->
r.value().equals(Parameterized.class));
- if (!testParameterized) {
- return 1;
- }
- for (Method method : clazz.getMethods()) {
- if (!isParametersMethod(method)) {
- continue;
- }
- // Found the parameters method. Figure out the number of parameters.
- Object parameters;
- try {
- parameters = method.invoke(clazz);
- } catch (IllegalAccessException | InvocationTargetException e) {
- LOG.warn("Error invoking parameters method {} in test class {}",
method.getName(), clazz,
- e);
- continue;
- }
- if (parameters instanceof List) {
- return ((List) parameters).size();
- } else if (parameters instanceof Collection) {
- return ((Collection) parameters).size();
- } else if (parameters instanceof Iterable) {
- return Iterables.size((Iterable) parameters);
- } else if (parameters instanceof Object[]) {
- return ((Object[]) parameters).length;
- }
- }
- LOG.warn("Unable to determine parameters size. Returning the default of
1.");
- return 1;
- }
-
- /**
- * Helper method that checks if the input method is a valid JUnit
@Parameters method.
- * @param method Input method.
- * @return true if the method is a valid JUnit parameters method, false
otherwise.
- */
- private static boolean isParametersMethod(@NonNull Method method) {
- // A valid parameters method is public static and with @Parameters
annotation.
- boolean methodPublicStatic =
- Modifier.isPublic(method.getModifiers()) &&
Modifier.isStatic(method.getModifiers());
- Parameters[] params = method.getAnnotationsByType(Parameters.class);
- return methodPublicStatic && (params != null && params.length > 0);
- }
-
- public static HBaseClassTestRule forClass(Class<?> clazz) {
- return new HBaseClassTestRule(clazz,
Timeout.builder().withLookingForStuckThread(true)
- .withTimeout(getTimeoutInSeconds(clazz), TimeUnit.SECONDS).build());
- }
-
- @Override
- public Statement apply(Statement base, Description description) {
- return systemExitRule.apply(timeout.apply(base, description), description);
- }
-
-}
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRuleChecker.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRuleChecker.java
deleted file mode 100644
index d6ee1ccaaee..00000000000
---
a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRuleChecker.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import org.apache.hadoop.hbase.testclassification.IntegrationTests;
-import org.apache.yetus.audience.InterfaceAudience;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.Description;
-import org.junit.runner.notification.RunListener;
-import org.junit.runner.notification.RunListener.ThreadSafe;
-
-/**
- * A RunListener to confirm that we have a {@link HBaseClassTestRule} class
rule for every test.
- */
[email protected]
-@ThreadSafe
-public class HBaseClassTestRuleChecker extends RunListener {
-
- @Override
- public void testStarted(Description description) throws Exception {
- Category[] categories =
description.getTestClass().getAnnotationsByType(Category.class);
-
- // @Category is not repeatable -- it is only possible to get an array of
length zero or one.
- if (categories.length == 1) {
- for (Class<?> c : categories[0].value()) {
- if (c == IntegrationTests.class) {
- return;
- }
- }
- }
- for (Field field : description.getTestClass().getFields()) {
- if (
- Modifier.isStatic(field.getModifiers()) && field.getType() ==
HBaseClassTestRule.class
- && field.isAnnotationPresent(ClassRule.class)
- ) {
- HBaseClassTestRule timeout = (HBaseClassTestRule) field.get(null);
- assertEquals("The HBaseClassTestRule ClassRule in " +
description.getTestClass().getName()
- + " is for " + timeout.getClazz().getName(),
description.getTestClass(),
- timeout.getClazz());
- return;
- }
- }
- fail("No HBaseClassTestRule ClassRule for " +
description.getTestClass().getName());
- }
-}
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseJupiterExtension.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseJupiterExtension.java
index 9d4ea87e0ec..1c606568c30 100644
---
a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseJupiterExtension.java
+++
b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseJupiterExtension.java
@@ -178,7 +178,7 @@ public class HBaseJupiterExtension implements
InvocationInterceptor, BeforeAllCa
private void printThreadDump() {
LOG.info("====> TEST TIMED OUT. PRINTING THREAD DUMP. <====");
- LOG.info(TimedOutTestsListener.buildThreadDiagnosticString());
+ LOG.info(TimedOutTestsThreadDumpHelper.buildThreadDiagnosticString());
}
@Override
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/ResourceCheckerJUnitListener.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/ResourceCheckerJUnitListener.java
deleted file mode 100644
index 2a796cc4077..00000000000
---
a/hbase-common/src/test/java/org/apache/hadoop/hbase/ResourceCheckerJUnitListener.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import org.junit.runner.notification.RunListener;
-
-/**
- * Listen to the test progress and check the usage of:
- * <ul>
- * <li>threads</li>
- * <li>open file descriptor</li>
- * <li>max open file descriptor</li>
- * </ul>
- * <p>
- * When surefire forkMode=once/always/perthread, this code is executed on the
forked process.
- */
-public class ResourceCheckerJUnitListener extends RunListener {
-
- private final Map<String, ResourceChecker> rcs = new ConcurrentHashMap<>();
-
- /**
- * To be implemented by sub classes if they want to add specific
ResourceAnalyzer.
- */
- protected void addResourceAnalyzer(ResourceChecker rc) {
- }
-
- private void start(String testName) {
- ResourceChecker rc = new ResourceChecker(testName);
- JUnitResourceCheckers.addResourceAnalyzer(rc);
- addResourceAnalyzer(rc);
- rcs.put(testName, rc);
- rc.start();
- }
-
- private void end(String testName) {
- ResourceChecker rc = rcs.remove(testName);
- assert rc != null;
- rc.end();
- }
-
- /**
- * Get the test name from the JUnit Description
- * @return the string for the short test name
- */
- private String descriptionToShortTestName(org.junit.runner.Description
description) {
- final int toRemove = "org.apache.hadoop.hbase.".length();
- return description.getTestClass().getName().substring(toRemove) + "#"
- + description.getMethodName();
- }
-
- @Override
- public void testStarted(org.junit.runner.Description description) throws
java.lang.Exception {
- start(descriptionToShortTestName(description));
- }
-
- @Override
- public void testFinished(org.junit.runner.Description description) throws
java.lang.Exception {
- end(descriptionToShortTestName(description));
- }
-}
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/SystemExitRule.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/SystemExitRule.java
deleted file mode 100644
index 4e3642cdb3b..00000000000
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/SystemExitRule.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-/*
-* Test rules to prevent System.exit or Runtime.halt from exiting
-* the JVM - instead an exception is thrown.
-* */
-public class SystemExitRule implements TestRule {
- final static SecurityManager securityManager = new TestSecurityManager();
-
- @Override
- public Statement apply(final Statement s, Description d) {
- return new Statement() {
- @Override
- public void evaluate() throws Throwable {
-
- try {
- forbidSystemExitCall();
- s.evaluate();
- } finally {
- System.setSecurityManager(null);
- }
- }
-
- };
- };
-
- // Exiting the JVM is not allowed in tests and this exception is thrown
instead
- // when it is done
- public static class SystemExitInTestException extends SecurityException {
- }
-
- private static void forbidSystemExitCall() {
- System.setSecurityManager(securityManager);
- }
-}
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TableNameTestRule.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/TableNameTestRule.java
deleted file mode 100644
index ef73abd042e..00000000000
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TableNameTestRule.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.rules.TestWatcher;
-import org.junit.runner.Description;
-
-/**
- * Returns a {@code TableName} based on currently running test method name.
Supports tests built on
- * the {@link org.junit.runners.Parameterized} runner.
- * @deprecated Use {@link TableNameTestExtension} instead, once we finish the
migration of JUnit5,
- * which means we do not need {@link TableNameTestRule} any more,
we can remove these
- * dependencies, see
- * <a
href="https://issues.apache.org/jira/browse/HBASE-23671">HBASE-23671</a> for
more
- * details.
- */
-@Deprecated
-public class TableNameTestRule extends TestWatcher {
-
- private TableName tableName;
-
- @Override
- protected void starting(Description description) {
- tableName =
TableName.valueOf(cleanUpTestName(description.getMethodName()));
- }
-
- /**
- * 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.
- */
- public static String cleanUpTestName(String methodName) {
- int index = methodName.indexOf('[');
- if (index == -1) {
- return methodName;
- }
- return methodName.substring(0, index);
- }
-
- public TableName getTableName() {
- return tableName;
- }
-}
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestBuildThreadDiagnosticString.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestBuildThreadDiagnosticString.java
index 74a4448983e..6e4ce1f69ce 100644
---
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestBuildThreadDiagnosticString.java
+++
b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestBuildThreadDiagnosticString.java
@@ -35,7 +35,7 @@ public class TestBuildThreadDiagnosticString {
@Test
public void test() {
- String threadDump = TimedOutTestsListener.buildThreadDiagnosticString();
+ String threadDump =
TimedOutTestsThreadDumpHelper.buildThreadDiagnosticString();
LOG.info(threadDump);
assertThat(threadDump,
containsString(getClass().getName() + ".test(" +
getClass().getSimpleName() + ".java:"));
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseClassTestRule.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseClassTestRule.java
deleted file mode 100644
index dc2b13c1c3e..00000000000
---
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseClassTestRule.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * 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 static junit.framework.TestCase.assertEquals;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;
-
-/**
- * Tests HBaseClassTestRule.
- */
-@Category(SmallTests.class)
-public class TestHBaseClassTestRule {
-
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHBaseClassTestRule.class);
-
- // Test input classes of various kinds.
- private static class NonParameterizedClass {
- void dummy() {
- }
-
- int dummy(int a) {
- return 0;
- }
- }
-
- @RunWith(Parameterized.class)
- private static class ParameterizedClassWithNoParametersMethod {
- void dummy() {
- }
- }
-
- @RunWith(Parameterized.class)
- @SuppressWarnings("UnusedMethod")
- private static class InValidParameterizedClass {
- // Not valid because parameters method is private.
- @Parameters
- private static List<Object> parameters() {
- return Arrays.asList(1, 2, 3, 4);
- }
-
- int dummy(int a) {
- return 0;
- }
- }
-
- @RunWith(Parameterized.class)
- private static class ValidParameterizedClass1 {
- @Parameters
- public static List<Object> parameters() {
- return Arrays.asList(1, 2, 3, 4, 5);
- }
-
- int dummy(int a) {
- return 0;
- }
- }
-
- @RunWith(Parameterized.class)
- private static class ValidParameterizedClass2 {
- @Parameters
- public static Object[] parameters() {
- return new Integer[] { 1, 2, 3, 4, 5, 6 };
- }
- }
-
- @RunWith(Parameterized.class)
- private static class ValidParameterizedClass3 {
- @Parameters
- public static Iterable<Integer> parameters() {
- return Arrays.asList(1, 2, 3, 4, 5, 6, 7);
- }
- }
-
- @RunWith(Parameterized.class)
- private static class ValidParameterizedClass4 {
- @Parameters
- public static Collection<Integer> parameters() {
- return Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
- }
- }
-
- @RunWith(Parameterized.class)
- private static class ExtendedParameterizedClass1 extends
ValidParameterizedClass1 {
- // Should be inferred from the parent class.
- int dummy2(int a) {
- return 0;
- }
- }
-
- @RunWith(Parameterized.class)
- private static class ExtendedParameterizedClass2 extends
ValidParameterizedClass1 {
- // Should override the parent parameters class.
- @Parameters
- public static List<Object> parameters() {
- return Arrays.asList(1, 2, 3);
- }
- }
-
- @Test
- public void testNumParameters() {
- // Invalid cases, expected to return 1.
-
assertEquals(HBaseClassTestRule.getNumParameters(NonParameterizedClass.class),
1);
- assertEquals(
-
HBaseClassTestRule.getNumParameters(ParameterizedClassWithNoParametersMethod.class),
1);
-
assertEquals(HBaseClassTestRule.getNumParameters(InValidParameterizedClass.class),
1);
- // Valid parameterized classes.
-
assertEquals(HBaseClassTestRule.getNumParameters(ValidParameterizedClass1.class),
- ValidParameterizedClass1.parameters().size());
-
assertEquals(HBaseClassTestRule.getNumParameters(ValidParameterizedClass2.class),
- ValidParameterizedClass2.parameters().length);
-
assertEquals(HBaseClassTestRule.getNumParameters(ValidParameterizedClass3.class),
- Iterables.size(ValidParameterizedClass3.parameters()));
-
assertEquals(HBaseClassTestRule.getNumParameters(ValidParameterizedClass4.class),
- ValidParameterizedClass4.parameters().size());
- // Testing inheritance.
-
assertEquals(HBaseClassTestRule.getNumParameters(ExtendedParameterizedClass1.class),
- ValidParameterizedClass1.parameters().size());
-
assertEquals(HBaseClassTestRule.getNumParameters(ExtendedParameterizedClass2.class),
- ExtendedParameterizedClass2.parameters().size());
- }
-}
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestSecurityManager.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestSecurityManager.java
index 030efa97709..22c7cf5c09d 100644
---
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestSecurityManager.java
+++
b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestSecurityManager.java
@@ -27,9 +27,15 @@ import java.security.Permission;
* TODO: Look at still using this in those tests
* */
public class TestSecurityManager extends SecurityManager {
+
+ // Exiting the JVM is not allowed in tests and this exception is thrown
instead
+ // when it is done
+ public static class SystemExitInTestException extends SecurityException {
+ }
+
@Override
public void checkExit(int status) {
- throw new SystemExitRule.SystemExitInTestException();
+ throw new SystemExitInTestException();
}
@Override
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestSystemExitInTest.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestSystemExitInTest.java
deleted file mode 100644
index 54fece09f39..00000000000
---
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestSystemExitInTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 static org.junit.jupiter.api.Assertions.assertThrows;
-
-import org.apache.hadoop.hbase.testclassification.MiscTests;
-import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.jupiter.api.Tag;
-import org.junit.jupiter.api.Test;
-
-@Tag(MiscTests.TAG)
-@Tag(SmallTests.TAG)
-public class TestSystemExitInTest {
-
- @Test
- public void testSystemExit() {
- assertThrows(SystemExitRule.SystemExitInTestException.class, () ->
System.exit(1));
- }
-
-}
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TimedOutTestsListener.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/TimedOutTestsThreadDumpHelper.java
similarity index 83%
rename from
hbase-common/src/test/java/org/apache/hadoop/hbase/TimedOutTestsListener.java
rename to
hbase-common/src/test/java/org/apache/hadoop/hbase/TimedOutTestsThreadDumpHelper.java
index 253d1735977..f10d76b5696 100644
---
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TimedOutTestsListener.java
+++
b/hbase-common/src/test/java/org/apache/hadoop/hbase/TimedOutTestsThreadDumpHelper.java
@@ -17,7 +17,6 @@
*/
package org.apache.hadoop.hbase;
-import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.management.LockInfo;
@@ -25,49 +24,24 @@ import java.lang.management.ManagementFactory;
import java.lang.management.MonitorInfo;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
-import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.Map;
-import org.junit.runner.notification.Failure;
-import org.junit.runner.notification.RunListener;
/**
* JUnit run listener which prints full thread dump into System.err in case a
test is failed due to
* timeout.
*/
-public class TimedOutTestsListener extends RunListener {
-
- private static final String TEST_TIMED_OUT_PREFIX = "test timed out after";
+public final class TimedOutTestsThreadDumpHelper {
private static final DateTimeFormatter TIMESTAMP_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss,SSS
Z").withZone(ZoneId.systemDefault());
- private static String INDENT = " ";
-
- private final PrintWriter output;
-
- public TimedOutTestsListener() {
- this.output = new PrintWriter(new OutputStreamWriter(System.err,
StandardCharsets.UTF_8));
- }
-
- public TimedOutTestsListener(PrintWriter output) {
- this.output = output;
- }
+ private static final String INDENT = " ";
- @Override
- public void testFailure(Failure failure) throws Exception {
- if (
- failure != null && failure.getMessage() != null
- && failure.getMessage().startsWith(TEST_TIMED_OUT_PREFIX)
- ) {
- output.println("====> TEST TIMED OUT. PRINTING THREAD DUMP. <====");
- output.println();
- output.print(buildThreadDiagnosticString());
- }
- output.flush();
+ private TimedOutTestsThreadDumpHelper() {
}
public static String buildThreadDiagnosticString() {
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestJul2Slf4j.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestJul2Slf4j.java
index 1e270ec6e1a..443d4a4f00e 100644
---
a/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestJul2Slf4j.java
+++
b/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestJul2Slf4j.java
@@ -27,7 +27,6 @@ import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.jupiter.api.AfterEach;
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestLog4jUtils.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestLog4jUtils.java
index de8b169fb2d..00cba91e075 100644
---
a/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestLog4jUtils.java
+++
b/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestLog4jUtils.java
@@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.jupiter.api.Tag;
diff --git a/hbase-common/src/test/java/org/junit/Assert.java
b/hbase-common/src/test/java/org/junit/Assert.java
new file mode 100644
index 00000000000..b3b51231c97
--- /dev/null
+++ b/hbase-common/src/test/java/org/junit/Assert.java
@@ -0,0 +1,255 @@
+/*
+ * 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.junit;
+
+import com.google.errorprone.annotations.RestrictedApi;
+import org.junit.jupiter.api.Assertions;
+
+/**
+ * JUnit4-compatible shim that delegates all calls to JUnit5 {@link
Assertions}. Exists so that
+ * third-party test utilities(especially hadoop mini cluster related classes)
compiled against
+ * JUnit4 can resolve {@code org.junit.Assert} without pulling in the real
junit4 dependency.
+ */
+public final class Assert {
+
+ private Assert() {
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertTrue(String message, boolean condition) {
+ Assertions.assertTrue(condition, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertTrue(boolean condition) {
+ Assertions.assertTrue(condition);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertFalse(String message, boolean condition) {
+ Assertions.assertFalse(condition, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertFalse(boolean condition) {
+ Assertions.assertFalse(condition);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void fail(String message) {
+ Assertions.fail(message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void fail() {
+ Assertions.fail();
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertEquals(String message, Object expected, Object
actual) {
+ Assertions.assertEquals(expected, actual, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertEquals(Object expected, Object actual) {
+ Assertions.assertEquals(expected, actual);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertEquals(String message, long expected, long actual) {
+ Assertions.assertEquals(expected, actual, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertEquals(long expected, long actual) {
+ Assertions.assertEquals(expected, actual);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertEquals(double expected, double actual, double
delta) {
+ Assertions.assertEquals(expected, actual, delta);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertEquals(String message, double expected, double
actual, double delta) {
+ Assertions.assertEquals(expected, actual, delta, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertEquals(float expected, float actual, float delta) {
+ Assertions.assertEquals(expected, actual, delta);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertEquals(String message, float expected, float
actual, float delta) {
+ Assertions.assertEquals(expected, actual, delta, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertNotEquals(String message, Object unexpected, Object
actual) {
+ Assertions.assertNotEquals(unexpected, actual, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertNotEquals(Object unexpected, Object actual) {
+ Assertions.assertNotEquals(unexpected, actual);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertNotEquals(String message, long unexpected, long
actual) {
+ Assertions.assertNotEquals(unexpected, actual, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertNotEquals(long unexpected, long actual) {
+ Assertions.assertNotEquals(unexpected, actual);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertNotEquals(double unexpected, double actual, double
delta) {
+ Assertions.assertNotEquals(unexpected, actual, delta);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertNotEquals(String message, double unexpected, double
actual,
+ double delta) {
+ Assertions.assertNotEquals(unexpected, actual, delta, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertNotNull(String message, Object object) {
+ Assertions.assertNotNull(object, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertNotNull(Object object) {
+ Assertions.assertNotNull(object);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertNull(String message, Object object) {
+ Assertions.assertNull(object, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertNull(Object object) {
+ Assertions.assertNull(object);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertSame(String message, Object expected, Object
actual) {
+ Assertions.assertSame(expected, actual, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertSame(Object expected, Object actual) {
+ Assertions.assertSame(expected, actual);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertNotSame(String message, Object unexpected, Object
actual) {
+ Assertions.assertNotSame(unexpected, actual, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertNotSame(Object unexpected, Object actual) {
+ Assertions.assertNotSame(unexpected, actual);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(String message, Object[] expecteds,
Object[] actuals) {
+ Assertions.assertArrayEquals(expecteds, actuals, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(Object[] expecteds, Object[] actuals) {
+ Assertions.assertArrayEquals(expecteds, actuals);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(String message, byte[] expecteds,
byte[] actuals) {
+ Assertions.assertArrayEquals(expecteds, actuals, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(byte[] expecteds, byte[] actuals) {
+ Assertions.assertArrayEquals(expecteds, actuals);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(String message, char[] expecteds,
char[] actuals) {
+ Assertions.assertArrayEquals(expecteds, actuals, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(char[] expecteds, char[] actuals) {
+ Assertions.assertArrayEquals(expecteds, actuals);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(String message, short[] expecteds,
short[] actuals) {
+ Assertions.assertArrayEquals(expecteds, actuals, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(short[] expecteds, short[] actuals) {
+ Assertions.assertArrayEquals(expecteds, actuals);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(String message, int[] expecteds, int[]
actuals) {
+ Assertions.assertArrayEquals(expecteds, actuals, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(int[] expecteds, int[] actuals) {
+ Assertions.assertArrayEquals(expecteds, actuals);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(String message, long[] expecteds,
long[] actuals) {
+ Assertions.assertArrayEquals(expecteds, actuals, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(long[] expecteds, long[] actuals) {
+ Assertions.assertArrayEquals(expecteds, actuals);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(String message, double[] expecteds,
double[] actuals,
+ double delta) {
+ Assertions.assertArrayEquals(expecteds, actuals, delta, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(double[] expecteds, double[] actuals,
double delta) {
+ Assertions.assertArrayEquals(expecteds, actuals, delta);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(String message, float[] expecteds,
float[] actuals,
+ float delta) {
+ Assertions.assertArrayEquals(expecteds, actuals, delta, message);
+ }
+
+ @RestrictedApi(explanation = "Only for thirdparty code, use JUnit5
Assertions in HBase")
+ public static void assertArrayEquals(float[] expecteds, float[] actuals,
float delta) {
+ Assertions.assertArrayEquals(expecteds, actuals, delta);
+ }
+}
diff --git
a/hbase-compression/hbase-compression-zstd/src/test/java/org/apache/hadoop/hbase/io/compress/zstd/TestZstdDictionarySplitMerge.java
b/hbase-compression/hbase-compression-zstd/src/test/java/org/apache/hadoop/hbase/io/compress/zstd/TestZstdDictionarySplitMerge.java
index eb5ddb4d780..425f92608d8 100644
---
a/hbase-compression/hbase-compression-zstd/src/test/java/org/apache/hadoop/hbase/io/compress/zstd/TestZstdDictionarySplitMerge.java
+++
b/hbase-compression/hbase-compression-zstd/src/test/java/org/apache/hadoop/hbase/io/compress/zstd/TestZstdDictionarySplitMerge.java
@@ -51,6 +51,7 @@ import org.junit.jupiter.api.Test;
public class TestZstdDictionarySplitMerge {
private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
+ private static int numRows = 10_000;
private static Configuration conf;
@BeforeAll
@@ -82,16 +83,16 @@ public class TestZstdDictionarySplitMerge {
.setConfiguration(ZstdCodec.ZSTD_DICTIONARY_KEY,
dictionaryPath).build())
.build();
final Admin admin = TEST_UTIL.getAdmin();
- admin.createTable(td, new byte[][] { Bytes.toBytes(1) });
+ admin.createTable(td, new byte[][] { Bytes.toBytes(String.valueOf(1)) });
TEST_UTIL.waitTableAvailable(tableName);
// Load some data
Table t = ConnectionFactory.createConnection(conf).getTable(tableName);
- TEST_UTIL.loadNumericRows(t, cfName, 0, 100_000);
+ TEST_UTIL.loadNumericRows(t, cfName, 0, numRows);
admin.flush(tableName);
assertTrue(DictionaryCache.contains(dictionaryPath), "Dictionary was not
loaded");
- TEST_UTIL.verifyNumericRows(t, cfName, 0, 100_000, 0);
+ TEST_UTIL.verifyNumericRows(t, cfName, 0, numRows, 0);
// Test split procedure
- admin.split(tableName, Bytes.toBytes(50_000));
+ admin.split(tableName, Bytes.toBytes(String.valueOf(numRows / 2)));
TEST_UTIL.waitFor(30000, new ExplainingPredicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
@@ -104,30 +105,36 @@ public class TestZstdDictionarySplitMerge {
}
});
TEST_UTIL.waitUntilNoRegionsInTransition();
- TEST_UTIL.verifyNumericRows(t, cfName, 0, 100_000, 0);
+ TEST_UTIL.verifyNumericRows(t, cfName, 0, numRows, 0);
// Test merge procedure
RegionInfo regionA = null;
RegionInfo regionB = null;
+
for (RegionInfo region : admin.getRegions(tableName)) {
if (region.getStartKey().length == 0) {
regionA = region;
- } else if (Bytes.equals(region.getStartKey(), Bytes.toBytes(1))) {
+ } else if (Bytes.equals(region.getStartKey(),
Bytes.toBytes(String.valueOf(1)))) {
regionB = region;
}
}
assertNotNull(regionA);
assertNotNull(regionB);
+
+ // major compact before merging otherwise the regions are not mergable
+ TEST_UTIL.compact(tableName, true);
+ admin.reopenTableRegions(tableName);
+
admin
.mergeRegionsAsync(new byte[][] { regionA.getRegionName(),
regionB.getRegionName() }, false)
- .get(30, TimeUnit.SECONDS);
+ .get(300, TimeUnit.SECONDS);
assertEquals(2, admin.getRegions(tableName).size());
ServerName expected =
TEST_UTIL.getMiniHBaseCluster().getRegionServer(0).getServerName();
assertEquals(expected,
TEST_UTIL.getConnection().getRegionLocator(tableName)
- .getRegionLocation(Bytes.toBytes(1), true).getServerName());
+ .getRegionLocation(Bytes.toBytes(String.valueOf(1)),
true).getServerName());
try (AsyncConnection asyncConn =
ConnectionFactory.createAsyncConnection(conf).get()) {
assertEquals(expected, asyncConn.getRegionLocator(tableName)
- .getRegionLocation(Bytes.toBytes(1), true).get().getServerName());
+ .getRegionLocation(Bytes.toBytes(String.valueOf(1)),
true).get().getServerName());
}
- TEST_UTIL.verifyNumericRows(t, cfName, 0, 100_000, 0);
+ TEST_UTIL.verifyNumericRows(t, cfName, 0, numRows, 0);
}
}
diff --git a/hbase-dev-generate-classpath/pom.xml
b/hbase-dev-generate-classpath/pom.xml
index 2f81f6a88ab..a248933bd9b 100644
--- a/hbase-dev-generate-classpath/pom.xml
+++ b/hbase-dev-generate-classpath/pom.xml
@@ -246,11 +246,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
diff --git
a/hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/TestSecureExport.java
b/hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/TestSecureExport.java
index 46885b64e12..bc0055b0f10 100644
---
a/hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/TestSecureExport.java
+++
b/hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/TestSecureExport.java
@@ -70,6 +70,7 @@ import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
@@ -304,7 +305,7 @@ public class TestSecureExport {
}
@Test
- @org.junit.Ignore // See HBASE-23990
+ @Disabled // See HBASE-23990
public void testVisibilityLabels() throws IOException, Throwable {
final String exportTable = methodName + "_export";
final String importTable = methodName + "_import";
diff --git
a/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/row/stats/TestRowStatisticsEventHandler.java
b/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/row/stats/TestRowStatisticsEventHandler.java
index 423f23073a7..fff85cd173f 100644
---
a/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/row/stats/TestRowStatisticsEventHandler.java
+++
b/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/row/stats/TestRowStatisticsEventHandler.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.coprocessor.example.row.stats;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
@@ -36,9 +36,9 @@ import org.apache.hadoop.hbase.metrics.Counter;
import org.apache.hadoop.hbase.metrics.impl.CounterImpl;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
@Tag(SmallTests.TAG)
public class TestRowStatisticsEventHandler {
@@ -53,7 +53,7 @@ public class TestRowStatisticsEventHandler {
private Counter failureCounter;
private RowStatisticsEventHandler eventHandler;
- @Before
+ @BeforeEach
public void setup() {
bufferedMutator = mock(BufferedMutator.class);
failureCounter = new CounterImpl();
diff --git a/hbase-it/pom.xml b/hbase-it/pom.xml
index 59987810f11..62b67b63548 100644
--- a/hbase-it/pom.xml
+++ b/hbase-it/pom.xml
@@ -196,6 +196,11 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-launcher</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
diff --git
a/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDDLMasterFailover.java
b/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDDLMasterFailover.java
index 6ca28bb4ae5..b659cf329ea 100644
---
a/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDDLMasterFailover.java
+++
b/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDDLMasterFailover.java
@@ -17,7 +17,11 @@
*/
package org.apache.hadoop.hbase;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.util.ArrayList;
@@ -46,9 +50,8 @@ import org.apache.hadoop.hbase.util.HBaseFsck;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.util.hbck.HbckTestingUtil;
import org.apache.hadoop.util.ToolRunner;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -96,7 +99,7 @@ import org.slf4j.LoggerFactory;
* -Dhbase.IntegrationTestDDLMasterFailover.numRegions=50 --monkey
masterKilling
*/
-@Category(IntegrationTests.class)
+@Tag(IntegrationTests.TAG)
public class IntegrationTestDDLMasterFailover extends IntegrationTestBase {
private static final Logger LOG =
LoggerFactory.getLogger(IntegrationTestDDLMasterFailover.class);
@@ -200,8 +203,7 @@ public class IntegrationTestDDLMasterFailover extends
IntegrationTestBase {
assertTrue(admin.getNamespaceDescriptor(nsName) != null,
"Namespace: " + nsName + " in namespaceMap does not exist");
} catch (NamespaceNotFoundException nsnfe) {
- Assert
- .fail("Namespace: " + nsName + " in namespaceMap does not exist: " +
nsnfe.getMessage());
+ fail("Namespace: " + nsName + " in namespaceMap does not exist: " +
nsnfe.getMessage());
}
}
admin.close();
@@ -220,8 +222,8 @@ public class IntegrationTestDDLMasterFailover extends
IntegrationTestBase {
"Table: " + tableName + " in disabledTables is not disabled");
}
for (TableName tableName : deletedTables.keySet()) {
- Assert.assertFalse("Table: " + tableName + " in deletedTables is not
deleted",
- admin.tableExists(tableName));
+ assertFalse(admin.tableExists(tableName),
+ "Table: " + tableName + " in deletedTables is not deleted");
}
admin.close();
}
@@ -549,7 +551,7 @@ public class IntegrationTestDDLMasterFailover extends
IntegrationTestBase {
TableName tableName = selected.getTableName();
LOG.info("Deleting table :" + selected);
admin.deleteTable(tableName);
- Assert.assertFalse("Table: " + selected + " was not deleted",
admin.tableExists(tableName));
+ assertFalse(admin.tableExists(tableName), "Table: " + selected + " was
not deleted");
deletedTables.put(tableName, selected);
LOG.info("Deleted table :" + selected);
} catch (Exception e) {
@@ -648,10 +650,10 @@ public class IntegrationTestDDLMasterFailover extends
IntegrationTestBase {
TableDescriptor freshTableDesc = admin.getDescriptor(tableName);
ColumnFamilyDescriptor freshColumnDesc =
freshTableDesc.getColumnFamily(columnDesc.getName());
- Assert.assertEquals("Column family: " + columnDesc + " was not
altered",
- freshColumnDesc.getMaxVersions(), versions);
- Assert.assertEquals("Column family: " + freshColumnDesc + " was not
altered",
- freshColumnDesc.getMinVersions(), versions);
+ assertEquals(freshColumnDesc.getMaxVersions(), versions,
+ "Column family: " + columnDesc + " was not altered");
+ assertEquals(freshColumnDesc.getMinVersions(), versions,
+ "Column family: " + freshColumnDesc + " was not altered");
assertTrue(admin.isTableDisabled(tableName),
"After alter versions of column family, Table: " + tableName + " is
not disabled");
disabledTables.put(tableName, freshTableDesc);
@@ -699,11 +701,10 @@ public class IntegrationTestDDLMasterFailover extends
IntegrationTestBase {
TableDescriptor freshTableDesc = admin.getDescriptor(tableName);
ColumnFamilyDescriptor freshColumnDesc =
freshTableDesc.getColumnFamily(columnDesc.getName());
- Assert.assertEquals("Encoding of column family: " + columnDesc + " was
not altered",
- freshColumnDesc.getDataBlockEncoding().getId(), id);
- Assert.assertTrue(
- "After alter encoding of column family, Table: " + tableName + " is
not disabled",
- admin.isTableDisabled(tableName));
+ assertEquals(freshColumnDesc.getDataBlockEncoding().getId(), id,
+ "Encoding of column family: " + columnDesc + " was not altered");
+ assertTrue(admin.isTableDisabled(tableName),
+ "After alter encoding of column family, Table: " + tableName + " is
not disabled");
disabledTables.put(tableName, freshTableDesc);
LOG.info("Altered encoding of column family: " + freshColumnDesc + "
to: " + id
+ " in table: " + tableName);
@@ -737,10 +738,10 @@ public class IntegrationTestDDLMasterFailover extends
IntegrationTestBase {
admin.deleteColumnFamily(tableName, cfd.getName());
// assertion
TableDescriptor freshTableDesc = admin.getDescriptor(tableName);
- Assert.assertFalse("Column family: " + cfd + " was not added",
- freshTableDesc.hasColumnFamily(cfd.getName()));
- Assert.assertTrue("After delete column family, Table: " + tableName +
" is not disabled",
- admin.isTableDisabled(tableName));
+ assertFalse(freshTableDesc.hasColumnFamily(cfd.getName()),
+ "Column family: " + cfd + " was not added");
+ assertTrue(admin.isTableDisabled(tableName),
+ "After delete column family, Table: " + tableName + " is not
disabled");
disabledTables.put(tableName, freshTableDesc);
LOG.info("Deleted column family: " + cfd + " from table: " +
tableName);
} catch (Exception e) {
@@ -788,8 +789,8 @@ public class IntegrationTestDDLMasterFailover extends
IntegrationTestBase {
table.put(put);
}
TableDescriptor freshTableDesc = admin.getDescriptor(tableName);
- Assert.assertTrue("After insert, Table: " + tableName + " in not
enabled",
- admin.isTableEnabled(tableName));
+ assertTrue(admin.isTableEnabled(tableName),
+ "After insert, Table: " + tableName + " in not enabled");
enabledTables.put(tableName, freshTableDesc);
LOG.info("Added " + numRows + " rows to table: " + selected);
} catch (Exception e) {
@@ -902,11 +903,9 @@ public class IntegrationTestDDLMasterFailover extends
IntegrationTestBase {
for (Worker worker : workers) {
Exception e = worker.getSavedException();
if (e != null) {
- LOG.error("Found exception in thread: " + worker.getName());
- e.printStackTrace();
+ LOG.error("Found exception in thread: " + worker.getName(), e);
}
- Assert.assertNull("Action failed: " + worker.getAction() + " in thread:
" + worker.getName(),
- e);
+ assertNull(e, "Action failed: " + worker.getAction() + " in thread: " +
worker.getName());
}
}
diff --git
a/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestRegionReplicaReplication.java
b/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestRegionReplicaReplication.java
index 9462d0a47a9..ba2ad27629e 100644
---
a/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestRegionReplicaReplication.java
+++
b/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestRegionReplicaReplication.java
@@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.io.IOException;
import java.util.List;
import java.util.concurrent.BlockingQueue;
@@ -34,9 +36,8 @@ import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.util.test.LoadTestDataGenerator;
import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.ToolRunner;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
@@ -67,7 +68,7 @@ import
org.apache.hbase.thirdparty.com.google.common.collect.Lists;
* -DIntegrationTestRegionReplicaReplication.num_write_threads=100
* </pre>
*/
-@Category(IntegrationTests.class)
+@Tag(IntegrationTests.TAG)
public class IntegrationTestRegionReplicaReplication extends
IntegrationTestIngest {
private static final String TEST_NAME =
@@ -194,7 +195,7 @@ public class IntegrationTestRegionReplicaReplication
extends IntegrationTestInge
if (0 != ret) {
String errorMsg = "Load failed with error code " + ret;
LOG.error(errorMsg);
- Assert.fail(errorMsg);
+ fail(errorMsg);
}
args = Lists.newArrayList(getArgsForLoadTestTool("", "", startKey,
numKeys));
@@ -211,7 +212,7 @@ public class IntegrationTestRegionReplicaReplication
extends IntegrationTestInge
if (0 != ret) {
String errorMsg = "Load failed with error code " + ret;
LOG.error(errorMsg);
- Assert.fail(errorMsg);
+ fail(errorMsg);
}
startKey += numKeys;
}
diff --git
a/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java
b/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java
index dcc2e3234da..bbe900ffff8 100644
--- a/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java
+++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java
@@ -18,14 +18,20 @@
package org.apache.hadoop.hbase;
import java.io.IOException;
+import java.io.PrintWriter;
import java.util.Set;
import java.util.regex.Pattern;
import org.apache.hadoop.hbase.testclassification.IntegrationTests;
import org.apache.hadoop.hbase.util.AbstractHBaseTool;
import org.apache.hadoop.util.ToolRunner;
-import org.junit.internal.TextListener;
-import org.junit.runner.JUnitCore;
-import org.junit.runner.Result;
+import org.junit.platform.engine.DiscoverySelector;
+import org.junit.platform.engine.discovery.DiscoverySelectors;
+import org.junit.platform.launcher.Launcher;
+import org.junit.platform.launcher.LauncherDiscoveryRequest;
+import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
+import org.junit.platform.launcher.core.LauncherFactory;
+import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
+import org.junit.platform.launcher.listeners.TestExecutionSummary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -95,6 +101,23 @@ public class IntegrationTestsDriver extends
AbstractHBaseTool {
return classes.toArray(new Class<?>[classes.size()]);
}
+ private static int runTests(Class<?>[] classes) {
+ DiscoverySelector[] selectors = new DiscoverySelector[classes.length];
+ for (int i = 0; i < classes.length; i++) {
+ selectors[i] = DiscoverySelectors.selectClass(classes[i]);
+ }
+ LauncherDiscoveryRequest request =
+ LauncherDiscoveryRequestBuilder.request().selectors(selectors).build();
+ Launcher launcher = LauncherFactory.create();
+ SummaryGeneratingListener listener = new SummaryGeneratingListener();
+ launcher.registerTestExecutionListeners(listener);
+ launcher.execute(request);
+
+ TestExecutionSummary summary = listener.getSummary();
+ summary.printTo(new PrintWriter(System.out));
+ return summary.getTotalFailureCount() > 0 ? 1 : 0;
+ }
+
@Override
protected int doWork() throws Exception {
// this is called from the command line, so we should set to use the
distributed cluster
@@ -104,10 +127,6 @@ public class IntegrationTestsDriver extends
AbstractHBaseTool {
for (Class<?> aClass : classes) {
LOG.info(" " + aClass);
}
- JUnitCore junit = new JUnitCore();
- junit.addListener(new TextListener(System.out));
- Result result = junit.run(classes);
-
- return result.wasSuccessful() ? 0 : 1;
+ return runTests(classes);
}
}
diff --git
a/hbase-it/src/test/java/org/apache/hadoop/hbase/StripeCompactionsPerformanceEvaluation.java
b/hbase-it/src/test/java/org/apache/hadoop/hbase/StripeCompactionsPerformanceEvaluation.java
index d23255d7ee2..f812d6dc210 100644
---
a/hbase-it/src/test/java/org/apache/hadoop/hbase/StripeCompactionsPerformanceEvaluation.java
+++
b/hbase-it/src/test/java/org/apache/hadoop/hbase/StripeCompactionsPerformanceEvaluation.java
@@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.io.IOException;
import java.util.List;
import java.util.Locale;
@@ -40,7 +42,6 @@ import org.apache.hadoop.hbase.util.MultiThreadedWriter;
import org.apache.hadoop.hbase.util.RegionSplitter;
import org.apache.hadoop.hbase.util.test.LoadTestDataGenerator;
import org.apache.yetus.audience.InterfaceAudience;
-import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -259,7 +260,7 @@ public class StripeCompactionsPerformanceEvaluation extends
AbstractHBaseTool {
*/
status(description + " test took "
+ (EnvironmentEdgeManager.currentTime() - testStartTime) / 1000 + "sec");
- Assert.assertTrue(success);
+ assertTrue(success);
}
private static void status(String s) {
diff --git
a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/UnbalanceKillAndRebalanceAction.java
b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/UnbalanceKillAndRebalanceAction.java
index 3a0f292e4a4..d46644f45d2 100644
---
a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/UnbalanceKillAndRebalanceAction.java
+++
b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/UnbalanceKillAndRebalanceAction.java
@@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase.chaos.actions;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -25,7 +27,6 @@ import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.hadoop.hbase.ClusterMetrics;
import org.apache.hadoop.hbase.ServerName;
-import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -69,8 +70,8 @@ public class UnbalanceKillAndRebalanceAction extends Action {
Set<ServerName> killedServers = new HashSet<>();
int liveCount = (int) Math.ceil(FRC_SERVERS_THAT_HOARD_AND_LIVE *
victimServers.size());
int deadCount = (int) Math.ceil(FRC_SERVERS_THAT_HOARD_AND_DIE *
victimServers.size());
- Assert.assertTrue("There are not enough victim servers: " +
victimServers.size(),
- liveCount + deadCount < victimServers.size());
+ assertTrue(liveCount + deadCount < victimServers.size(),
+ "There are not enough victim servers: " + victimServers.size());
Random rand = ThreadLocalRandom.current();
List<ServerName> targetServers = new ArrayList<>(liveCount);
for (int i = 0; i < liveCount + deadCount; ++i) {
diff --git
a/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestTableSnapshotInputFormat.java
b/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestTableSnapshotInputFormat.java
index ec11284eb28..a6c795d39c7 100644
---
a/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestTableSnapshotInputFormat.java
+++
b/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestTableSnapshotInputFormat.java
@@ -28,9 +28,9 @@ import
org.apache.hadoop.hbase.testclassification.IntegrationTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.util.ToolRunner;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -61,7 +61,7 @@ import org.slf4j.LoggerFactory;
* "IntegrationTestTableSnapshotInputFormat.tableDir" => temporary
directory to restore the
* snapshot files
*/
-@Category(IntegrationTests.class)
+@Tag(IntegrationTests.TAG)
// Not runnable as a unit test. See TestTableSnapshotInputFormat
public class IntegrationTestTableSnapshotInputFormat extends
IntegrationTestBase {
private static final Logger LOG =
@@ -97,7 +97,7 @@ public class IntegrationTestTableSnapshotInputFormat extends
IntegrationTestBase
}
@Override
- @Before
+ @BeforeEach
public void setUp() throws Exception {
super.setUp();
util = getTestingUtil(getConf());
@@ -106,7 +106,7 @@ public class IntegrationTestTableSnapshotInputFormat
extends IntegrationTestBase
}
@Override
- @After
+ @AfterEach
public void cleanUp() throws Exception {
util.restoreCluster();
}
diff --git a/hbase-mapreduce/pom.xml b/hbase-mapreduce/pom.xml
index 8b2063e64b8..d0aa63d79c7 100644
--- a/hbase-mapreduce/pom.xml
+++ b/hbase-mapreduce/pom.xml
@@ -191,6 +191,11 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
diff --git a/hbase-rest/pom.xml b/hbase-rest/pom.xml
index f9b3176a957..b259612337f 100644
--- a/hbase-rest/pom.xml
+++ b/hbase-rest/pom.xml
@@ -213,6 +213,11 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
diff --git
a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/model/TestColumnSchemaModel.java
b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/model/TestColumnSchemaModel.java
index c6aac9eb96d..45685b327cc 100644
---
a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/model/TestColumnSchemaModel.java
+++
b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/model/TestColumnSchemaModel.java
@@ -20,20 +20,15 @@ package org.apache.hadoop.hbase.rest.model;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-@Category({ RestTests.class, SmallTests.class })
+@Tag(RestTests.TAG)
+@Tag(SmallTests.TAG)
public class TestColumnSchemaModel extends TestModelBase<ColumnSchemaModel> {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestColumnSchemaModel.class);
-
protected static final String COLUMN_NAME = "testcolumn";
protected static final boolean BLOCKCACHE = true;
protected static final int BLOCKSIZE = 16384;
diff --git a/hbase-server/pom.xml b/hbase-server/pom.xml
index 80353e14185..8cd7b4bc853 100644
--- a/hbase-server/pom.xml
+++ b/hbase-server/pom.xml
@@ -297,11 +297,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/ClearUserNamespacesAndTablesRule.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/ClearUserNamespacesAndTablesRule.java
deleted file mode 100644
index 87adccf2e3d..00000000000
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/ClearUserNamespacesAndTablesRule.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * 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.List;
-import java.util.Objects;
-import java.util.StringJoiner;
-import java.util.concurrent.CompletableFuture;
-import java.util.function.Supplier;
-import java.util.stream.Collectors;
-import org.apache.hadoop.hbase.client.AsyncAdmin;
-import org.apache.hadoop.hbase.client.AsyncConnection;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.rules.ExternalResource;
-import org.junit.rules.TestRule;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A {@link TestRule} that clears all user namespaces and tables {@link
ExternalResource#before()
- * before} the test executes. Can be used in either the {@link Rule} or {@link
ClassRule} positions.
- * Lazily realizes the provided {@link AsyncConnection} so as to avoid
initialization races with
- * other {@link Rule Rules}. <b>Does not</b> {@link AsyncConnection#close()
close()} provided
- * connection instance when finished.
- * </p>
- * Use in combination with {@link MiniClusterRule} and {@link ConnectionRule},
for example:
- *
- * <pre>
- * {
- * @code
- * public class TestMyClass {
- * @ClassRule
- * public static final MiniClusterRule miniClusterRule =
MiniClusterRule.newBuilder().build();
- *
- * private final ConnectionRule connectionRule =
- * new ConnectionRule(miniClusterRule::createConnection);
- * private final ClearUserNamespacesAndTablesRule
clearUserNamespacesAndTablesRule =
- * new ClearUserNamespacesAndTablesRule(connectionRule::getConnection);
- *
- * @Rule
- * public TestRule rule =
- *
RuleChain.outerRule(connectionRule).around(clearUserNamespacesAndTablesRule);
- * }
- * }
- * </pre>
- */
-public class ClearUserNamespacesAndTablesRule extends ExternalResource {
- private static final Logger logger =
- LoggerFactory.getLogger(ClearUserNamespacesAndTablesRule.class);
-
- private final Supplier<AsyncConnection> connectionSupplier;
- private AsyncAdmin admin;
-
- public ClearUserNamespacesAndTablesRule(final Supplier<AsyncConnection>
connectionSupplier) {
- this.connectionSupplier = connectionSupplier;
- }
-
- @Override
- protected void before() throws Throwable {
- final AsyncConnection connection =
Objects.requireNonNull(connectionSupplier.get());
- admin = connection.getAdmin();
-
- clearTablesAndNamespaces().join();
- }
-
- private CompletableFuture<Void> clearTablesAndNamespaces() {
- return deleteUserTables().thenCompose(_void -> deleteUserNamespaces());
- }
-
- private CompletableFuture<Void> deleteUserTables() {
- return listTableNames().thenApply(tableNames -> tableNames.stream()
- .map(tableName -> disableIfEnabled(tableName).thenCompose(_void ->
deleteTable(tableName)))
-
.toArray(CompletableFuture[]::new)).thenCompose(CompletableFuture::allOf);
- }
-
- private CompletableFuture<List<TableName>> listTableNames() {
- return CompletableFuture.runAsync(() -> logger.trace("listing tables"))
- .thenCompose(_void -> admin.listTableNames(false)).thenApply(tableNames
-> {
- if (logger.isTraceEnabled()) {
- final StringJoiner joiner = new StringJoiner(", ", "[", "]");
-
tableNames.stream().map(TableName::getNameAsString).forEach(joiner::add);
- logger.trace("found existing tables {}", joiner.toString());
- }
- return tableNames;
- });
- }
-
- private CompletableFuture<Boolean> isTableEnabled(final TableName tableName)
{
- return admin.isTableEnabled(tableName).thenApply(isEnabled -> {
- logger.trace("table {} is enabled.", tableName);
- return isEnabled;
- });
- }
-
- private CompletableFuture<Void> disableIfEnabled(final TableName tableName) {
- return isTableEnabled(tableName).thenCompose(
- isEnabled -> isEnabled ? disableTable(tableName) :
CompletableFuture.completedFuture(null));
- }
-
- private CompletableFuture<Void> disableTable(final TableName tableName) {
- return CompletableFuture.runAsync(() -> logger.trace("disabling enabled
table {}", tableName))
- .thenCompose(_void -> admin.disableTable(tableName));
- }
-
- private CompletableFuture<Void> deleteTable(final TableName tableName) {
- return CompletableFuture.runAsync(() -> logger.trace("deleting disabled
table {}", tableName))
- .thenCompose(_void -> admin.deleteTable(tableName));
- }
-
- private CompletableFuture<List<String>> listUserNamespaces() {
- return CompletableFuture.runAsync(() -> logger.trace("listing namespaces"))
- .thenCompose(_void ->
admin.listNamespaceDescriptors()).thenApply(namespaceDescriptors -> {
- final StringJoiner joiner = new StringJoiner(", ", "[", "]");
- final List<String> names =
namespaceDescriptors.stream().map(NamespaceDescriptor::getName)
- .peek(joiner::add).collect(Collectors.toList());
- logger.trace("found existing namespaces {}", joiner);
- return names;
- })
- .thenApply(namespaces -> namespaces.stream()
- .filter(
- namespace -> !Objects.equals(namespace,
NamespaceDescriptor.SYSTEM_NAMESPACE.getName()))
- .filter(
- namespace -> !Objects.equals(namespace,
NamespaceDescriptor.DEFAULT_NAMESPACE.getName()))
- .collect(Collectors.toList()));
- }
-
- private CompletableFuture<Void> deleteNamespace(final String namespace) {
- return CompletableFuture.runAsync(() -> logger.trace("deleting namespace
{}", namespace))
- .thenCompose(_void -> admin.deleteNamespace(namespace));
- }
-
- private CompletableFuture<Void> deleteUserNamespaces() {
- return listUserNamespaces().thenCompose(namespaces -> CompletableFuture
-
.allOf(namespaces.stream().map(this::deleteNamespace).toArray(CompletableFuture[]::new)));
- }
-}
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/ConnectionRule.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/ConnectionRule.java
deleted file mode 100644
index 9927eb8c6a3..00000000000
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/ConnectionRule.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * 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.io.IOException;
-import java.util.concurrent.CompletableFuture;
-import java.util.function.Supplier;
-import org.apache.hadoop.hbase.client.AsyncConnection;
-import org.apache.hadoop.hbase.client.Connection;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.rules.ExternalResource;
-
-/**
- * A {@link Rule} that manages the lifecycle of an instance of {@link
AsyncConnection}. Can be used
- * in either the {@link Rule} or {@link ClassRule} positions.
- * </p>
- * Use in combination with {@link MiniClusterRule}, for example:
- *
- * <pre>
- * {
- * @code
- * public class TestMyClass {
- * private static final MiniClusterRule miniClusterRule =
MiniClusterRule.newBuilder().build();
- * private static final ConnectionRule connectionRule =
- *
ConnectionRule.createAsyncConnectionRule(miniClusterRule::createConnection);
- *
- * @ClassRule
- * public static final TestRule rule =
- * RuleChain.outerRule(miniClusterRule).around(connectionRule);
- * }
- * }
- * </pre>
- *
- * @deprecated Use {@link ConnectionExtension} instead, once we finish the
migration of JUnit5,
- * which means we do not need {@link ConnectionRule} any more, we
can remove these
- * dependencies, see
- * <a
href="https://issues.apache.org/jira/browse/HBASE-23671">HBASE-23671</a> for
more
- * details.
- */
-@Deprecated
-public final class ConnectionRule extends ExternalResource {
-
- private final Supplier<Connection> connectionSupplier;
- private final Supplier<CompletableFuture<AsyncConnection>>
asyncConnectionSupplier;
-
- private Connection connection;
- private AsyncConnection asyncConnection;
-
- public static ConnectionRule createConnectionRule(final Supplier<Connection>
connectionSupplier) {
- return new ConnectionRule(connectionSupplier, null);
- }
-
- public static ConnectionRule createAsyncConnectionRule(
- final Supplier<CompletableFuture<AsyncConnection>>
asyncConnectionSupplier) {
- return new ConnectionRule(null, asyncConnectionSupplier);
- }
-
- public static ConnectionRule createConnectionRule(final Supplier<Connection>
connectionSupplier,
- final Supplier<CompletableFuture<AsyncConnection>>
asyncConnectionSupplier) {
- return new ConnectionRule(connectionSupplier, asyncConnectionSupplier);
- }
-
- private ConnectionRule(final Supplier<Connection> connectionSupplier,
- final Supplier<CompletableFuture<AsyncConnection>>
asyncConnectionSupplier) {
- this.connectionSupplier = connectionSupplier;
- this.asyncConnectionSupplier = asyncConnectionSupplier;
- }
-
- public Connection getConnection() {
- if (connection == null) {
- throw new IllegalStateException(
- "ConnectionRule not initialized with a synchronous connection.");
- }
- return connection;
- }
-
- public AsyncConnection getAsyncConnection() {
- if (asyncConnection == null) {
- throw new IllegalStateException(
- "ConnectionRule not initialized with an asynchronous connection.");
- }
- return asyncConnection;
- }
-
- @Override
- protected void before() throws Throwable {
- if (connectionSupplier != null) {
- this.connection = connectionSupplier.get();
- }
- if (asyncConnectionSupplier != null) {
- this.asyncConnection = asyncConnectionSupplier.get().join();
- }
- if (connection == null && asyncConnection != null) {
- this.connection = asyncConnection.toConnection();
- }
- }
-
- @Override
- protected void after() {
- CompletableFuture<Void> closeConnection = CompletableFuture.runAsync(() ->
{
- if (this.connection != null) {
- try {
- connection.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- });
- CompletableFuture<Void> closeAsyncConnection =
CompletableFuture.runAsync(() -> {
- if (this.asyncConnection != null) {
- try {
- asyncConnection.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- });
- CompletableFuture.allOf(closeConnection, closeAsyncConnection).join();
- }
-}
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniClusterRule.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniClusterRule.java
deleted file mode 100644
index a36fd05d405..00000000000
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniClusterRule.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * 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.io.IOException;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-import java.util.function.Supplier;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.client.AsyncConnection;
-import org.apache.hadoop.hbase.client.Connection;
-import org.apache.hadoop.hbase.client.ConnectionFactory;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.rules.ExternalResource;
-import org.junit.rules.TestRule;
-
-/**
- * A {@link TestRule} that manages an instance of the {@link
SingleProcessHBaseCluster}. Can be used
- * in either the {@link Rule} or {@link ClassRule} positions. Built on top of
an instance of
- * {@link HBaseTestingUtil}, so be weary of intermixing direct use of that
class with this Rule.
- * </p>
- * Use in combination with {@link ConnectionRule}, for example:
- *
- * <pre>
- * {
- * @code
- * public class TestMyClass {
- * @ClassRule
- * public static final MiniClusterRule miniClusterRule =
MiniClusterRule.newBuilder().build();
- *
- * @Rule
- * public final ConnectionRule connectionRule =
- *
ConnectionRule.createAsyncConnectionRule(miniClusterRule::createAsyncConnection);
- * }
- * }
- * </pre>
- *
- * @deprecated Use {@link MiniClusterExtension} instead, Once we finish the
migration of JUnit5,
- * which means we do not need {@link MiniClusterRule} any more, we
can remove these
- * dependencies, see
- * <a
href="https://issues.apache.org/jira/browse/HBASE-23671">HBASE-23671</a> for
more
- * details.
- */
-@Deprecated
-public final class MiniClusterRule extends ExternalResource {
-
- /**
- * A builder for fluent composition of a new {@link MiniClusterRule}.
- */
- public static class Builder {
-
- private StartTestingClusterOption miniClusterOption;
- private Configuration conf;
-
- /**
- * Use the provided {@link StartTestingClusterOption} to construct the
- * {@link SingleProcessHBaseCluster}.
- */
- public Builder setMiniClusterOption(final StartTestingClusterOption
miniClusterOption) {
- this.miniClusterOption = miniClusterOption;
- return this;
- }
-
- /**
- * Seed the underlying {@link HBaseTestingUtil} with the provided {@link
Configuration}.
- */
- public Builder setConfiguration(final Configuration conf) {
- this.conf = conf;
- return this;
- }
-
- public Builder setConfiguration(Supplier<Configuration> supplier) {
- return setConfiguration(supplier.get());
- }
-
- public MiniClusterRule build() {
- return new MiniClusterRule(conf,
- miniClusterOption != null
- ? miniClusterOption
- : StartTestingClusterOption.builder().build());
- }
- }
-
- private final HBaseTestingUtil testingUtility;
- private final StartTestingClusterOption miniClusterOptions;
-
- private SingleProcessHBaseCluster miniCluster;
-
- private MiniClusterRule(final Configuration conf,
- final StartTestingClusterOption miniClusterOptions) {
- this.testingUtility = new HBaseTestingUtil(conf);
- this.miniClusterOptions = miniClusterOptions;
- }
-
- public static Builder newBuilder() {
- return new Builder();
- }
-
- /**
- * Returns the underlying instance of {@link HBaseTestingUtil}
- */
- public HBaseTestingUtil getTestingUtility() {
- return testingUtility;
- }
-
- /**
- * Create a {@link Connection} to the managed {@link
SingleProcessHBaseCluster}. It's up to the
- * caller to {@link Connection#close() close()} the connection when finished.
- */
- public Connection createConnection() {
- try {
- return createAsyncConnection().get().toConnection();
- } catch (InterruptedException | ExecutionException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Create a {@link AsyncConnection} to the managed {@link
SingleProcessHBaseCluster}. It's up to
- * the caller to {@link AsyncConnection#close() close()} the connection when
finished.
- */
- public CompletableFuture<AsyncConnection> createAsyncConnection() {
- if (miniCluster == null) {
- throw new IllegalStateException("test cluster not initialized");
- }
- return ConnectionFactory.createAsyncConnection(miniCluster.getConf());
- }
-
- @Override
- protected void before() throws Throwable {
- miniCluster = testingUtility.startMiniCluster(miniClusterOptions);
- }
-
- @Override
- protected void after() {
- try {
- testingUtility.shutdownMiniCluster();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java
deleted file mode 100644
index 961bc83763f..00000000000
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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 static org.junit.Assert.assertTrue;
-
-import java.util.List;
-import org.apache.hadoop.hbase.testclassification.MiscTests;
-import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-/**
- * Checks tests are categorized.
- * <p>
- * @deprecated Will be removed after we fully upgrade to junit5, so keep it as
is.
- */
-@Deprecated
-@Category({ MiscTests.class, SmallTests.class })
-public class TestCheckTestClasses {
-
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCheckTestClasses.class);
-
- /**
- * Throws an assertion if we find a test class without category
(small/medium/large/integration).
- * List all the test classes without category in the assertion message.
- */
- @Test
- public void checkClasses() throws Exception {
- List<Class<?>> badClasses = new java.util.ArrayList<>();
- ClassTestFinder classFinder = new ClassTestFinder();
- for (Class<?> c : classFinder.findClasses(false)) {
- if (
- ClassTestFinder.getCategoryAnnotations(c).length == 0
- && ClassTestFinder.getTagAnnotations(c).length == 0
- ) {
- badClasses.add(c);
- }
- }
- assertTrue(
- "There are " + badClasses.size() + " test classes without category and
tag: " + badClasses,
- badClasses.isEmpty());
- }
-}
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRegionLocatorPagedScanRpcCount.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRegionLocatorPagedScanRpcCount.java
index 6c63ec7cb03..3e772d9feb5 100644
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRegionLocatorPagedScanRpcCount.java
+++
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRegionLocatorPagedScanRpcCount.java
@@ -18,7 +18,7 @@
package org.apache.hadoop.hbase.client;
import static org.apache.hadoop.hbase.util.FutureUtils.get;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
@@ -26,7 +26,6 @@ import java.lang.reflect.Proxy;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.hbase.ClientMetaTableAccessor;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionLocation;
@@ -35,11 +34,10 @@ import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
@@ -52,13 +50,10 @@ import
org.apache.hbase.thirdparty.com.google.common.io.Closeables;
* Cluster runs with {@code hbase.meta.scanner.caching = 2} so the {@code
limit > caching} branch is
* exercised cheaply with a small table (5 user regions).
*/
-@Category({ MediumTests.class, ClientTests.class })
+@Tag(MediumTests.TAG)
+@Tag(ClientTests.TAG)
public class TestRegionLocatorPagedScanRpcCount {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRegionLocatorPagedScanRpcCount.class);
-
private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
private static final TableName TABLE_NAME =
TableName.valueOf("LocatorPaged");
private static final byte[] FAMILY = Bytes.toBytes("family");
@@ -69,7 +64,7 @@ public class TestRegionLocatorPagedScanRpcCount {
private static AsyncConnection CONN;
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
UTIL.getConfiguration().setInt(HConstants.HBASE_META_SCANNER_CACHING,
META_CACHING);
UTIL.startMiniCluster(1);
@@ -85,7 +80,7 @@ public class TestRegionLocatorPagedScanRpcCount {
CONN =
ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get();
}
- @AfterClass
+ @AfterAll
public static void tearDown() throws Exception {
Closeables.close(CONN, true);
UTIL.shutdownMiniCluster();
@@ -95,7 +90,7 @@ public class TestRegionLocatorPagedScanRpcCount {
public void testSingleRpcWhenLimitWithinCaching() throws Exception {
// limit (2) <= caching (2): trivially one ScannerNext. Baseline.
int rpcs = runPagedScanAndCountRpcs(2);
- assertEquals("expected exactly one ScannerNext RPC for limit <= caching",
1, rpcs);
+ assertEquals(1, rpcs, "expected exactly one ScannerNext RPC for limit <=
caching");
}
@Test
@@ -103,8 +98,8 @@ public class TestRegionLocatorPagedScanRpcCount {
// limit (5) > caching (2): without the isPagedScan fix this would be
ceil(5/2) = 3
// ScannerNext RPCs. With the fix, getMetaScan sizes caching to limit -> 1
RPC.
int rpcs = runPagedScanAndCountRpcs(NUM_REGIONS);
- assertEquals("expected exactly one ScannerNext RPC for paged scan even
when limit > caching", 1,
- rpcs);
+ assertEquals(1, rpcs,
+ "expected exactly one ScannerNext RPC for paged scan even when limit >
caching");
}
@Test
@@ -120,10 +115,9 @@ public class TestRegionLocatorPagedScanRpcCount {
get(ClientMetaTableAccessor.getTableHRegionLocations(metaTable,
TABLE_NAME));
assertEquals(NUM_REGIONS, all.size());
int rpcs = onNextCalls.get();
- assertEquals(
+ assertEquals((int) Math.ceil((double) NUM_REGIONS / META_CACHING), rpcs,
"unbounded scan should still split across "
- + "ceil(NUM_REGIONS / caching) ScannerNext batches; got " + rpcs,
- (int) Math.ceil((double) NUM_REGIONS / META_CACHING), rpcs);
+ + "ceil(NUM_REGIONS / caching) ScannerNext batches; got " + rpcs);
}
private int runPagedScanAndCountRpcs(int limit) throws Exception {
@@ -131,7 +125,7 @@ public class TestRegionLocatorPagedScanRpcCount {
AsyncTable<AdvancedScanResultConsumer> metaTable =
wrapMetaTable(onNextCalls);
List<HRegionLocation> page =
get(ClientMetaTableAccessor.getTableHRegionLocations(metaTable,
TABLE_NAME, null, limit));
- assertEquals("paged call returned wrong number of regions", limit,
page.size());
+ assertEquals(limit, page.size(), "paged call returned wrong number of
regions");
return onNextCalls.get();
}
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCacheRefCnt.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCacheRefCnt.java
index 08e7e8ea69e..b466719136c 100644
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCacheRefCnt.java
+++
b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCacheRefCnt.java
@@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.nio.RefCnt;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@@ -101,7 +102,7 @@ public class TestBucketCacheRefCnt {
}
}
- @org.junit.Ignore
+ @Disabled
@Test // Disabled by HBASE-24079. Reenable issue HBASE-24082
// Flakey TestBucketCacheRefCnt.testBlockInRAMCache:121 expected:<3> but
was:<2>
public void testBlockInRAMCache() throws IOException {
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/QosTestBase.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/QosTestBase.java
index 192ac6d0b8a..f2dba9f7dbb 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/QosTestBase.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/QosTestBase.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.ipc;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.security.User;
@@ -37,7 +37,7 @@ public class QosTestBase {
final AnnotationReadingPriorityFunction<?> qosf, final Message param) {
RPCProtos.RequestHeader.Builder builder =
RPCProtos.RequestHeader.newBuilder();
builder.setMethodName(methodName);
- assertEquals(methodName, expected, qosf.getPriority(builder.build(), param,
- User.createUserForTesting(conf, "someuser", new String[] { "somegroup"
})));
+ assertEquals(expected, qosf.getPriority(builder.build(), param,
+ User.createUserForTesting(conf, "someuser", new String[] { "somegroup"
})), methodName);
}
}
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/MobStressToolRunner.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/MobStressToolRunner.java
index ec1a567591c..0d485ae8c96 100644
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/MobStressToolRunner.java
+++
b/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/MobStressToolRunner.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.mob;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.Arrays;
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/AbstractTestDateTieredCompactionPolicy.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/AbstractTestDateTieredCompactionPolicy.java
index 48a4e7b2984..f5226411163 100644
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/AbstractTestDateTieredCompactionPolicy.java
+++
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/AbstractTestDateTieredCompactionPolicy.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.regionserver;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.ArrayList;
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/trace/OpenTelemetryClassRule.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/trace/OpenTelemetryClassRule.java
deleted file mode 100644
index 7b5455f2011..00000000000
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/trace/OpenTelemetryClassRule.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.trace;
-
-import io.opentelemetry.api.GlobalOpenTelemetry;
-import io.opentelemetry.api.OpenTelemetry;
-import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
-import io.opentelemetry.context.propagation.ContextPropagators;
-import io.opentelemetry.sdk.OpenTelemetrySdk;
-import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter;
-import io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule;
-import io.opentelemetry.sdk.trace.SdkTracerProvider;
-import io.opentelemetry.sdk.trace.data.SpanData;
-import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
-import java.util.List;
-import org.junit.rules.ExternalResource;
-
-/**
- * <p>
- * Like {@link OpenTelemetryRule}, except modeled after the junit5
implementation
- * {@code OpenTelemetryExtension}. Use this class when you need to make
asserts on {@link SpanData}
- * created on a MiniCluster. Make sure this rule initialized before the
MiniCluster so that it can
- * register its instance of {@link OpenTelemetry} as the global instance
before any server-side
- * component can call {@link TraceUtil#getGlobalTracer()}.
- * </p>
- * <p>
- * For example:
- * </p>
- *
- * <pre>
- * {
- * @code
- * public class TestMyClass {
- * private static final OpenTelemetryClassRule otelClassRule =
OpenTelemetryClassRule.create();
- * private static final MiniClusterRule miniClusterRule =
MiniClusterRule.newBuilder().build();
- * protected static final ConnectionRule connectionRule =
- *
ConnectionRule.createAsyncConnectionRule(miniClusterRule::createAsyncConnection);
- *
- * @ClassRule
- * public static final TestRule classRule =
- *
RuleChain.outerRule(otelClassRule).around(miniClusterRule).around(connectionRule);
- *
- * @Rule
- * public final OpenTelemetryTestRule otelTestRule = new
OpenTelemetryTestRule(otelClassRule);
- *
- * @Test
- * public void myTest() {
- * // ...
- * // do something that makes spans
- * final List<SpanData> spans = otelClassRule.getSpans();
- * // make assertions on them
- * }
- * }
- * }
- * </pre>
- *
- * @see <a href=
- *
"https://github.com/open-telemetry/opentelemetry-java/blob/9a330d0/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/junit5/OpenTelemetryExtension.java">junit5/OpenTelemetryExtension.java</a>
- */
-public final class OpenTelemetryClassRule extends ExternalResource {
-
- public static OpenTelemetryClassRule create() {
- InMemorySpanExporter spanExporter = InMemorySpanExporter.create();
-
- SdkTracerProvider tracerProvider = SdkTracerProvider.builder()
- .addSpanProcessor(SimpleSpanProcessor.create(spanExporter)).build();
-
- OpenTelemetrySdk openTelemetry = OpenTelemetrySdk.builder()
-
.setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance()))
- .setTracerProvider(tracerProvider).build();
-
- return new OpenTelemetryClassRule(openTelemetry, spanExporter);
- }
-
- private final OpenTelemetrySdk openTelemetry;
- private final InMemorySpanExporter spanExporter;
-
- private OpenTelemetryClassRule(final OpenTelemetrySdk openTelemetry,
- final InMemorySpanExporter spanExporter) {
- this.openTelemetry = openTelemetry;
- this.spanExporter = spanExporter;
- }
-
- /** Returns the {@link OpenTelemetry} created by this Rule. */
- public OpenTelemetry getOpenTelemetry() {
- return openTelemetry;
- }
-
- /** Returns all the exported {@link SpanData} so far. */
- public List<SpanData> getSpans() {
- return spanExporter.getFinishedSpanItems();
- }
-
- /**
- * Clears the collected exported {@link SpanData}.
- */
- public void clearSpans() {
- spanExporter.reset();
- }
-
- @Override
- protected void before() throws Throwable {
- GlobalOpenTelemetry.resetForTest();
- GlobalOpenTelemetry.set(openTelemetry);
- }
-
- @Override
- protected void after() {
- GlobalOpenTelemetry.resetForTest();
- }
-}
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/trace/OpenTelemetryTestRule.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/trace/OpenTelemetryTestRule.java
deleted file mode 100644
index a51dc2eff45..00000000000
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/trace/OpenTelemetryTestRule.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.trace;
-
-import org.junit.rules.ExternalResource;
-
-/**
- * Used alongside {@link OpenTelemetryClassRule}. See that class's javadoc for
details on when to
- * use these classes instead of {@link
io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule} and an
- * example of how to use these classes together.
- */
-public final class OpenTelemetryTestRule extends ExternalResource {
-
- private final OpenTelemetryClassRule classRuleSupplier;
-
- public OpenTelemetryTestRule(final OpenTelemetryClassRule classRule) {
- this.classRuleSupplier = classRule;
- }
-
- @Override
- protected void before() throws Throwable {
- classRuleSupplier.clearSpans();
- }
-}
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/HFileArchiveTestingUtil.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/HFileArchiveTestingUtil.java
index 3aa247c0632..07add0667b0 100644
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/HFileArchiveTestingUtil.java
+++
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/HFileArchiveTestingUtil.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.IOException;
import java.util.ArrayList;
@@ -115,8 +115,8 @@ public class HFileArchiveTestingUtil {
// check the backed up files versus the current (should match up, less the
// backup time in the name)
- assertEquals("Didn't expect any backup files, but got: " + backedup,
hasTimedBackup,
- backedup.size() > 0);
+ assertEquals(hasTimedBackup, backedup.size() > 0,
+ "Didn't expect any backup files, but got: " + backedup);
String msg = null;
if (hasTimedBackup) {
assertArchiveEquality(original, backedup);
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/HFileTestUtil.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/HFileTestUtil.java
index 8f5e660f1f7..e508e4964a8 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/HFileTestUtil.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/HFileTestUtil.java
@@ -18,8 +18,8 @@
package org.apache.hadoop.hbase.util;
import static
org.apache.hadoop.hbase.regionserver.HStoreFile.BULKLOAD_TIME_KEY;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.util.Locale;
@@ -147,7 +147,7 @@ public class HFileTestUtil {
}
Tag t = tag.get();
byte[] tval = Tag.cloneValue(t);
- assertArrayEquals(c.toString() + " has tag" + Bytes.toString(tval),
r.getRow(), tval);
+ assertArrayEquals(r.getRow(), tval, c.toString() + " has tag" +
Bytes.toString(tval));
}
}
}
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestServerHttpUtils.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestServerHttpUtils.java
index a69971e1f36..aff65053b86 100644
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestServerHttpUtils.java
+++
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestServerHttpUtils.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.BufferedReader;
import java.io.IOException;
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/HbckTestingUtil.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/HbckTestingUtil.java
index 41e98464bfd..7923b0e865f 100644
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/HbckTestingUtil.java
+++
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/HbckTestingUtil.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.util.hbck;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.ArrayList;
diff --git a/hbase-shaded/hbase-shaded-check-invariants/pom.xml
b/hbase-shaded/hbase-shaded-check-invariants/pom.xml
index 51afd3a5b00..8668efd27ee 100644
--- a/hbase-shaded/hbase-shaded-check-invariants/pom.xml
+++ b/hbase-shaded/hbase-shaded-check-invariants/pom.xml
@@ -84,11 +84,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>provided</scope>
- </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
diff --git a/hbase-shaded/hbase-shaded-testing-util-tester/pom.xml
b/hbase-shaded/hbase-shaded-testing-util-tester/pom.xml
index 97950ed9f2d..40c26684f4f 100644
--- a/hbase-shaded/hbase-shaded-testing-util-tester/pom.xml
+++ b/hbase-shaded/hbase-shaded-testing-util-tester/pom.xml
@@ -48,11 +48,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-logging</artifactId>
diff --git
a/hbase-shaded/hbase-shaded-testing-util-tester/src/test/java/org/apache/hbase/shaded/TestShadedHBaseTestingUtility.java
b/hbase-shaded/hbase-shaded-testing-util-tester/src/test/java/org/apache/hbase/shaded/TestShadedHBaseTestingUtility.java
index 6bff222a8a2..11fd9f98236 100644
---
a/hbase-shaded/hbase-shaded-testing-util-tester/src/test/java/org/apache/hbase/shaded/TestShadedHBaseTestingUtility.java
+++
b/hbase-shaded/hbase-shaded-testing-util-tester/src/test/java/org/apache/hbase/shaded/TestShadedHBaseTestingUtility.java
@@ -17,9 +17,8 @@
*/
package org.apache.hbase.shaded;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Put;
@@ -27,26 +26,23 @@ import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ ClientTests.class, MediumTests.class })
+@Tag(ClientTests.TAG)
+@Tag(MediumTests.TAG)
public class TestShadedHBaseTestingUtility {
- private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestShadedHBaseTestingUtility.class);
+ private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
TEST_UTIL.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void tearDown() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
diff --git a/hbase-shaded/hbase-shaded-with-hadoop-check-invariants/pom.xml
b/hbase-shaded/hbase-shaded-with-hadoop-check-invariants/pom.xml
index bc77916b632..a09b93eb2c2 100644
--- a/hbase-shaded/hbase-shaded-with-hadoop-check-invariants/pom.xml
+++ b/hbase-shaded/hbase-shaded-with-hadoop-check-invariants/pom.xml
@@ -74,11 +74,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>provided</scope>
- </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
diff --git
a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftHttpServerBase.java
b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftHttpServerBase.java
index 2f90c39bfc7..f313e5f463e 100644
---
a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftHttpServerBase.java
+++
b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftHttpServerBase.java
@@ -21,7 +21,6 @@ import static
org.apache.hadoop.hbase.thrift.TestThriftServerCmdLine.createBound
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.net.HttpURLConnection;
@@ -40,7 +39,6 @@ import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.THttpClient;
import org.apache.thrift.transport.TTransportException;
import org.junit.jupiter.api.Test;
-import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -73,21 +71,11 @@ public class TestThriftHttpServerBase {
Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
conf.set("hbase.thrift.security.qop", "privacy");
conf.setBoolean("hbase.thrift.ssl.enabled", false);
- ExpectedException thrown = ExpectedException.none();
- ThriftServerRunner tsr = null;
- try {
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage(
- "Thrift HTTP Server's QoP is privacy, " + "but
hbase.thrift.ssl.enabled is false");
- tsr = TestThriftServerCmdLine.createBoundServer(() -> new
ThriftServer(conf));
- fail("Thrift HTTP Server starts up even with wrong security
configurations.");
- } catch (Exception e) {
- LOG.info("Expected!", e);
- } finally {
- if (tsr != null) {
- tsr.close();
- }
- }
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
+ () -> TestThriftServerCmdLine.createBoundServer(() -> new
ThriftServer(conf)),
+ "Thrift HTTP Server starts up even with wrong security configurations.");
+ assertEquals("Thrift HTTP Server's QoP is privacy, but
hbase.thrift.ssl.enabled is false",
+ e.getMessage());
}
@Test
diff --git
a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
index 108e5fece94..76f0dfba73a 100644
---
a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
+++
b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
@@ -132,6 +132,7 @@ import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
@@ -773,7 +774,7 @@ public class TestThriftHBaseServiceHandler {
* Tests keeping a HBase scanner alive for long periods of time. Each call
to getScannerRow()
* should reset the ConnectionCache timeout for the scanner's connection.
*/
- @org.junit.Ignore
+ @Disabled
@Test // Flakey. Diasabled by HBASE-24079. Renable with Fails with
HBASE-24083.
// Caused by: java.util.concurrent.RejectedExecutionException:
// Task
org.apache.hadoop.hbase.client.ResultBoundedCompletionService$QueueingFuture@e385431
diff --git a/pom.xml b/pom.xml
index bb92845f79c..6baa95159fc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -843,7 +843,6 @@
<tomcat.jasper.version>9.0.110</tomcat.jasper.version>
<jruby.version>9.4.14.0</jruby.version>
<junit.jupiter.version>5.13.4</junit.jupiter.version>
- <junit.vintage.version>5.13.4</junit.vintage.version>
<awaitility.version>4.3.0</awaitility.version>
<hamcrest.version>1.3</hamcrest.version>
<opentelemetry.version>1.49.0</opentelemetry.version>
@@ -1602,28 +1601,11 @@
</exclusions>
</dependency>
<dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-api</artifactId>
+ <groupId>org.junit</groupId>
+ <artifactId>junit-bom</artifactId>
<version>${junit.jupiter.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <version>${junit.jupiter.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-params</artifactId>
- <version>${junit.jupiter.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <version>${junit.vintage.version}</version>
- <scope>test</scope>
+ <type>pom</type>
+ <scope>import</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
@@ -2486,6 +2468,24 @@
</rules>
</configuration>
</execution>
+ <execution>
+ <id>banned-junit4</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <bannedDependencies>
+ <excludes>
+ <exclude>junit:junit</exclude>
+ <exclude>org.junit.vintage:*</exclude>
+ </excludes>
+ <message>Use junit5 instead</message>
+ <searchTransitive>true</searchTransitive>
+ </bannedDependencies>
+ </rules>
+ </configuration>
+ </execution>
<execution>
<id>check-aggregate-license</id>
<goals>
@@ -2656,7 +2656,7 @@
<restrictImports
implementation="de.skuzzle.enforcer.restrictimports.rule.RestrictImports">
<includeTestCode>true</includeTestCode>
<commentLineBufferSize>512</commentLineBufferSize>
- <reason>Use junit4 instead</reason>
+ <reason>Use junit5 instead</reason>
<bannedImports>
<bannedImport>junit.framework.**</bannedImport>
</bannedImports>
@@ -4114,6 +4114,10 @@
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>