hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [hbase] branch branch-2.2 updated: HBASE-23701 Try to converge automated checks around Category
Date Fri, 17 Jan 2020 18:03:27 GMT
This is an automated email from the ASF dual-hosted git repository.

elserj pushed a commit to branch branch-2.2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2.2 by this push:
     new 7133504  HBASE-23701 Try to converge automated checks around Category
7133504 is described below

commit 71335045791db5c5c91777e362443b0308cdc76c
Author: Josh Elser <elserj@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 <vjasani@apache.org>
    Signed-off-by: Bharath Vissapragada <bharathv@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;


Mime
View raw message