This is an automated email from the ASF dual-hosted git repository. elserj pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push: new df8f80a HBASE-23701 Try to converge automated checks around Category df8f80a is described below commit df8f80a8198d1dde5e235749a65d83483e3f6dac Author: Josh Elser <els...@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 <vjas...@apache.org> Signed-off-by: Bharath Vissapragada <bhara...@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 45884eb..d38b36f 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;