HADOOP-6987. Use JUnit Rule to optionally fail test cases that run more than 10 seconds.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1005977 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a503521a2c
commit
5fe802ea0a
|
@ -136,6 +136,9 @@ Trunk (unreleased changes)
|
||||||
|
|
||||||
HADOOP-6856. Simplify constructors for SequenceFile, and MapFile. (omalley)
|
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
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HADOOP-6884. Add LOG.isDebugEnabled() guard for each LOG.debug(..).
|
HADOOP-6884. Add LOG.isDebugEnabled() guard for each LOG.debug(..).
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -18,13 +18,17 @@
|
||||||
|
|
||||||
package org.apache.hadoop.util;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.apache.hadoop.test.UnitTestcaseTimeLimit;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
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 NULL_STR = null;
|
||||||
final private static String EMPTY_STR = "";
|
final private static String EMPTY_STR = "";
|
||||||
final private static String STR_WO_SPECIAL_CHARS = "AB";
|
final private static String STR_WO_SPECIAL_CHARS = "AB";
|
||||||
|
@ -36,6 +40,7 @@ public class TestStringUtils extends TestCase {
|
||||||
final private static String ESCAPED_STR_WITH_BOTH2 =
|
final private static String ESCAPED_STR_WITH_BOTH2 =
|
||||||
"\\,A\\\\\\,\\,B\\\\\\\\\\,";
|
"\\,A\\\\\\,\\,B\\\\\\\\\\,";
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEscapeString() throws Exception {
|
public void testEscapeString() throws Exception {
|
||||||
assertEquals(NULL_STR, StringUtils.escapeString(NULL_STR));
|
assertEquals(NULL_STR, StringUtils.escapeString(NULL_STR));
|
||||||
assertEquals(EMPTY_STR, StringUtils.escapeString(EMPTY_STR));
|
assertEquals(EMPTY_STR, StringUtils.escapeString(EMPTY_STR));
|
||||||
|
@ -49,6 +54,7 @@ public class TestStringUtils extends TestCase {
|
||||||
StringUtils.escapeString(STR_WITH_BOTH2));
|
StringUtils.escapeString(STR_WITH_BOTH2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSplit() throws Exception {
|
public void testSplit() throws Exception {
|
||||||
assertEquals(NULL_STR, StringUtils.split(NULL_STR));
|
assertEquals(NULL_STR, StringUtils.split(NULL_STR));
|
||||||
String[] splits = StringUtils.split(EMPTY_STR);
|
String[] splits = StringUtils.split(EMPTY_STR);
|
||||||
|
@ -78,6 +84,7 @@ public class TestStringUtils extends TestCase {
|
||||||
assertEquals(ESCAPED_STR_WITH_BOTH2, splits[0]);
|
assertEquals(ESCAPED_STR_WITH_BOTH2, splits[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleSplit() throws Exception {
|
public void testSimpleSplit() throws Exception {
|
||||||
final String[] TO_TEST = {
|
final String[] TO_TEST = {
|
||||||
"a/b/c",
|
"a/b/c",
|
||||||
|
@ -93,6 +100,7 @@ public class TestStringUtils extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testUnescapeString() throws Exception {
|
public void testUnescapeString() throws Exception {
|
||||||
assertEquals(NULL_STR, StringUtils.unEscapeString(NULL_STR));
|
assertEquals(NULL_STR, StringUtils.unEscapeString(NULL_STR));
|
||||||
assertEquals(EMPTY_STR, StringUtils.unEscapeString(EMPTY_STR));
|
assertEquals(EMPTY_STR, StringUtils.unEscapeString(EMPTY_STR));
|
||||||
|
@ -124,6 +132,7 @@ public class TestStringUtils extends TestCase {
|
||||||
StringUtils.unEscapeString(ESCAPED_STR_WITH_BOTH2));
|
StringUtils.unEscapeString(ESCAPED_STR_WITH_BOTH2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTraditionalBinaryPrefix() throws Exception {
|
public void testTraditionalBinaryPrefix() throws Exception {
|
||||||
String[] symbol = {"k", "m", "g", "t", "p", "e"};
|
String[] symbol = {"k", "m", "g", "t", "p", "e"};
|
||||||
long m = 1024;
|
long m = 1024;
|
||||||
|
@ -138,6 +147,7 @@ public class TestStringUtils extends TestCase {
|
||||||
assertEquals(956703965184L, StringUtils.TraditionalBinaryPrefix.string2long("891g"));
|
assertEquals(956703965184L, StringUtils.TraditionalBinaryPrefix.string2long("891g"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJoin() {
|
public void testJoin() {
|
||||||
List<String> s = new ArrayList<String>();
|
List<String> s = new ArrayList<String>();
|
||||||
s.add("a");
|
s.add("a");
|
||||||
|
@ -149,6 +159,7 @@ public class TestStringUtils extends TestCase {
|
||||||
assertEquals("a:b:c", StringUtils.join(":", s.subList(0, 3)));
|
assertEquals("a:b:c", StringUtils.join(":", s.subList(0, 3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetTrimmedStrings() throws Exception {
|
public void testGetTrimmedStrings() throws Exception {
|
||||||
String compactDirList = "/spindle1/hdfs,/spindle2/hdfs,/spindle3/hdfs";
|
String compactDirList = "/spindle1/hdfs,/spindle2/hdfs,/spindle3/hdfs";
|
||||||
String spacedDirList = "/spindle1/hdfs, /spindle2/hdfs, /spindle3/hdfs";
|
String spacedDirList = "/spindle1/hdfs, /spindle2/hdfs, /spindle3/hdfs";
|
||||||
|
@ -169,6 +180,7 @@ public class TestStringUtils extends TestCase {
|
||||||
assertArrayEquals(emptyArray, StringUtils.getTrimmedStrings(emptyList2));
|
assertArrayEquals(emptyArray, StringUtils.getTrimmedStrings(emptyList2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCamelize() {
|
public void testCamelize() {
|
||||||
// common use cases
|
// common use cases
|
||||||
assertEquals("Map", StringUtils.camelize("MAP"));
|
assertEquals("Map", StringUtils.camelize("MAP"));
|
||||||
|
|
Loading…
Reference in New Issue