You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by el...@apache.org on 2020/01/17 18:03:26 UTC
[hbase] branch branch-2.1 updated: HBASE-23701 Try to converge
automated checks around Category
This is an automated email from the ASF dual-hosted git repository.
elserj pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 012ff54 HBASE-23701 Try to converge automated checks around Category
012ff54 is described below
commit 012ff54fdd7e065228755886404d50f1d472fb87
Author: Josh Elser <el...@apache.org>
AuthorDate: Thu Jan 16 15:57:42 2020 -0500
HBASE-23701 Try to converge automated checks around Category
We have a compile-time guarantee to either have a category array
of length zero or one because the category annotation is non-repeatable.
Also tries to clean up the checking for unit-test annotations.
Closes #1057
Signed-off-by: Viraj Jasani <vj...@apache.org>
Signed-off-by: Bharath Vissapragada <bh...@apache.org>
---
.../apache/hadoop/hbase/HBaseClassTestRule.java | 24 +++++++++++++++-------
.../hadoop/hbase/HBaseClassTestRuleChecker.java | 5 +++--
2 files changed, 20 insertions(+), 9 deletions(-)
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
index 155bd92..00374c1 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRule.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRule.java
@@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase;
+import java.util.Collections;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.testclassification.IntegrationTests;
@@ -30,6 +32,8 @@ import org.junit.rules.Timeout;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
+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.
@@ -39,6 +43,8 @@ import org.junit.runners.model.Statement;
*/
@InterfaceAudience.Private
public final class HBaseClassTestRule implements TestRule {
+ public static final Set<Class<?>> UNIT_TEST_CLASSES = Collections.unmodifiableSet(
+ Sets.<Class<?>> newHashSet(SmallTests.class, MediumTests.class, LargeTests.class));
private final Class<?> clazz;
@@ -59,13 +65,17 @@ public final class HBaseClassTestRule implements TestRule {
private static long getTimeoutInSeconds(Class<?> clazz) {
Category[] categories = clazz.getAnnotationsByType(Category.class);
- for (Class<?> c : categories[0].value()) {
- if (c == SmallTests.class || c == MediumTests.class || c == LargeTests.class) {
- // All tests have a 13 minutes timeout.
- return TimeUnit.MINUTES.toSeconds(13);
- }
- if (c == IntegrationTests.class) {
- return TimeUnit.MINUTES.toSeconds(Long.MAX_VALUE);
+
+ // @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)) {
+ // All tests have a 13 minutes timeout.
+ return TimeUnit.MINUTES.toSeconds(13);
+ }
+ if (c == IntegrationTests.class) {
+ return TimeUnit.MINUTES.toSeconds(Long.MAX_VALUE);
+ }
}
}
throw new IllegalArgumentException(
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
index 8eb0bf8..bf7412a 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRuleChecker.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRuleChecker.java
@@ -41,8 +41,9 @@ public class HBaseClassTestRuleChecker extends RunListener {
@Override
public void testStarted(Description description) throws Exception {
Category[] categories = description.getTestClass().getAnnotationsByType(Category.class);
- // Don't fail if there is a missing category
- if (categories.length > 0) {
+
+ // @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;