Repository: hbase
Updated Branches:
  refs/heads/branch-1 585f8fa8a -> 95682e7b7


HBASE-13127 Add timeouts on all tests so less zombie sightings


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/95682e7b
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/95682e7b
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/95682e7b

Branch: refs/heads/branch-1
Commit: 95682e7b7db60b123d73dfa362de05d9ab1ec3dc
Parents: 585f8fa
Author: stack <[email protected]>
Authored: Mon Aug 24 13:37:45 2015 -0700
Committer: stack <[email protected]>
Committed: Mon Aug 24 13:38:03 2015 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/CategoryBasedTimeout.java      | 77 ++++++++++++++++++++
 .../org/apache/hadoop/hbase/TestTimeout.java    | 48 ++++++++++++
 pom.xml                                         |  2 +-
 3 files changed, 126 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/95682e7b/hbase-common/src/test/java/org/apache/hadoop/hbase/CategoryBasedTimeout.java
----------------------------------------------------------------------
diff --git 
a/hbase-common/src/test/java/org/apache/hadoop/hbase/CategoryBasedTimeout.java 
b/hbase-common/src/test/java/org/apache/hadoop/hbase/CategoryBasedTimeout.java
new file mode 100644
index 0000000..f921b1b
--- /dev/null
+++ 
b/hbase-common/src/test/java/org/apache/hadoop/hbase/CategoryBasedTimeout.java
@@ -0,0 +1,77 @@
+/*
+ * 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.lang.annotation.Annotation;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hadoop.hbase.testclassification.LargeTests;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.experimental.categories.Category;
+import org.junit.internal.runners.statements.FailOnTimeout;
+import org.junit.rules.TestRule;
+import org.junit.rules.Timeout;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/**
+ * Set 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
+ */
+public class CategoryBasedTimeout extends Timeout {
+
+  @Deprecated
+  public CategoryBasedTimeout(int millis) {
+    super(millis);
+  }
+
+  public CategoryBasedTimeout(long timeout, TimeUnit timeUnit) {
+    super(timeout, timeUnit);
+  }
+
+  protected CategoryBasedTimeout(Builder builder) {
+    super(builder);
+  }
+
+  public static Builder builder() {
+    return new CategoryBasedTimeout.Builder();
+  }
+
+  public static class Builder extends Timeout.Builder {
+    public Timeout.Builder withTimeout(Class<?> clazz) {
+      Annotation annotation = clazz.getAnnotation(Category.class);
+      if (annotation != null) {
+        Category category = (Category)annotation;
+        for (Class<?> c: category.value()) {
+          if (c == SmallTests.class) {
+            // See SmallTests. Supposed to run 15 seconds.
+            return withTimeout(30, TimeUnit.SECONDS);
+          } else if (c == MediumTests.class) {
+            // See MediumTests. Supposed to run 50 seconds.
+            return withTimeout(180, TimeUnit.SECONDS);
+          } else if (c == LargeTests.class) {
+            // Let large tests have a ten minute timeout.
+            return withTimeout(10, TimeUnit.MINUTES);
+          }
+        }
+      }
+      return this;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/95682e7b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java
----------------------------------------------------------------------
diff --git 
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java 
b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java
new file mode 100644
index 0000000..d6ee673
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java
@@ -0,0 +1,48 @@
+/*
+ * 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.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.Rule;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestRule;
+import org.junit.rules.Timeout;
+
+@Category({SmallTests.class})
+public class TestTimeout {
+  @Rule public final TestRule timeout = CategoryBasedTimeout.builder()
+      .withTimeout(this.getClass())
+      .withLookingForStuckThread(true)
+      .build();
+
+    @Test
+    public void run1() throws InterruptedException {
+        Thread.sleep(100);
+    }
+
+    /**
+     * Enable to check if timeout works.
+     * Can't enable as it waits 30seconds and expected doesn't do Exception 
catching
+     */
+    @Ignore @Test
+    public void infiniteLoop() {
+        while (true) {}
+   }
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/95682e7b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index c09c190..326aa90 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1159,7 +1159,7 @@
     <jersey.version>1.9</jersey.version>
     <jmock-junit4.version>2.6.0</jmock-junit4.version>
     <jruby.version>1.6.8</jruby.version>
-    <junit.version>4.11</junit.version>
+    <junit.version>4.12</junit.version>
     <hamcrest.version>1.3</hamcrest.version>
     <htrace.version>3.1.0-incubating</htrace.version>
     <log4j.version>1.2.17</log4j.version>

Reply via email to