You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by jg...@apache.org on 2010/10/08 21:21:42 UTC

svn commit: r1005977 - in /hadoop/common/trunk: CHANGES.txt src/test/core/org/apache/hadoop/test/UnitTestcaseTimeLimit.java src/test/core/org/apache/hadoop/util/TestStringUtils.java

Author: jghoman
Date: Fri Oct  8 19:21:42 2010
New Revision: 1005977

URL: http://svn.apache.org/viewvc?rev=1005977&view=rev
Log:
HADOOP-6987. Use JUnit Rule to optionally fail test cases that run more than 10 seconds.

Added:
    hadoop/common/trunk/src/test/core/org/apache/hadoop/test/UnitTestcaseTimeLimit.java
Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestStringUtils.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=1005977&r1=1005976&r2=1005977&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Fri Oct  8 19:21:42 2010
@@ -136,6 +136,9 @@ Trunk (unreleased changes)
 
     HADOOP-6856. Simplify constructors for SequenceFile, and MapFile. (omalley)
 
+    HADOOP-6987. Use JUnit Rule to optionally fail test cases that run more
+    than 10 seconds (jghoman)
+
   OPTIMIZATIONS
 
     HADOOP-6884. Add LOG.isDebugEnabled() guard for each LOG.debug(..).

Added: hadoop/common/trunk/src/test/core/org/apache/hadoop/test/UnitTestcaseTimeLimit.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/test/UnitTestcaseTimeLimit.java?rev=1005977&view=auto
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/test/UnitTestcaseTimeLimit.java (added)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/test/UnitTestcaseTimeLimit.java Fri Oct  8 19:21:42 2010
@@ -0,0 +1,34 @@
+/**
+ * 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.test;
+
+import org.junit.Rule;
+import org.junit.rules.MethodRule;
+import org.junit.rules.Timeout;
+
+/**
+ * Class for test units to extend in order that their individual tests will
+ * be timed out and fail automatically should they run more than 10 seconds.
+ * This provides an automatic regression check for tests that begin running
+ * longer than expected.
+ */
+public class UnitTestcaseTimeLimit {
+  public final int timeOutSecs = 10;
+  
+  @Rule public MethodRule globalTimeout = new Timeout(timeOutSecs * 1000);
+}

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestStringUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestStringUtils.java?rev=1005977&r1=1005976&r2=1005977&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestStringUtils.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestStringUtils.java Fri Oct  8 19:21:42 2010
@@ -18,13 +18,17 @@
 
 package org.apache.hadoop.util;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
 import java.util.ArrayList;
 import java.util.List;
 
-import junit.framework.TestCase;
-import static org.junit.Assert.assertArrayEquals;
+import org.apache.hadoop.test.UnitTestcaseTimeLimit;
+import org.junit.Test;
 
-public class TestStringUtils extends TestCase {
+public class TestStringUtils extends UnitTestcaseTimeLimit {
   final private static String NULL_STR = null;
   final private static String EMPTY_STR = "";
   final private static String STR_WO_SPECIAL_CHARS = "AB";
@@ -36,6 +40,7 @@ public class TestStringUtils extends Tes
   final private static String ESCAPED_STR_WITH_BOTH2 = 
     "\\,A\\\\\\,\\,B\\\\\\\\\\,";
   
+  @Test
   public void testEscapeString() throws Exception {
     assertEquals(NULL_STR, StringUtils.escapeString(NULL_STR));
     assertEquals(EMPTY_STR, StringUtils.escapeString(EMPTY_STR));
@@ -49,6 +54,7 @@ public class TestStringUtils extends Tes
         StringUtils.escapeString(STR_WITH_BOTH2));
   }
   
+  @Test
   public void testSplit() throws Exception {
     assertEquals(NULL_STR, StringUtils.split(NULL_STR));
     String[] splits = StringUtils.split(EMPTY_STR);
@@ -78,6 +84,7 @@ public class TestStringUtils extends Tes
     assertEquals(ESCAPED_STR_WITH_BOTH2, splits[0]);    
   }
   
+  @Test
   public void testSimpleSplit() throws Exception {
     final String[] TO_TEST = {
         "a/b/c",
@@ -93,6 +100,7 @@ public class TestStringUtils extends Tes
     }
   }
 
+  @Test
   public void testUnescapeString() throws Exception {
     assertEquals(NULL_STR, StringUtils.unEscapeString(NULL_STR));
     assertEquals(EMPTY_STR, StringUtils.unEscapeString(EMPTY_STR));
@@ -124,6 +132,7 @@ public class TestStringUtils extends Tes
         StringUtils.unEscapeString(ESCAPED_STR_WITH_BOTH2));
   }
   
+  @Test
   public void testTraditionalBinaryPrefix() throws Exception {
     String[] symbol = {"k", "m", "g", "t", "p", "e"};
     long m = 1024;
@@ -138,6 +147,7 @@ public class TestStringUtils extends Tes
     assertEquals(956703965184L, StringUtils.TraditionalBinaryPrefix.string2long("891g"));
   }
 
+  @Test
   public void testJoin() {
     List<String> s = new ArrayList<String>();
     s.add("a");
@@ -149,6 +159,7 @@ public class TestStringUtils extends Tes
     assertEquals("a:b:c", StringUtils.join(":", s.subList(0, 3)));
   }
   
+  @Test
   public void testGetTrimmedStrings() throws Exception {
     String compactDirList = "/spindle1/hdfs,/spindle2/hdfs,/spindle3/hdfs";
     String spacedDirList = "/spindle1/hdfs, /spindle2/hdfs, /spindle3/hdfs";
@@ -169,6 +180,7 @@ public class TestStringUtils extends Tes
     assertArrayEquals(emptyArray, StringUtils.getTrimmedStrings(emptyList2));
   } 
 
+  @Test
   public void testCamelize() {
     // common use cases
     assertEquals("Map", StringUtils.camelize("MAP"));