commit 1f6e724699e7958c8bd0057125dcea0f001f9db1 Author: stack Date: Sat Aug 15 09:52:10 2015 -0700 HBASE-13127 Add timeouts on all tests so less zombie sightings diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java index 137bbed..2e2d45e 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java @@ -3033,7 +3033,7 @@ public final class ProtobufUtil { * @param builder current message builder * @param in InputStream containing protobuf data * @param size known size of protobuf data - * @throws IOException + * @throws IOException */ public static void mergeFrom(Message.Builder builder, InputStream in, int size) throws IOException { @@ -3048,7 +3048,7 @@ public final class ProtobufUtil { * buffers where the message size is not known * @param builder current message builder * @param in InputStream containing protobuf data - * @throws IOException + * @throws IOException */ public static void mergeFrom(Message.Builder builder, InputStream in) throws IOException { @@ -3062,8 +3062,8 @@ public final class ProtobufUtil { * This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding * buffers when working with ByteStrings * @param builder current message builder - * @param bs ByteString containing the - * @throws IOException + * @param bs ByteString containing the + * @throws IOException */ public static void mergeFrom(Message.Builder builder, ByteString bs) throws IOException { final CodedInputStream codedInput = bs.newCodedInput(); @@ -3077,7 +3077,7 @@ public final class ProtobufUtil { * buffers when working with byte arrays * @param builder current message builder * @param b byte array - * @throws IOException + * @throws IOException */ public static void mergeFrom(Message.Builder builder, byte[] b) throws IOException { final CodedInputStream codedInput = CodedInputStream.newInstance(b); @@ -3141,7 +3141,7 @@ public final class ProtobufUtil { /** * Convert SecurityCapabilitiesResponse.Capability to SecurityCapability - * @param caps capabilities returned in the SecurityCapabilitiesResponse message + * @param capabilities capabilities returned in the SecurityCapabilitiesResponse message * @return the converted list of SecurityCapability elements */ public static List toSecurityCapabilityList( 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..a3363f4 --- /dev/null +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/CategoryBasedTimeout.java @@ -0,0 +1,66 @@ +/* + * 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 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.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 implements TestRule { + private final int fMillis; + + public CategoryBasedTimeout(Class clazz) { + int timeout = Integer.MAX_VALUE; + 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. If 30 seconds, its been going on too long + timeout = 30000; + break; + } else if (c == MediumTests.class) { + // See MediumTests. Supposed to run 50 seconds. + timeout = 180000; + break; + } else if (c == LargeTests.class) { + // Let large tests have a ten minute timeout. + timeout = 600000; + break; + } + } + } + this.fMillis = timeout; + } + + @Override + public Statement apply(Statement base, Description description) { + return new FailOnTimeout(base, fMillis); + } +} 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..5def7e7 --- /dev/null +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java @@ -0,0 +1,46 @@ +/* + * 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.Test; +import org.junit.Ignore; +import org.junit.experimental.categories.Category; + +@Category({SmallTests.class}) +public class TestTimeout { + @Rule public CategoryBasedTimeout defaultGlobalTestTimeout = + new CategoryBasedTimeout(this.getClass()); + + @Test + public void run1() throws InterruptedException { + Thread.sleep(100); + } + + /** + * Should fail after 30 seconds, the timeout for small tests. + * Should throw: java.lang. test timed out after 30000 milliseconds + * Disabled. Enable to try out the timeout-by-test-category facility in + * CategoryBasedTimeout + */ + @Ignore @Test + public void infiniteLoop() { + while (true) {} + } +}