HADOOP-14729. Upgrade JUnit 3 test cases to JUnit 4. Contributed by Ajay Kumar.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/8b7cbe38 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/8b7cbe38 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/8b7cbe38 Branch: refs/heads/trunk Commit: 8b7cbe3840f1a4f4dc038ac3018a4f0dbe3bc82d Parents: 3a4e861 Author: Arpit Agarwal <[email protected]> Authored: Fri Aug 25 09:55:46 2017 -0700 Committer: Arpit Agarwal <[email protected]> Committed: Fri Aug 25 09:55:46 2017 -0700 ---------------------------------------------------------------------- .../apache/hadoop/conf/TestConfiguration.java | 340 ++++++++++++------- .../hadoop/conf/TestConfigurationSubclass.java | 8 +- .../apache/hadoop/conf/TestDeprecatedKeys.java | 8 +- .../apache/hadoop/conf/TestGetInstances.java | 8 +- .../org/apache/hadoop/fs/TestAvroFSInput.java | 6 +- .../test/java/org/apache/hadoop/fs/TestDU.java | 19 +- .../java/org/apache/hadoop/fs/TestFilterFs.java | 8 +- .../hadoop/fs/TestGetFileBlockLocations.java | 25 +- .../org/apache/hadoop/fs/TestGlobExpander.java | 7 +- .../java/org/apache/hadoop/fs/TestTrash.java | 24 +- .../apache/hadoop/fs/TestTruncatedInputBug.java | 6 +- .../hadoop/fs/permission/TestFsPermission.java | 14 +- .../apache/hadoop/ipc/TestFairCallQueue.java | 33 +- .../org/apache/hadoop/log/TestLog4Json.java | 6 +- .../hadoop/net/TestScriptBasedMapping.java | 9 +- .../TestScriptBasedMappingWithDependency.java | 7 +- .../security/TestAuthenticationFilter.java | 6 +- .../TestAuthenticationWithProxyUserFilter.java | 7 +- .../security/TestWhitelistBasedResolver.java | 9 +- .../apache/hadoop/security/token/TestToken.java | 12 +- .../hadoop/util/TestAsyncDiskService.java | 6 +- .../apache/hadoop/util/TestCacheableIPList.java | 13 +- .../apache/hadoop/util/TestFileBasedIPList.java | 12 +- .../org/apache/hadoop/util/TestFindClass.java | 2 +- .../apache/hadoop/util/TestGenericsUtil.java | 12 +- .../org/apache/hadoop/util/TestIndexedSort.java | 7 +- .../hadoop/util/TestNativeLibraryChecker.java | 8 +- .../mapred/TestMRWithDistributedCache.java | 40 +-- .../hadoop/mapred/TestFileOutputCommitter.java | 23 +- .../apache/hadoop/mapred/TestIndexCache.java | 15 +- .../hadoop/mapred/TestJobEndNotifier.java | 12 +- .../mapreduce/TestJobMonitorAndPrint.java | 8 +- .../lib/output/TestFileOutputCommitter.java | 39 ++- .../lib/output/TestFileOutputFormat.java | 7 +- .../mapred/jobcontrol/TestJobControl.java | 6 +- .../hadoop/mapreduce/TestMapCollection.java | 6 - .../lib/input/TestDelegatingInputFormat.java | 7 +- .../lib/jobcontrol/TestMapReduceJobControl.java | 2 +- .../output/TestMRCJCFileOutputCommitter.java | 17 +- .../mapred/nativetask/TestTaskContext.java | 23 +- .../nativetask/buffer/TestInputBuffer.java | 7 +- .../nativetask/buffer/TestOutputBuffer.java | 7 +- .../nativetask/serde/TestKVSerializer.java | 13 +- .../nativetask/utils/TestReadWriteBuffer.java | 7 +- .../nativetask/utils/TestSizedWritable.java | 5 +- .../examples/TestBaileyBorweinPlouffe.java | 14 +- .../hadoop/examples/pi/math/TestLongLong.java | 33 +- .../hadoop/examples/pi/math/TestModular.java | 105 +++--- .../hadoop/examples/pi/math/TestSummation.java | 30 +- .../hadoop/contrib/utils/join/TestDataJoin.java | 41 +-- .../org/apache/hadoop/tools/TestDistCh.java | 23 +- .../typedbytes/TestTypedBytesWritable.java | 7 +- .../amfilter/TestAmFilterInitializer.java | 15 +- 53 files changed, 718 insertions(+), 416 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index 8fe88bc..b41a807 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -44,7 +44,11 @@ import java.util.regex.Pattern; import static java.util.concurrent.TimeUnit.*; import com.fasterxml.jackson.databind.ObjectMapper; -import junit.framework.TestCase; +import org.apache.hadoop.fs.CommonConfigurationKeysPublic; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; import static org.junit.Assert.assertArrayEquals; import org.apache.commons.lang.StringUtils; @@ -65,11 +69,11 @@ import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.Logger; import org.apache.log4j.spi.LoggingEvent; import org.hamcrest.CoreMatchers; -import org.junit.Assert; import org.mockito.Mockito; -public class TestConfiguration extends TestCase { +public class TestConfiguration { + private static final double DOUBLE_DELTA = 0.000000001f; private Configuration conf; final static String CONFIG = new File("./test-config-TestConfiguration.xml").getAbsolutePath(); final static String CONFIG2 = new File("./test-config2-TestConfiguration.xml").getAbsolutePath(); @@ -82,7 +86,7 @@ public class TestConfiguration extends TestCase { private static final String CONFIG_MULTI_BYTE_SAVED = new File( "./test-config-multi-byte-saved-TestConfiguration.xml").getAbsolutePath(); final static Random RAN = new Random(); - final static String XMLHEADER = + final static String XMLHEADER = IBM_JAVA?"<?xml version=\"1.0\" encoding=\"UTF-8\"?><configuration>": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><configuration>"; @@ -94,18 +98,16 @@ public class TestConfiguration extends TestCase { private BufferedWriter out; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { conf = new Configuration(); } - - @Override - protected void tearDown() throws Exception { + + @After + public void tearDown() throws Exception { if(out != null) { out.close(); } - super.tearDown(); new File(CONFIG).delete(); new File(CONFIG2).delete(); new File(CONFIG_FOR_ENUM).delete(); @@ -113,7 +115,7 @@ public class TestConfiguration extends TestCase { new File(CONFIG_MULTI_BYTE).delete(); new File(CONFIG_MULTI_BYTE_SAVED).delete(); } - + private void startConfig() throws IOException{ out.write("<?xml version=\"1.0\"?>\n"); out.write("<configuration>\n"); @@ -164,6 +166,7 @@ public class TestConfiguration extends TestCase { + " [\n<!ENTITY " + entity + " SYSTEM \"" + value + "\">\n]>"); } + @Test public void testInputStreamResource() throws Exception { StringWriter writer = new StringWriter(); out = new BufferedWriter(writer); @@ -182,6 +185,7 @@ public class TestConfiguration extends TestCase { assertEquals("A", conf.get("prop")); } + @Test public void testFinalWarnings() throws Exception { // Make a configuration file with a final property StringWriter writer = new StringWriter(); @@ -226,6 +230,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testNoFinalWarnings() throws Exception { // Make a configuration file with a final property StringWriter writer = new StringWriter(); @@ -263,6 +268,7 @@ public class TestConfiguration extends TestCase { + @Test public void testFinalWarningsMultiple() throws Exception { // Make a configuration file with a repeated final property StringWriter writer = new StringWriter(); @@ -296,6 +302,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testFinalWarningsMultipleOverride() throws Exception { // Make a configuration file with 2 final properties with different values StringWriter writer = new StringWriter(); @@ -358,6 +365,7 @@ public class TestConfiguration extends TestCase { * round-trips multi-byte string literals through saving and loading of config * and asserts that the same values were read. */ + @Test public void testMultiByteCharacters() throws IOException { String priorDefaultEncoding = System.getProperty("file.encoding"); try { @@ -388,6 +396,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testVariableSubstitution() throws IOException { // stubbing only environment dependent functions Configuration mock = Mockito.spy(conf); @@ -419,12 +428,13 @@ public class TestConfiguration extends TestCase { assertEq(p.val, gotRawVal); assertEq(p.expectEval, gotVal); } - + // check that expansion also occurs for getInt() assertTrue(mock.getInt("intvar", -1) == 42); assertTrue(mock.getInt("my.int", -1) == 42); } + @Test public void testEnvDefault() throws IOException { Configuration mock = Mockito.spy(conf); Mockito.when(mock.getenv("NULL_VALUE")).thenReturn(null); @@ -465,6 +475,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testFinalParam() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -474,7 +485,7 @@ public class TestConfiguration extends TestCase { Configuration conf1 = new Configuration(); conf1.addResource(fileResource); assertNull("my var is not null", conf1.get("my.var")); - + out=new BufferedWriter(new FileWriter(CONFIG2)); startConfig(); declareProperty("my.var", "myval", "myval", false); @@ -486,6 +497,7 @@ public class TestConfiguration extends TestCase { assertNull("my var is not final", conf2.get("my.var")); } + @Test public void testCompactFormat() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -530,8 +542,8 @@ public class TestConfiguration extends TestCase { } void declareProperty(String name, String val, String expectEval, - boolean isFinal) - throws IOException { + boolean isFinal) + throws IOException { appendProperty(name, val, isFinal); Prop p = new Prop(); p.name = name; @@ -543,10 +555,10 @@ public class TestConfiguration extends TestCase { void appendProperty(String name, String val) throws IOException { appendProperty(name, val, false); } - - void appendProperty(String name, String val, boolean isFinal, + + void appendProperty(String name, String val, boolean isFinal, String ... sources) - throws IOException { + throws IOException { out.write("<property>"); out.write("<name>"); out.write(name); @@ -564,19 +576,19 @@ public class TestConfiguration extends TestCase { } out.write("</property>\n"); } - + void appendCompactFormatProperty(String name, String val) throws IOException { appendCompactFormatProperty(name, val, false); } void appendCompactFormatProperty(String name, String val, boolean isFinal) - throws IOException { + throws IOException { appendCompactFormatProperty(name, val, isFinal, null); } void appendCompactFormatProperty(String name, String val, boolean isFinal, String source) - throws IOException { + throws IOException { out.write("<property "); out.write("name=\""); out.write(name); @@ -595,6 +607,7 @@ public class TestConfiguration extends TestCase { out.write("/>\n"); } + @Test public void testOverlay() throws IOException{ out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -610,25 +623,26 @@ public class TestConfiguration extends TestCase { appendProperty("b","d"); appendProperty("e","e"); endConfig(); - + Path fileResource = new Path(CONFIG); conf.addResource(fileResource); - + //set dynamically something conf.set("c","d"); conf.set("a","d"); - + Configuration clone=new Configuration(conf); clone.addResource(new Path(CONFIG2)); - - assertEquals(clone.get("a"), "d"); - assertEquals(clone.get("b"), "d"); - assertEquals(clone.get("c"), "d"); - assertEquals(clone.get("d"), "e"); - assertEquals(clone.get("e"), "f"); - - } - + + assertEquals(clone.get("a"), "d"); + assertEquals(clone.get("b"), "d"); + assertEquals(clone.get("c"), "d"); + assertEquals(clone.get("d"), "e"); + assertEquals(clone.get("e"), "f"); + + } + + @Test public void testCommentsInValue() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -640,6 +654,7 @@ public class TestConfiguration extends TestCase { assertEquals("this contains a comment", conf.get("my.comment")); } + @Test public void testEscapedCharactersInValue() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -651,6 +666,7 @@ public class TestConfiguration extends TestCase { assertEquals("''''", conf.get("my.comment")); } + @Test public void testTrim() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -658,13 +674,13 @@ public class TestConfiguration extends TestCase { String[] name = new String[100]; for(int i = 0; i < name.length; i++) { name[i] = "foo" + i; - StringBuilder prefix = new StringBuilder(); - StringBuilder postfix = new StringBuilder(); + StringBuilder prefix = new StringBuilder(); + StringBuilder postfix = new StringBuilder(); for(int j = 0; j < 3; j++) { prefix.append(whitespaces[RAN.nextInt(whitespaces.length)]); postfix.append(whitespaces[RAN.nextInt(whitespaces.length)]); } - + appendProperty(prefix + name[i] + postfix, name[i] + ".value"); } endConfig(); @@ -675,6 +691,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testGetLocalPath() throws IOException { Configuration conf = new Configuration(); String[] dirs = new String[]{"a", "b", "c"}; @@ -690,7 +707,8 @@ public class TestConfiguration extends TestCase { localPath.contains(" ")); } } - + + @Test public void testGetFile() throws IOException { Configuration conf = new Configuration(); String[] dirs = new String[]{"a", "b", "c"}; @@ -707,29 +725,32 @@ public class TestConfiguration extends TestCase { } } + @Test public void testToString() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); endConfig(); Path fileResource = new Path(CONFIG); conf.addResource(fileResource); - - String expectedOutput = - "Configuration: core-default.xml, core-site.xml, " + + + String expectedOutput = + "Configuration: core-default.xml, core-site.xml, " + fileResource.toString(); assertEquals(expectedOutput, conf.toString()); } - + + @Test public void testWriteXml() throws IOException { Configuration conf = new Configuration(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); conf.writeXml(baos); String result = baos.toString(); assertTrue("Result has proper header", result.startsWith(XMLHEADER)); - + assertTrue("Result has proper footer", result.endsWith("</configuration>")); } - + + @Test public void testIncludes() throws Exception { tearDown(); System.out.println("XXX testIncludes"); @@ -758,8 +779,8 @@ public class TestConfiguration extends TestCase { // verify that the includes file contains all properties Path fileResource = new Path(CONFIG); conf.addResource(fileResource); - assertEquals(conf.get("a"), "b"); - assertEquals(conf.get("c"), "d"); + assertEquals(conf.get("a"), "b"); + assertEquals(conf.get("c"), "d"); assertEquals(conf.get("e"), "f"); assertEquals(conf.get("g"), "h"); assertEquals(conf.get("i"), "j"); @@ -767,6 +788,7 @@ public class TestConfiguration extends TestCase { tearDown(); } + @Test public void testCharsetInDocumentEncoding() throws Exception { tearDown(); out=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(CONFIG), @@ -785,6 +807,7 @@ public class TestConfiguration extends TestCase { tearDown(); } + @Test public void testEntityReference() throws Exception { tearDown(); out=new BufferedWriter(new FileWriter(CONFIG)); @@ -803,6 +826,7 @@ public class TestConfiguration extends TestCase { tearDown(); } + @Test public void testSystemEntityReference() throws Exception { tearDown(); out=new BufferedWriter(new FileWriter(CONFIG2)); @@ -824,6 +848,7 @@ public class TestConfiguration extends TestCase { tearDown(); } + @Test public void testIncludesWithFallback() throws Exception { tearDown(); out=new BufferedWriter(new FileWriter(CONFIG2)); @@ -862,6 +887,7 @@ public class TestConfiguration extends TestCase { tearDown(); } + @Test public void testRelativeIncludes() throws Exception { tearDown(); String relConfig = new File("./tmp/test-config.xml").getAbsolutePath(); @@ -893,6 +919,7 @@ public class TestConfiguration extends TestCase { new File(new File(relConfig).getParent()).delete(); } + @Test public void testIntegerRanges() { Configuration conf = new Configuration(); conf.set("first", "-100"); @@ -923,7 +950,8 @@ public class TestConfiguration extends TestCase { assertEquals(true, range.isIncluded(34)); assertEquals(true, range.isIncluded(100000000)); } - + + @Test public void testGetRangeIterator() throws Exception { Configuration config = new Configuration(false); IntegerRanges ranges = config.getRange("Test", ""); @@ -943,7 +971,7 @@ public class TestConfiguration extends TestCase { found.add(i); } assertEquals(expected, found); - + ranges = config.getRange("Test", "8-12, 5- 7"); expected = new HashSet<Integer>(Arrays.asList(5,6,7,8,9,10,11,12)); found = new HashSet<Integer>(); @@ -953,6 +981,7 @@ public class TestConfiguration extends TestCase { assertEquals(expected, found); } + @Test public void testHexValues() throws IOException{ out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -984,6 +1013,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testIntegerValues() throws IOException{ out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1014,7 +1044,8 @@ public class TestConfiguration extends TestCase { // pass } } - + + @Test public void testHumanReadableValues() throws IOException { out = new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1035,6 +1066,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testBooleanValues() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1058,7 +1090,8 @@ public class TestConfiguration extends TestCase { assertEquals(false, conf.getBoolean("test.bool7", true)); assertEquals(false, conf.getBoolean("test.bool8", false)); } - + + @Test public void testFloatValues() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1070,10 +1103,10 @@ public class TestConfiguration extends TestCase { endConfig(); Path fileResource = new Path(CONFIG); conf.addResource(fileResource); - assertEquals(3.1415f, conf.getFloat("test.float1", 0.0f)); - assertEquals(3.1415f, conf.getFloat("test.float2", 0.0f)); - assertEquals(-3.1415f, conf.getFloat("test.float3", 0.0f)); - assertEquals(-3.1415f, conf.getFloat("test.float4", 0.0f)); + assertEquals(3.1415f, conf.getFloat("test.float1", 0.0f), DOUBLE_DELTA); + assertEquals(3.1415f, conf.getFloat("test.float2", 0.0f), DOUBLE_DELTA); + assertEquals(-3.1415f, conf.getFloat("test.float3", 0.0f), DOUBLE_DELTA); + assertEquals(-3.1415f, conf.getFloat("test.float4", 0.0f), DOUBLE_DELTA); try { conf.getFloat("test.float5", 0.0f); fail("Property had invalid float value, but was read successfully."); @@ -1081,7 +1114,8 @@ public class TestConfiguration extends TestCase { // pass } } - + + @Test public void testDoubleValues() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1093,10 +1127,10 @@ public class TestConfiguration extends TestCase { endConfig(); Path fileResource = new Path(CONFIG); conf.addResource(fileResource); - assertEquals(3.1415, conf.getDouble("test.double1", 0.0)); - assertEquals(3.1415, conf.getDouble("test.double2", 0.0)); - assertEquals(-3.1415, conf.getDouble("test.double3", 0.0)); - assertEquals(-3.1415, conf.getDouble("test.double4", 0.0)); + assertEquals(3.1415, conf.getDouble("test.double1", 0.0), DOUBLE_DELTA); + assertEquals(3.1415, conf.getDouble("test.double2", 0.0), DOUBLE_DELTA); + assertEquals(-3.1415, conf.getDouble("test.double3", 0.0), DOUBLE_DELTA); + assertEquals(-3.1415, conf.getDouble("test.double4", 0.0), DOUBLE_DELTA); try { conf.getDouble("test.double5", 0.0); fail("Property had invalid double value, but was read successfully."); @@ -1104,7 +1138,8 @@ public class TestConfiguration extends TestCase { // pass } } - + + @Test public void testGetClass() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1113,10 +1148,13 @@ public class TestConfiguration extends TestCase { endConfig(); Path fileResource = new Path(CONFIG); conf.addResource(fileResource); - assertEquals("java.lang.Integer", conf.getClass("test.class1", null).getCanonicalName()); - assertEquals("java.lang.Integer", conf.getClass("test.class2", null).getCanonicalName()); + assertEquals("java.lang.Integer", + conf.getClass("test.class1", null).getCanonicalName()); + assertEquals("java.lang.Integer", + conf.getClass("test.class2", null).getCanonicalName()); } - + + @Test public void testGetClasses() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1132,14 +1170,15 @@ public class TestConfiguration extends TestCase { assertArrayEquals(expectedNames, extractClassNames(classes1)); assertArrayEquals(expectedNames, extractClassNames(classes2)); } - + + @Test public void testGetStringCollection() { Configuration c = new Configuration(); c.set("x", " a, b\n,\nc "); Collection<String> strs = c.getTrimmedStringCollection("x"); assertEquals(3, strs.size()); assertArrayEquals(new String[]{ "a", "b", "c" }, - strs.toArray(new String[0])); + strs.toArray(new String[0])); // Check that the result is mutable strs.add("z"); @@ -1150,13 +1189,14 @@ public class TestConfiguration extends TestCase { strs.add("z"); } + @Test public void testGetTrimmedStringCollection() { Configuration c = new Configuration(); c.set("x", "a, b, c"); Collection<String> strs = c.getStringCollection("x"); assertEquals(3, strs.size()); assertArrayEquals(new String[]{ "a", " b", " c" }, - strs.toArray(new String[0])); + strs.toArray(new String[0])); // Check that the result is mutable strs.add("z"); @@ -1174,9 +1214,10 @@ public class TestConfiguration extends TestCase { } return classNames; } - + enum Dingo { FOO, BAR }; enum Yak { RAB, FOO }; + @Test public void testEnum() { Configuration conf = new Configuration(); conf.setEnum("test.enum", Dingo.FOO); @@ -1193,6 +1234,7 @@ public class TestConfiguration extends TestCase { assertTrue(fail); } + @Test public void testEnumFromXml() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG_FOR_ENUM)); startConfig(); @@ -1213,6 +1255,7 @@ public class TestConfiguration extends TestCase { assertTrue(fail); } + @Test public void testTimeDuration() { Configuration conf = new Configuration(false); conf.setTimeDuration("test.time.a", 7L, SECONDS); @@ -1246,17 +1289,18 @@ public class TestConfiguration extends TestCase { assertEquals(30L, conf.getTimeDuration("test.time.d", 40, SECONDS)); for (Configuration.ParsedTimeDuration ptd : - Configuration.ParsedTimeDuration.values()) { + Configuration.ParsedTimeDuration.values()) { conf.setTimeDuration("test.time.unit", 1, ptd.unit()); assertEquals(1 + ptd.suffix(), conf.get("test.time.unit")); assertEquals(1, conf.getTimeDuration("test.time.unit", 2, ptd.unit())); } } + @Test public void testTimeDurationWarning() { // check warn for possible loss of precision final String warnFormat = "Possible loss of precision converting %s" + - " to %s for test.time.warn"; + " to %s for test.time.warn"; final ArrayList<String> warnchk = new ArrayList<>(); Configuration wconf = new Configuration(false) { @Override @@ -1290,6 +1334,7 @@ public class TestConfiguration extends TestCase { assertEquals(2, warnchk.size()); } + @Test public void testPattern() throws IOException { out = new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1303,20 +1348,21 @@ public class TestConfiguration extends TestCase { Pattern defaultPattern = Pattern.compile("x+"); // Return default if missing assertEquals(defaultPattern.pattern(), - conf.getPattern("xxxxx", defaultPattern).pattern()); + conf.getPattern("xxxxx", defaultPattern).pattern()); // Return null if empty and default is null assertNull(conf.getPattern("test.pattern1", null)); // Return default for empty assertEquals(defaultPattern.pattern(), - conf.getPattern("test.pattern1", defaultPattern).pattern()); + conf.getPattern("test.pattern1", defaultPattern).pattern()); // Return default for malformed assertEquals(defaultPattern.pattern(), - conf.getPattern("test.pattern2", defaultPattern).pattern()); + conf.getPattern("test.pattern2", defaultPattern).pattern()); // Works for correct patterns assertEquals("a+b", - conf.getPattern("test.pattern3", defaultPattern).pattern()); + conf.getPattern("test.pattern3", defaultPattern).pattern()); } + @Test public void testPropertySource() throws IOException { out = new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1329,17 +1375,19 @@ public class TestConfiguration extends TestCase { assertEquals(1, sources.length); assertEquals( "Resource string returned for a file-loaded property" + - " must be a proper absolute path", + " must be a proper absolute path", fileResource, new Path(sources[0])); assertArrayEquals("Resource string returned for a set() property must be " + - "\"programmatically\"", + "\"programmatically\"", new String[]{"programmatically"}, conf.getPropertySources("fs.defaultFS")); - assertEquals("Resource string returned for an unset property must be null", + assertArrayEquals("Resource string returned for an unset property must " + + "be null", null, conf.getPropertySources("fs.defaultFoo")); } - + + @Test public void testMultiplePropertySource() throws IOException { out = new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1354,24 +1402,25 @@ public class TestConfiguration extends TestCase { assertEquals("c", sources[2]); assertEquals( "Resource string returned for a file-loaded property" + - " must be a proper absolute path", + " must be a proper absolute path", fileResource, new Path(sources[3])); } + @Test public void testSocketAddress() { Configuration conf = new Configuration(); final String defaultAddr = "host:1"; final int defaultPort = 2; InetSocketAddress addr = null; - + addr = conf.getSocketAddr("myAddress", defaultAddr, defaultPort); assertEquals(defaultAddr, NetUtils.getHostPortString(addr)); - + conf.set("myAddress", "host2"); addr = conf.getSocketAddr("myAddress", defaultAddr, defaultPort); assertEquals("host2:"+defaultPort, NetUtils.getHostPortString(addr)); - + conf.set("myAddress", "host2:3"); addr = conf.getSocketAddr("myAddress", defaultAddr, defaultPort); assertEquals("host2:3", NetUtils.getHostPortString(addr)); @@ -1387,35 +1436,38 @@ public class TestConfiguration extends TestCase { } catch (IllegalArgumentException iae) { threwException = true; assertEquals("Does not contain a valid host:port authority: " + - "bad:-port (configuration property 'myAddress')", - iae.getMessage()); - + "bad:-port (configuration property 'myAddress')", + iae.getMessage()); + } finally { assertTrue(threwException); } } + @Test public void testSetSocketAddress() { Configuration conf = new Configuration(); NetUtils.addStaticResolution("host", "127.0.0.1"); final String defaultAddr = "host:1"; - - InetSocketAddress addr = NetUtils.createSocketAddr(defaultAddr); + + InetSocketAddress addr = NetUtils.createSocketAddr(defaultAddr); conf.setSocketAddr("myAddress", addr); assertEquals(defaultAddr, NetUtils.getHostPortString(addr)); } - + + @Test public void testUpdateSocketAddress() throws IOException { InetSocketAddress addr = NetUtils.createSocketAddrForHost("host", 1); InetSocketAddress connectAddr = conf.updateConnectAddr("myAddress", addr); assertEquals(connectAddr.getHostName(), addr.getHostName()); - + addr = new InetSocketAddress(1); connectAddr = conf.updateConnectAddr("myAddress", addr); assertEquals(connectAddr.getHostName(), - InetAddress.getLocalHost().getHostName()); + InetAddress.getLocalHost().getHostName()); } + @Test public void testReload() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1424,7 +1476,7 @@ public class TestConfiguration extends TestCase { endConfig(); Path fileResource = new Path(CONFIG); conf.addResource(fileResource); - + out=new BufferedWriter(new FileWriter(CONFIG2)); startConfig(); appendProperty("test.key1", "value1"); @@ -1432,23 +1484,23 @@ public class TestConfiguration extends TestCase { endConfig(); Path fileResource1 = new Path(CONFIG2); conf.addResource(fileResource1); - + // add a few values via set. conf.set("test.key3", "value4"); conf.set("test.key4", "value5"); - + assertEquals("final-value1", conf.get("test.key1")); assertEquals("value2", conf.get("test.key2")); assertEquals("value4", conf.get("test.key3")); assertEquals("value5", conf.get("test.key4")); - + // change values in the test file... out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); appendProperty("test.key1", "final-value1"); appendProperty("test.key3", "final-value3", true); endConfig(); - + conf.reloadConfiguration(); assertEquals("value1", conf.get("test.key1")); // overlayed property overrides. @@ -1457,6 +1509,7 @@ public class TestConfiguration extends TestCase { assertEquals("value5", conf.get("test.key4")); } + @Test public void testSize() { Configuration conf = new Configuration(false); conf.set("a", "A"); @@ -1464,6 +1517,7 @@ public class TestConfiguration extends TestCase { assertEquals(2, conf.size()); } + @Test public void testClear() { Configuration conf = new Configuration(false); conf.set("a", "A"); @@ -1476,6 +1530,7 @@ public class TestConfiguration extends TestCase { public static class Fake_ClassLoader extends ClassLoader { } + @Test public void testClassLoader() { Configuration conf = new Configuration(false); conf.setQuietMode(false); @@ -1483,7 +1538,7 @@ public class TestConfiguration extends TestCase { Configuration other = new Configuration(conf); assertTrue(other.getClassLoader() instanceof Fake_ClassLoader); } - + static class JsonConfiguration { JsonProperty[] properties; @@ -1546,6 +1601,7 @@ public class TestConfiguration extends TestCase { return ac; } + @Test public void testGetSetTrimmedNames() throws IOException { Configuration conf = new Configuration(false); conf.set(" name", "value"); @@ -1554,6 +1610,7 @@ public class TestConfiguration extends TestCase { assertEquals("value", conf.getRaw(" name ")); } + @Test public void testDumpProperty() throws IOException { StringWriter outWriter = new StringWriter(); ObjectMapper mapper = new ObjectMapper(); @@ -1668,15 +1725,16 @@ public class TestConfiguration extends TestCase { } } + @Test public void testDumpConfiguration() throws IOException { StringWriter outWriter = new StringWriter(); Configuration.dumpConfiguration(conf, outWriter); String jsonStr = outWriter.toString(); ObjectMapper mapper = new ObjectMapper(); - JsonConfiguration jconf = - mapper.readValue(jsonStr, JsonConfiguration.class); + JsonConfiguration jconf = + mapper.readValue(jsonStr, JsonConfiguration.class); int defaultLength = jconf.getProperties().length; - + // add 3 keys to the existing configuration properties out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1687,7 +1745,7 @@ public class TestConfiguration extends TestCase { Path fileResource = new Path(CONFIG); conf.addResource(fileResource); out.close(); - + outWriter = new StringWriter(); Configuration.dumpConfiguration(conf, outWriter); jsonStr = outWriter.toString(); @@ -1696,7 +1754,7 @@ public class TestConfiguration extends TestCase { int length = jconf.getProperties().length; // check for consistency in the number of properties parsed in Json format. assertEquals(length, defaultLength+3); - + //change few keys in another resource file out=new BufferedWriter(new FileWriter(CONFIG2)); startConfig(); @@ -1706,14 +1764,14 @@ public class TestConfiguration extends TestCase { Path fileResource1 = new Path(CONFIG2); conf.addResource(fileResource1); out.close(); - + outWriter = new StringWriter(); Configuration.dumpConfiguration(conf, outWriter); jsonStr = outWriter.toString(); mapper = new ObjectMapper(); jconf = mapper.readValue(jsonStr, JsonConfiguration.class); - - // put the keys and their corresponding attributes into a hashmap for their + + // put the keys and their corresponding attributes into a hashmap for their // efficient retrieval HashMap<String,JsonProperty> confDump = new HashMap<String,JsonProperty>(); for(JsonProperty prop : jconf.getProperties()) { @@ -1724,7 +1782,7 @@ public class TestConfiguration extends TestCase { assertEquals(false, confDump.get("test.key1").getIsFinal()); assertEquals(fileResource1.toString(), confDump.get("test.key1").getResource()); - // check if final parameter test.key2 is not changed, since it is first + // check if final parameter test.key2 is not changed, since it is first // loaded as final parameter assertEquals("value2", confDump.get("test.key2").getValue()); assertEquals(true, confDump.get("test.key2").getIsFinal()); @@ -1735,7 +1793,7 @@ public class TestConfiguration extends TestCase { assertEquals(false, confDump.get("test.key3").getIsFinal()); assertEquals(fileResource.toString(), confDump.get("test.key3").getResource()); - // check for resource to be "Unknown" for keys which are loaded using 'set' + // check for resource to be "Unknown" for keys which are loaded using 'set' // and expansion of properties conf.set("test.key4", "value4"); conf.set("test.key5", "value5"); @@ -1753,7 +1811,8 @@ public class TestConfiguration extends TestCase { assertEquals("programmatically", confDump.get("test.key4").getResource()); outWriter.close(); } - + + @Test public void testDumpConfiguratioWithoutDefaults() throws IOException { // check for case when default resources are not loaded Configuration config = new Configuration(false); @@ -1761,12 +1820,12 @@ public class TestConfiguration extends TestCase { Configuration.dumpConfiguration(config, outWriter); String jsonStr = outWriter.toString(); ObjectMapper mapper = new ObjectMapper(); - JsonConfiguration jconf = - mapper.readValue(jsonStr, JsonConfiguration.class); - + JsonConfiguration jconf = + mapper.readValue(jsonStr, JsonConfiguration.class); + //ensure that no properties are loaded. assertEquals(0, jconf.getProperties().length); - + // add 2 keys out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -1776,13 +1835,13 @@ public class TestConfiguration extends TestCase { Path fileResource = new Path(CONFIG); config.addResource(fileResource); out.close(); - + outWriter = new StringWriter(); Configuration.dumpConfiguration(config, outWriter); jsonStr = outWriter.toString(); mapper = new ObjectMapper(); jconf = mapper.readValue(jsonStr, JsonConfiguration.class); - + HashMap<String, JsonProperty>confDump = new HashMap<String, JsonProperty>(); for (JsonProperty prop : jconf.getProperties()) { confDump.put(prop.getKey(), prop); @@ -1801,6 +1860,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testDumpSensitiveProperty() throws IOException { final String myPassword = "ThisIsMyPassword"; Configuration testConf = new Configuration(false); @@ -1818,6 +1878,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testDumpSensitiveConfiguration() throws IOException { final String myPassword = "ThisIsMyPassword"; Configuration testConf = new Configuration(false); @@ -1835,6 +1896,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testGetValByRegex() { Configuration conf = new Configuration(); String key1 = "t.abc.key1"; @@ -1853,10 +1915,11 @@ public class TestConfiguration extends TestCase { assertTrue("Picked out wrong key " + key4, !res.containsKey(key4)); } + @Test public void testGetClassesShouldReturnDefaultValue() throws Exception { Configuration config = new Configuration(); - Class<?>[] classes = - config.getClasses("testClassName", Configuration.class); + Class<?>[] classes = + config.getClasses("testClassName", Configuration.class); assertEquals( "Not returning expected number of classes. Number of returned classes =" + classes.length, 1, classes.length); @@ -1864,6 +1927,7 @@ public class TestConfiguration extends TestCase { classes[0]); } + @Test public void testGetClassesShouldReturnEmptyArray() throws Exception { Configuration config = new Configuration(); @@ -1873,7 +1937,8 @@ public class TestConfiguration extends TestCase { "Not returning expected number of classes. Number of returned classes =" + classes.length, 0, classes.length); } - + + @Test public void testSettingValueNull() throws Exception { Configuration config = new Configuration(); try { @@ -1886,6 +1951,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testSettingKeyNull() throws Exception { Configuration config = new Configuration(); try { @@ -1897,6 +1963,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testInvalidSubstitution() { final Configuration configuration = new Configuration(false); @@ -1913,6 +1980,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testIncompleteSubbing() { Configuration configuration = new Configuration(false); String key = "test.random.key"; @@ -1931,6 +1999,7 @@ public class TestConfiguration extends TestCase { } } + @Test public void testBoolean() { boolean value = true; Configuration configuration = new Configuration(); @@ -1938,6 +2007,7 @@ public class TestConfiguration extends TestCase { assertEquals(value, configuration.getBoolean("value", false)); } + @Test public void testBooleanIfUnset() { boolean value = true; Configuration configuration = new Configuration(); @@ -1947,20 +2017,23 @@ public class TestConfiguration extends TestCase { assertEquals(value, configuration.getBoolean("value", false)); } + @Test public void testFloat() { float value = 1.0F; Configuration configuration = new Configuration(); configuration.setFloat("value", value); - assertEquals(value, configuration.getFloat("value", 0.0F)); + assertEquals(value, configuration.getFloat("value", 0.0F), DOUBLE_DELTA); } - + + @Test public void testDouble() { double value = 1.0D; Configuration configuration = new Configuration(); configuration.setDouble("value", value); - assertEquals(value, configuration.getDouble("value", 0.0D)); + assertEquals(value, configuration.getDouble("value", 0.0D), DOUBLE_DELTA); } + @Test public void testInt() { int value = 1; Configuration configuration = new Configuration(); @@ -1968,6 +2041,7 @@ public class TestConfiguration extends TestCase { assertEquals(value, configuration.getInt("value", 0)); } + @Test public void testLong() { long value = 1L; Configuration configuration = new Configuration(); @@ -1975,16 +2049,18 @@ public class TestConfiguration extends TestCase { assertEquals(value, configuration.getLong("value", 0L)); } + @Test public void testStrings() { String [] strings = {"FOO","BAR"}; Configuration configuration = new Configuration(); configuration.setStrings("strings", strings); String [] returnStrings = configuration.getStrings("strings"); for(int i=0;i<returnStrings.length;i++) { - assertEquals(strings[i], returnStrings[i]); + assertEquals(strings[i], returnStrings[i]); } } - + + @Test public void testSetPattern() { Pattern testPattern = Pattern.compile("a+b"); Configuration configuration = new Configuration(); @@ -1992,13 +2068,15 @@ public class TestConfiguration extends TestCase { assertEquals(testPattern.pattern(), configuration.getPattern("testPattern", Pattern.compile("")).pattern()); } - + + @Test public void testGetClassByNameOrNull() throws Exception { - Configuration config = new Configuration(); - Class<?> clazz = config.getClassByNameOrNull("java.lang.Object"); - assertNotNull(clazz); + Configuration config = new Configuration(); + Class<?> clazz = config.getClassByNameOrNull("java.lang.Object"); + assertNotNull(clazz); } + @Test public void testGetFinalParameters() throws Exception { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -2021,6 +2099,7 @@ public class TestConfiguration extends TestCase { * by SPARK-2546. * @throws Exception */ + @Test public void testConcurrentAccesses() throws Exception { out = new BufferedWriter(new FileWriter(CONFIG)); startConfig(); @@ -2061,6 +2140,7 @@ public class TestConfiguration extends TestCase { // it's expected behaviour. } + @Test public void testNullValueProperties() throws Exception { Configuration conf = new Configuration(); conf.setAllowNullValueProperties(true); @@ -2074,6 +2154,7 @@ public class TestConfiguration extends TestCase { assertEquals("value", conf.get("attr")); } + @Test public void testGetPasswordDeprecatedKeyStored() throws Exception { final String oldKey = "test.password.old.key"; final String newKey = "test.password.new.key"; @@ -2093,14 +2174,15 @@ public class TestConfiguration extends TestCase { Configuration.addDeprecation(oldKey, newKey); - Assert.assertThat(conf.getPassword(newKey), + assertThat(conf.getPassword(newKey), CoreMatchers.is(password.toCharArray())); - Assert.assertThat(conf.getPassword(oldKey), + assertThat(conf.getPassword(oldKey), CoreMatchers.is(password.toCharArray())); FileUtil.fullyDelete(tmpDir); } + @Test public void testGetPasswordByDeprecatedKey() throws Exception { final String oldKey = "test.password.old.key"; final String newKey = "test.password.new.key"; @@ -2120,9 +2202,9 @@ public class TestConfiguration extends TestCase { Configuration.addDeprecation(oldKey, newKey); - Assert.assertThat(conf.getPassword(newKey), + assertThat(conf.getPassword(newKey), CoreMatchers.is(password.toCharArray())); - Assert.assertThat(conf.getPassword(oldKey), + assertThat(conf.getPassword(oldKey), CoreMatchers.is(password.toCharArray())); FileUtil.fullyDelete(tmpDir); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationSubclass.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationSubclass.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationSubclass.java index fd2fa38..e15e699 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationSubclass.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationSubclass.java @@ -17,7 +17,8 @@ */ package org.apache.hadoop.conf; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import java.util.Properties; @@ -25,11 +26,12 @@ import java.util.Properties; * Created 21-Jan-2009 13:42:36 */ -public class TestConfigurationSubclass extends TestCase { +public class TestConfigurationSubclass { private static final String EMPTY_CONFIGURATION_XML = "/org/apache/hadoop/conf/empty-configuration.xml"; + @Test public void testGetProps() { SubConf conf = new SubConf(true); Properties properties = conf.getProperties(); @@ -37,6 +39,7 @@ public class TestConfigurationSubclass extends TestCase { properties.getProperty("hadoop.tmp.dir")); } + @Test public void testReload() throws Throwable { SubConf conf = new SubConf(true); assertFalse(conf.isReloaded()); @@ -45,6 +48,7 @@ public class TestConfigurationSubclass extends TestCase { Properties properties = conf.getProperties(); } + @Test public void testReloadNotQuiet() throws Throwable { SubConf conf = new SubConf(true); conf.setQuietMode(false); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestDeprecatedKeys.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestDeprecatedKeys.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestDeprecatedKeys.java index 167daa5..fd01650 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestDeprecatedKeys.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestDeprecatedKeys.java @@ -21,15 +21,14 @@ package org.apache.hadoop.conf; import java.io.ByteArrayOutputStream; import java.util.Map; -import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.CommonConfigurationKeys; import org.junit.Test; +import static org.junit.Assert.*; -import junit.framework.TestCase; - -public class TestDeprecatedKeys extends TestCase { +public class TestDeprecatedKeys { //Tests a deprecated key + @Test public void testDeprecatedKeys() throws Exception { Configuration conf = new Configuration(); conf.set("topology.script.file.name", "xyz"); @@ -39,6 +38,7 @@ public class TestDeprecatedKeys extends TestCase { } //Tests reading / writing a conf file with deprecation after setting + @Test public void testReadWriteWithDeprecatedKeys() throws Exception { Configuration conf = new Configuration(); conf.setBoolean("old.config.yet.to.be.deprecated", true); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestGetInstances.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestGetInstances.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestGetInstances.java index 57b7ff4..bc08e66 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestGetInstances.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestGetInstances.java @@ -18,10 +18,11 @@ package org.apache.hadoop.conf; import java.util.List; +import org.junit.Test; -import junit.framework.TestCase; +import static org.junit.Assert.*; -public class TestGetInstances extends TestCase { +public class TestGetInstances { interface SampleInterface {} @@ -30,7 +31,7 @@ public class TestGetInstances extends TestCase { static class SampleClass implements SampleInterface { SampleClass() {} } - + static class AnotherClass implements ChildInterface { AnotherClass() {} } @@ -39,6 +40,7 @@ public class TestGetInstances extends TestCase { * Makes sure <code>Configuration.getInstances()</code> returns * instances of the required type. */ + @Test public void testGetInstances() throws Exception { Configuration conf = new Configuration(); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestAvroFSInput.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestAvroFSInput.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestAvroFSInput.java index 4009a60..f182fe5 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestAvroFSInput.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestAvroFSInput.java @@ -24,9 +24,10 @@ import java.io.OutputStreamWriter; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.test.GenericTestUtils; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; -public class TestAvroFSInput extends TestCase { +public class TestAvroFSInput { private static final String INPUT_DIR = "AvroFSInput"; @@ -34,6 +35,7 @@ public class TestAvroFSInput extends TestCase { return new Path(GenericTestUtils.getTempPath(INPUT_DIR)); } + @Test public void testAFSInput() throws Exception { Configuration conf = new Configuration(); FileSystem fs = FileSystem.getLocal(conf); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDU.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDU.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDU.java index 615d0b5..a22b765 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDU.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDU.java @@ -17,7 +17,10 @@ */ package org.apache.hadoop.fs; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; import java.io.File; import java.io.IOException; @@ -29,16 +32,16 @@ import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.test.GenericTestUtils; /** This test makes sure that "DU" does not get to run on each call to getUsed */ -public class TestDU extends TestCase { +public class TestDU { final static private File DU_DIR = GenericTestUtils.getTestDir("dutmp"); - @Override + @Before public void setUp() { - FileUtil.fullyDelete(DU_DIR); - assertTrue(DU_DIR.mkdirs()); + FileUtil.fullyDelete(DU_DIR); + assertTrue(DU_DIR.mkdirs()); } - @Override + @After public void tearDown() throws IOException { FileUtil.fullyDelete(DU_DIR); } @@ -69,6 +72,7 @@ public class TestDU extends TestCase { * @throws IOException * @throws InterruptedException */ + @Test public void testDU() throws IOException, InterruptedException { final int writtenSize = 32*1024; // writing 32K // Allow for extra 4K on-disk slack for local file systems @@ -107,6 +111,8 @@ public class TestDU extends TestCase { duSize >= writtenSize && writtenSize <= (duSize + slack)); } + + @Test public void testDUGetUsedWillNotReturnNegative() throws IOException { File file = new File(DU_DIR, "data"); assertTrue(file.createNewFile()); @@ -118,6 +124,7 @@ public class TestDU extends TestCase { assertTrue(String.valueOf(duSize), duSize >= 0L); } + @Test public void testDUSetInitialValue() throws IOException { File file = new File(DU_DIR, "dataX"); createFile(file, 8192); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFs.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFs.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFs.java index a2f0905..5ed743f 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFs.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFs.java @@ -23,12 +23,12 @@ import java.lang.reflect.Modifier; import java.net.URI; import java.util.Iterator; -import junit.framework.TestCase; import org.apache.commons.logging.Log; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.viewfs.ConfigUtil; +import org.junit.Test; -public class TestFilterFs extends TestCase { +public class TestFilterFs { private static final Log LOG = FileSystem.LOG; @@ -41,7 +41,8 @@ public class TestFilterFs extends TestCase { return null; } } - + + @Test public void testFilterFileSystem() throws Exception { for (Method m : AbstractFileSystem.class.getDeclaredMethods()) { if (Modifier.isStatic(m.getModifiers())) @@ -69,6 +70,7 @@ public class TestFilterFs extends TestCase { // Test that FilterFs will accept an AbstractFileSystem to be filtered which // has an optional authority, such as ViewFs + @Test public void testFilteringWithNonrequiredAuthority() throws Exception { Configuration conf = new Configuration(); ConfigUtil.addLink(conf, "custom", "/mnt", URI.create("file:///")); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGetFileBlockLocations.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGetFileBlockLocations.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGetFileBlockLocations.java index 87265f4..f43480e 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGetFileBlockLocations.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGetFileBlockLocations.java @@ -22,7 +22,10 @@ import java.util.Arrays; import java.util.Comparator; import java.util.Random; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.test.GenericTestUtils; @@ -30,7 +33,7 @@ import org.apache.hadoop.test.GenericTestUtils; /** * Testing the correctness of FileSystem.getFileBlockLocations. */ -public class TestGetFileBlockLocations extends TestCase { +public class TestGetFileBlockLocations { private static String TEST_ROOT_DIR = GenericTestUtils.getTempPath( "testGetFileBlockLocations"); private static final int FileLength = 4 * 1024 * 1024; // 4MB @@ -39,11 +42,8 @@ public class TestGetFileBlockLocations extends TestCase { private FileSystem fs; private Random random; - /** - * @see TestCase#setUp() - */ - @Override - protected void setUp() throws IOException { + @Before + public void setUp() throws IOException { conf = new Configuration(); Path rootPath = new Path(TEST_ROOT_DIR); path = new Path(rootPath, "TestGetFileBlockLocations"); @@ -91,15 +91,14 @@ public class TestGetFileBlockLocations extends TestCase { assertTrue(locations.length == 0); } } - /** - * @see TestCase#tearDown() - */ - @Override - protected void tearDown() throws IOException { + + @After + public void tearDown() throws IOException { fs.delete(path, true); fs.close(); } + @Test public void testFailureNegativeParameters() throws IOException { FileStatus status = fs.getFileStatus(path); try { @@ -117,6 +116,7 @@ public class TestGetFileBlockLocations extends TestCase { } } + @Test public void testGetFileBlockLocations1() throws IOException { FileStatus status = fs.getFileStatus(path); oneTest(0, (int) status.getLen(), status); @@ -130,6 +130,7 @@ public class TestGetFileBlockLocations extends TestCase { } } + @Test public void testGetFileBlockLocations2() throws IOException { FileStatus status = fs.getFileStatus(path); for (int i = 0; i < 1000; ++i) { http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGlobExpander.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGlobExpander.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGlobExpander.java index b0466b8..9d75ba0 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGlobExpander.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGlobExpander.java @@ -20,10 +20,12 @@ package org.apache.hadoop.fs; import java.io.IOException; import java.util.List; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; -public class TestGlobExpander extends TestCase { +public class TestGlobExpander { + @Test public void testExpansionIsIdentical() throws IOException { checkExpansionIsIdentical(""); checkExpansionIsIdentical("/}"); @@ -35,6 +37,7 @@ public class TestGlobExpander extends TestCase { checkExpansionIsIdentical("p{a\\/b,c\\/d}s"); } + @Test public void testExpansion() throws IOException { checkExpansion("{a/b}", "a/b"); checkExpansion("/}{a/b}", "/}a/b"); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java index 7a5b25e..12aed29 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTrash.java @@ -33,20 +33,21 @@ import java.util.Random; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.TrashPolicyDefault.Emptier; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.util.Time; -import org.junit.Before; -import org.junit.Test; /** * This class tests commands from Trash. */ -public class TestTrash extends TestCase { +public class TestTrash { private final static Path TEST_DIR = new Path(GenericTestUtils.getTempPath( "testTrash")); @@ -507,19 +508,22 @@ public class TestTrash extends TestCase { } } + @Test public void testTrash() throws IOException { Configuration conf = new Configuration(); conf.setClass("fs.file.impl", TestLFS.class, FileSystem.class); trashShell(FileSystem.getLocal(conf), TEST_DIR); } + @Test public void testNonDefaultFS() throws IOException { Configuration conf = new Configuration(); conf.setClass("fs.file.impl", TestLFS.class, FileSystem.class); conf.set("fs.defaultFS", "invalid://host/bar/foo"); trashNonDefaultFS(conf); } - + + @Test public void testPluggableTrash() throws IOException { Configuration conf = new Configuration(); @@ -604,6 +608,7 @@ public class TestTrash extends TestCase { verifyTrashPermission(FileSystem.getLocal(conf), conf); } + @Test public void testTrashEmptier() throws Exception { Configuration conf = new Configuration(); // Trash with 12 second deletes and 6 seconds checkpoints @@ -665,12 +670,9 @@ public class TestTrash extends TestCase { emptierThread.interrupt(); emptierThread.join(); } - - /** - * @see TestCase#tearDown() - */ - @Override - protected void tearDown() throws IOException { + + @After + public void tearDown() throws IOException { File trashDir = new File(TEST_DIR.toUri().getPath()); if (trashDir.exists() && !FileUtil.fullyDelete(trashDir)) { throw new IOException("Cannot remove data directory: " + trashDir); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTruncatedInputBug.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTruncatedInputBug.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTruncatedInputBug.java index 41c4d47..799471b 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTruncatedInputBug.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestTruncatedInputBug.java @@ -20,16 +20,17 @@ package org.apache.hadoop.fs; import java.io.DataOutputStream; import java.io.IOException; -import junit.framework.TestCase; +import static org.junit.Assert.*; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.test.GenericTestUtils; +import org.junit.Test; /** * test for the input truncation bug when mark/reset is used. * HADOOP-1489 */ -public class TestTruncatedInputBug extends TestCase { +public class TestTruncatedInputBug { private static String TEST_ROOT_DIR = GenericTestUtils.getTestDir().getAbsolutePath(); @@ -49,6 +50,7 @@ public class TestTruncatedInputBug extends TestCase { * checksum file system currently depends on the request size * >= bytesPerSum to work properly. */ + @Test public void testTruncatedInputBug() throws IOException { final int ioBufSize = 512; final int fileSize = ioBufSize*4; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/permission/TestFsPermission.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/permission/TestFsPermission.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/permission/TestFsPermission.java index 6368a57..a22985d 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/permission/TestFsPermission.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/permission/TestFsPermission.java @@ -21,11 +21,14 @@ import java.io.IOException; import org.apache.hadoop.conf.Configuration; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import static org.apache.hadoop.fs.permission.FsAction.*; -public class TestFsPermission extends TestCase { +public class TestFsPermission { + + @Test public void testFsAction() { //implies for(FsAction a : FsAction.values()) { @@ -53,6 +56,7 @@ public class TestFsPermission extends TestCase { * Ensure that when manually specifying permission modes we get * the expected values back out for all combinations */ + @Test public void testConvertingPermissions() { for(short s = 0; s <= 01777; s++) { assertEquals(s, new FsPermission(s).toShort()); @@ -80,6 +84,7 @@ public class TestFsPermission extends TestCase { assertEquals(02000, s); } + @Test public void testSpecialBitsToString() { for (boolean sb : new boolean[] { false, true }) { for (FsAction u : FsAction.values()) { @@ -106,6 +111,7 @@ public class TestFsPermission extends TestCase { } } + @Test public void testFsPermission() { String symbolic = "-rwxrwxrwx"; @@ -132,6 +138,7 @@ public class TestFsPermission extends TestCase { } } + @Test public void testSymbolicPermission() { for (int i = 0; i < SYMBOLIC.length; ++i) { short val = 0777; @@ -146,6 +153,7 @@ public class TestFsPermission extends TestCase { } } + @Test public void testUMaskParser() throws IOException { Configuration conf = new Configuration(); @@ -163,6 +171,7 @@ public class TestFsPermission extends TestCase { } } + @Test public void testSymbolicUmasks() { Configuration conf = new Configuration(); @@ -176,6 +185,7 @@ public class TestFsPermission extends TestCase { assertEquals(0111, FsPermission.getUMask(conf).toShort()); } + @Test public void testBadUmasks() { Configuration conf = new Configuration(); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java index 6b1cd29..d82a2f1 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java @@ -25,7 +25,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.Mockito.times; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; import javax.management.MBeanServer; import javax.management.ObjectName; @@ -39,13 +41,12 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.BlockingQueue; import org.apache.hadoop.security.UserGroupInformation; -import org.junit.Test; import org.mockito.Mockito; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ipc.CallQueueManager.CallQueueOverflowException; import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcResponseHeaderProto.RpcStatusProto; -public class TestFairCallQueue extends TestCase { +public class TestFairCallQueue { private FairCallQueue<Schedulable> fcq; private Schedulable mockCall(String id, int priority) { @@ -65,6 +66,7 @@ public class TestFairCallQueue extends TestCase { } @SuppressWarnings("deprecation") + @Before public void setUp() { Configuration conf = new Configuration(); conf.setInt("ns." + FairCallQueue.IPC_CALLQUEUE_PRIORITY_LEVELS_KEY, 2); @@ -74,6 +76,7 @@ public class TestFairCallQueue extends TestCase { // Validate that the total capacity of all subqueues equals // the maxQueueSize for different values of maxQueueSize + @Test public void testTotalCapacityOfSubQueues() { Configuration conf = new Configuration(); FairCallQueue<Schedulable> fairCallQueue; @@ -291,11 +294,12 @@ public class TestFairCallQueue extends TestCase { // // Ensure that FairCallQueue properly implements BlockingQueue - // + @Test public void testPollReturnsNullWhenEmpty() { assertNull(fcq.poll()); } + @Test public void testPollReturnsTopCallWhenNotEmpty() { Schedulable call = mockCall("c"); assertTrue(fcq.offer(call)); @@ -306,6 +310,7 @@ public class TestFairCallQueue extends TestCase { assertEquals(0, fcq.size()); } + @Test public void testOfferSucceeds() { for (int i = 0; i < 5; i++) { @@ -316,6 +321,7 @@ public class TestFairCallQueue extends TestCase { assertEquals(5, fcq.size()); } + @Test public void testOfferFailsWhenFull() { for (int i = 0; i < 5; i++) { assertTrue(fcq.offer(mockCall("c"))); } @@ -324,6 +330,7 @@ public class TestFairCallQueue extends TestCase { assertEquals(5, fcq.size()); } + @Test public void testOfferSucceedsWhenScheduledLowPriority() { // Scheduler will schedule into queue 0 x 5, then queue 1 int mockedPriorities[] = {0, 0, 0, 0, 0, 1, 0}; @@ -334,10 +341,12 @@ public class TestFairCallQueue extends TestCase { assertEquals(6, fcq.size()); } + @Test public void testPeekNullWhenEmpty() { assertNull(fcq.peek()); } + @Test public void testPeekNonDestructive() { Schedulable call = mockCall("c", 0); assertTrue(fcq.offer(call)); @@ -347,6 +356,7 @@ public class TestFairCallQueue extends TestCase { assertEquals(1, fcq.size()); } + @Test public void testPeekPointsAtHead() { Schedulable call = mockCall("c", 0); Schedulable next = mockCall("b", 0); @@ -356,10 +366,12 @@ public class TestFairCallQueue extends TestCase { assertEquals(call, fcq.peek()); // Peek points at the head } + @Test public void testPollTimeout() throws InterruptedException { assertNull(fcq.poll(10, TimeUnit.MILLISECONDS)); } + @Test public void testPollSuccess() throws InterruptedException { Schedulable call = mockCall("c", 0); assertTrue(fcq.offer(call)); @@ -369,6 +381,7 @@ public class TestFairCallQueue extends TestCase { assertEquals(0, fcq.size()); } + @Test public void testOfferTimeout() throws InterruptedException { for (int i = 0; i < 5; i++) { assertTrue(fcq.offer(mockCall("c"), 10, TimeUnit.MILLISECONDS)); @@ -380,6 +393,7 @@ public class TestFairCallQueue extends TestCase { } @SuppressWarnings("deprecation") + @Test public void testDrainTo() { Configuration conf = new Configuration(); conf.setInt("ns." + FairCallQueue.IPC_CALLQUEUE_PRIORITY_LEVELS_KEY, 2); @@ -397,6 +411,7 @@ public class TestFairCallQueue extends TestCase { } @SuppressWarnings("deprecation") + @Test public void testDrainToWithLimit() { Configuration conf = new Configuration(); conf.setInt("ns." + FairCallQueue.IPC_CALLQUEUE_PRIORITY_LEVELS_KEY, 2); @@ -413,16 +428,19 @@ public class TestFairCallQueue extends TestCase { assertEquals(2, fcq2.size()); } + @Test public void testInitialRemainingCapacity() { assertEquals(10, fcq.remainingCapacity()); } + @Test public void testFirstQueueFullRemainingCapacity() { while (fcq.offer(mockCall("c"))) ; // Queue 0 will fill up first, then queue 1 assertEquals(5, fcq.remainingCapacity()); } + @Test public void testAllQueuesFullRemainingCapacity() { int[] mockedPriorities = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0}; int i = 0; @@ -432,6 +450,7 @@ public class TestFairCallQueue extends TestCase { assertEquals(10, fcq.size()); } + @Test public void testQueuesPartialFilledRemainingCapacity() { int[] mockedPriorities = {0, 1, 0, 1, 0}; for (int i = 0; i < 5; i++) { fcq.offer(mockCall("c", mockedPriorities[i])); } @@ -555,12 +574,14 @@ public class TestFairCallQueue extends TestCase { } // Make sure put will overflow into lower queues when the top is full + @Test public void testPutOverflows() throws InterruptedException { // We can fit more than 5, even though the scheduler suggests the top queue assertCanPut(fcq, 8, 8); assertEquals(8, fcq.size()); } + @Test public void testPutBlocksWhenAllFull() throws InterruptedException { assertCanPut(fcq, 10, 10); // Fill up assertEquals(10, fcq.size()); @@ -569,10 +590,12 @@ public class TestFairCallQueue extends TestCase { assertCanPut(fcq, 0, 1); // Will block } + @Test public void testTakeBlocksWhenEmpty() throws InterruptedException { assertCanTake(fcq, 0, 1); } + @Test public void testTakeRemovesCall() throws InterruptedException { Schedulable call = mockCall("c"); fcq.offer(call); @@ -581,6 +604,7 @@ public class TestFairCallQueue extends TestCase { assertEquals(0, fcq.size()); } + @Test public void testTakeTriesNextQueue() throws InterruptedException { // A mux which only draws from q 0 @@ -597,6 +621,7 @@ public class TestFairCallQueue extends TestCase { assertEquals(0, fcq.size()); } + @Test public void testFairCallQueueMXBean() throws Exception { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName( http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/log/TestLog4Json.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/log/TestLog4Json.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/log/TestLog4Json.java index 9fea50e..d41a587 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/log/TestLog4Json.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/log/TestLog4Json.java @@ -20,7 +20,8 @@ package org.apache.hadoop.log; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ContainerNode; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.util.Time; @@ -33,7 +34,6 @@ import org.apache.log4j.spi.HierarchyEventListener; import org.apache.log4j.spi.LoggerFactory; import org.apache.log4j.spi.LoggerRepository; import org.apache.log4j.spi.ThrowableInformation; -import org.junit.Test; import java.io.IOException; import java.io.StringWriter; @@ -42,7 +42,7 @@ import java.net.NoRouteToHostException; import java.util.Enumeration; import java.util.Vector; -public class TestLog4Json extends TestCase { +public class TestLog4Json { private static final Log LOG = LogFactory.getLog(TestLog4Json.class); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestScriptBasedMapping.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestScriptBasedMapping.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestScriptBasedMapping.java index e201787..0d0d5b1 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestScriptBasedMapping.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestScriptBasedMapping.java @@ -19,15 +19,12 @@ package org.apache.hadoop.net; import java.util.ArrayList; import java.util.List; - -import org.apache.hadoop.conf.Configuration; - -import junit.framework.TestCase; import org.junit.Test; +import static org.junit.Assert.*; -public class TestScriptBasedMapping extends TestCase { - +import org.apache.hadoop.conf.Configuration; +public class TestScriptBasedMapping { public TestScriptBasedMapping() { http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestScriptBasedMappingWithDependency.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestScriptBasedMappingWithDependency.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestScriptBasedMappingWithDependency.java index 77da45b..8638591 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestScriptBasedMappingWithDependency.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestScriptBasedMappingWithDependency.java @@ -19,13 +19,12 @@ package org.apache.hadoop.net; import java.util.ArrayList; import java.util.List; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.hadoop.conf.Configuration; -import junit.framework.TestCase; -import org.junit.Test; - -public class TestScriptBasedMappingWithDependency extends TestCase { +public class TestScriptBasedMappingWithDependency { public TestScriptBasedMappingWithDependency() { http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationFilter.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationFilter.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationFilter.java index 64cd9b7..9fae536 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationFilter.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationFilter.java @@ -17,19 +17,21 @@ package org.apache.hadoop.security; -import junit.framework.TestCase; +import static org.junit.Assert.*; import org.apache.hadoop.http.HttpServer2; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.http.FilterContainer; +import org.junit.Test; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.util.Map; -public class TestAuthenticationFilter extends TestCase { +public class TestAuthenticationFilter { @SuppressWarnings("unchecked") + @Test public void testConfiguration() throws Exception { Configuration conf = new Configuration(); conf.set("hadoop.http.authentication.foo", "bar"); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationWithProxyUserFilter.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationWithProxyUserFilter.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationWithProxyUserFilter.java index 504f5a1..dac6a55 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationWithProxyUserFilter.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationWithProxyUserFilter.java @@ -16,8 +16,8 @@ */ package org.apache.hadoop.security; - -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.hadoop.http.HttpServer2; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.http.FilterContainer; @@ -30,9 +30,10 @@ import java.util.Map; * This class is tested for {@link AuthenticationWithProxyUserFilter} * to verify configurations of this filter. */ -public class TestAuthenticationWithProxyUserFilter extends TestCase { +public class TestAuthenticationWithProxyUserFilter { @SuppressWarnings("unchecked") + @Test public void testConfiguration() throws Exception { Configuration conf = new Configuration(); conf.set("hadoop.http.authentication.foo", "bar"); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestWhitelistBasedResolver.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestWhitelistBasedResolver.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestWhitelistBasedResolver.java index 684ef3b..03fc4cb 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestWhitelistBasedResolver.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestWhitelistBasedResolver.java @@ -21,17 +21,18 @@ import java.io.IOException; import java.net.InetAddress; import java.util.Map; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.security.WhitelistBasedResolver; import org.apache.hadoop.util.TestFileBasedIPList; -public class TestWhitelistBasedResolver extends TestCase { +public class TestWhitelistBasedResolver { public static final Map<String, String> SASL_PRIVACY_PROPS = WhitelistBasedResolver.getSaslProperties(new Configuration()); + @Test public void testFixedVariableAndLocalWhiteList() throws IOException { String[] fixedIps = {"10.119.103.112", "10.221.102.0/23"}; @@ -79,6 +80,7 @@ public class TestWhitelistBasedResolver extends TestCase { * Check for inclusion in whitelist * Check for exclusion from whitelist */ + @Test public void testFixedAndLocalWhiteList() throws IOException { String[] fixedIps = {"10.119.103.112", "10.221.102.0/23"}; @@ -128,6 +130,7 @@ public class TestWhitelistBasedResolver extends TestCase { * Add a bunch of subnets and IPSs to the whitelist * Check for inclusion in whitelist with a null value */ + @Test public void testNullIPAddress() throws IOException { String[] fixedIps = {"10.119.103.112", "10.221.102.0/23"}; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/TestToken.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/TestToken.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/TestToken.java index 1741eb7..f6e5133 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/TestToken.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/TestToken.java @@ -25,11 +25,12 @@ import org.apache.hadoop.io.*; import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier; import org.apache.hadoop.security.token.delegation.TestDelegationToken.TestDelegationTokenIdentifier; import org.apache.hadoop.security.token.delegation.TestDelegationToken.TestDelegationTokenSecretManager; +import org.junit.Test; -import junit.framework.TestCase; +import static org.junit.Assert.*; /** Unit tests for Token */ -public class TestToken extends TestCase { +public class TestToken { static boolean isEqual(Object a, Object b) { return a == null ? b == null : a.equals(b); @@ -45,6 +46,7 @@ public class TestToken extends TestCase { /** * Test token serialization */ + @Test public void testTokenSerialization() throws IOException { // Get a token Token<TokenIdentifier> sourceToken = new Token<TokenIdentifier>(); @@ -76,7 +78,8 @@ public class TestToken extends TestCase { } } - public static void testEncodeWritable() throws Exception { + @Test + public void testEncodeWritable() throws Exception { String[] values = new String[]{"", "a", "bb", "ccc", "dddd", "eeeee", "ffffff", "ggggggg", "hhhhhhhh", "iiiiiiiii", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM" + @@ -96,7 +99,8 @@ public class TestToken extends TestCase { checkUrlSafe(encode); } } - + + @Test public void testDecodeIdentifier() throws IOException { TestDelegationTokenSecretManager secretManager = new TestDelegationTokenSecretManager(0, 0, 0, 0); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestAsyncDiskService.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestAsyncDiskService.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestAsyncDiskService.java index 58935f2..f36c586 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestAsyncDiskService.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestAsyncDiskService.java @@ -17,17 +17,15 @@ */ package org.apache.hadoop.util; -import junit.framework.TestCase; - -import org.apache.hadoop.util.AsyncDiskService; import org.junit.Test; +import static org.junit.Assert.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A test for AsyncDiskService. */ -public class TestAsyncDiskService extends TestCase { +public class TestAsyncDiskService { public static final Logger LOG = LoggerFactory.getLogger(TestAsyncDiskService.class); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
