bharathv commented on a change in pull request #1057: HBASE-23701 Try to 
converge automated checks around Category
URL: https://github.com/apache/hbase/pull/1057#discussion_r367665168
 
 

 ##########
 File path: 
hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRule.java
 ##########
 @@ -59,13 +59,20 @@ private HBaseClassTestRule(Class<?> clazz, Timeout 
timeout) {
 
   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);
+    // This should never happen
+    if (categories.length > 1) {
+      throw new IllegalArgumentException("Code-bug: unsure how to handle more 
than one Category");
 
 Review comment:
   It appears that Category is not a repeatable annotation [1]. There are 
compile time checks for this.  I think the whole block of code can be 
simplified to something like.
   
   ```
   Preconditions.checkArgument(categories.length == 1, "Invalid number of 
categories found for class " + clazz + " Required 1: found: " + 
categories.length. Include one of ...");
    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);
           }
         }
   }
   ```
    
   
   [1] https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to