Repository: hadoop Updated Branches: refs/heads/trunk 3a4e86116 -> 8b7cbe384
http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestCacheableIPList.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestCacheableIPList.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestCacheableIPList.java index 3289d78..88f3b69 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestCacheableIPList.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestCacheableIPList.java @@ -18,14 +18,11 @@ package org.apache.hadoop.util; import java.io.IOException; +import org.junit.Test; -import org.apache.hadoop.util.CacheableIPList; -import org.apache.hadoop.util.FileBasedIPList; +import static org.junit.Assert.*; - -import junit.framework.TestCase; - -public class TestCacheableIPList extends TestCase { +public class TestCacheableIPList { /** * Add a bunch of subnets and IPSs to the file @@ -37,6 +34,7 @@ public class TestCacheableIPList extends TestCase { * test for inclusion * Check for exclusion */ + @Test public void testAddWithSleepForCacheTimeout() throws IOException, InterruptedException { String[] ips = {"10.119.103.112", "10.221.102.0/23", "10.113.221.221"}; @@ -76,6 +74,7 @@ public class TestCacheableIPList extends TestCase { * test for inclusion * Check for exclusion */ + @Test public void testRemovalWithSleepForCacheTimeout() throws IOException, InterruptedException { String[] ips = {"10.119.103.112", "10.221.102.0/23", @@ -115,6 +114,7 @@ public class TestCacheableIPList extends TestCase { * test for inclusion * Check for exclusion */ + @Test public void testAddWithRefresh() throws IOException, InterruptedException { String[] ips = {"10.119.103.112", "10.221.102.0/23", "10.113.221.221"}; @@ -154,6 +154,7 @@ public class TestCacheableIPList extends TestCase { * test for inclusion * Check for exclusion */ + @Test public void testRemovalWithRefresh() throws IOException, InterruptedException { String[] ips = {"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/util/TestFileBasedIPList.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestFileBasedIPList.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestFileBasedIPList.java index 0e79fd1..1bb595c 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestFileBasedIPList.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestFileBasedIPList.java @@ -22,14 +22,11 @@ import java.io.IOException; import java.util.Arrays; import org.apache.commons.io.FileUtils; -import org.apache.hadoop.util.FileBasedIPList; -import org.apache.hadoop.util.IPList; import org.junit.After; import org.junit.Test; +import static org.junit.Assert.*; -import junit.framework.TestCase; - -public class TestFileBasedIPList extends TestCase { +public class TestFileBasedIPList { @After public void tearDown() { @@ -127,6 +124,7 @@ public class TestFileBasedIPList extends TestCase { * test for inclusion * should be true as if the feature is turned off */ + @Test public void testFileNotSpecified() { IPList ipl = new FileBasedIPList(null); @@ -140,6 +138,7 @@ public class TestFileBasedIPList extends TestCase { * test for inclusion * should be true as if the feature is turned off */ + @Test public void testFileMissing() { IPList ipl = new FileBasedIPList("missingips.txt"); @@ -153,6 +152,7 @@ public class TestFileBasedIPList extends TestCase { * test for inclusion * should be true as if the feature is turned off */ + @Test public void testWithEmptyList() throws IOException { String[] ips = {}; @@ -168,6 +168,7 @@ public class TestFileBasedIPList extends TestCase { * test for inclusion * should be true as if the feature is turned off */ + @Test public void testForBadFIle() throws IOException { String[] ips = { "10.221.102/23"}; @@ -187,6 +188,7 @@ public class TestFileBasedIPList extends TestCase { * Check for inclusion with good entries * Check for exclusion */ + @Test public void testWithAWrongEntry() throws IOException { String[] ips = {"10.119.103.112", "10.221.102/23", "10.221.204.1/23"}; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestFindClass.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestFindClass.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestFindClass.java index 3a4ebd5..8ba930b 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestFindClass.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestFindClass.java @@ -19,7 +19,7 @@ package org.apache.hadoop.util; import java.io.ByteArrayOutputStream; import java.io.PrintStream; -import junit.framework.Assert; +import org.junit.Assert; import org.apache.hadoop.util.FindClass; import org.apache.hadoop.util.ToolRunner; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericsUtil.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericsUtil.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericsUtil.java index 58537ad..85d649c 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericsUtil.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericsUtil.java @@ -21,12 +21,14 @@ package org.apache.hadoop.util; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.hadoop.conf.Configuration; -public class TestGenericsUtil extends TestCase { +public class TestGenericsUtil { + @Test public void testToArray() { //test a list of size 10 @@ -45,6 +47,7 @@ public class TestGenericsUtil extends TestCase { } } + @Test public void testWithEmptyList() { try { List<String> list = new ArrayList<String>(); @@ -57,6 +60,7 @@ public class TestGenericsUtil extends TestCase { } } + @Test public void testWithEmptyList2() { List<String> list = new ArrayList<String>(); //this method should not throw IndexOutOfBoundsException @@ -81,6 +85,7 @@ public class TestGenericsUtil extends TestCase { } } + @Test public void testWithGenericClass() { GenericClass<String> testSubject = new GenericClass<String>(); @@ -102,6 +107,7 @@ public class TestGenericsUtil extends TestCase { } + @Test public void testGenericOptionsParser() throws Exception { GenericOptionsParser parser = new GenericOptionsParser( new Configuration(), new String[] {"-jt"}); @@ -116,6 +122,7 @@ public class TestGenericsUtil extends TestCase { "y=z", parser.getConfiguration().get("x")); } + @Test public void testGetClass() { //test with Integer @@ -131,6 +138,7 @@ public class TestGenericsUtil extends TestCase { GenericClass.class, c2); } + @Test public void testIsLog4jLogger() throws Exception { assertFalse("False if clazz is null", GenericsUtil.isLog4jLogger(null)); assertTrue("The implementation is Log4j", http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestIndexedSort.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestIndexedSort.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestIndexedSort.java index 8f33c9d..3de0854 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestIndexedSort.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestIndexedSort.java @@ -21,14 +21,15 @@ import java.io.IOException; import java.util.Arrays; import java.util.Random; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.hadoop.io.DataInputBuffer; import org.apache.hadoop.io.DataOutputBuffer; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.WritableComparator; -public class TestIndexedSort extends TestCase { +public class TestIndexedSort { public void sortAllEqual(IndexedSorter sorter) throws Exception { final int SAMPLE = 500; @@ -128,6 +129,7 @@ public class TestIndexedSort extends TestCase { } + @Test public void testQuickSort() throws Exception { QuickSort sorter = new QuickSort(); sortRandom(sorter); @@ -158,6 +160,7 @@ public class TestIndexedSort extends TestCase { assertTrue(Arrays.equals(values, check)); } + @Test public void testHeapSort() throws Exception { HeapSort sorter = new HeapSort(); sortRandom(sorter); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestNativeLibraryChecker.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestNativeLibraryChecker.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestNativeLibraryChecker.java index 7589e5a..e4792dc 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestNativeLibraryChecker.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestNativeLibraryChecker.java @@ -19,13 +19,13 @@ package org.apache.hadoop.util; import java.io.ByteArrayOutputStream; import java.io.PrintStream; - -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.hadoop.util.ExitUtil.ExitException; -import org.junit.Test; -public class TestNativeLibraryChecker extends TestCase { + +public class TestNativeLibraryChecker { private void expectExit(String [] args) { try { // should throw exit exception http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestMRWithDistributedCache.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestMRWithDistributedCache.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestMRWithDistributedCache.java index 341f38d..d1d392e 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestMRWithDistributedCache.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestMRWithDistributedCache.java @@ -28,7 +28,8 @@ import java.util.jar.JarOutputStream; import java.util.zip.ZipEntry; import org.junit.Assert; -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; @@ -49,8 +50,6 @@ import org.apache.hadoop.mapreduce.TaskInputOutputContext; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.NullOutputFormat; import org.apache.hadoop.mapreduce.server.jobtracker.JTConfig; -import org.junit.Test; - /** * Tests the use of the * {@link org.apache.hadoop.mapreduce.filecache.DistributedCache} within the @@ -66,7 +65,7 @@ import org.junit.Test; * This test is not fast: it uses MiniMRCluster. */ @SuppressWarnings("deprecation") -public class TestMRWithDistributedCache extends TestCase { +public class TestMRWithDistributedCache { private static Path TEST_ROOT_DIR = new Path(System.getProperty("test.build.data","/tmp")); private static File symlinkFile = new File("distributed.first.symlink"); @@ -97,23 +96,23 @@ public class TestMRWithDistributedCache extends TestCase { FileSystem fs = LocalFileSystem.get(conf); // Check that 2 files and 2 archives are present - TestCase.assertEquals(2, localFiles.length); - TestCase.assertEquals(2, localArchives.length); - TestCase.assertEquals(2, files.length); - TestCase.assertEquals(2, archives.length); + Assert.assertEquals(2, localFiles.length); + Assert.assertEquals(2, localArchives.length); + Assert.assertEquals(2, files.length); + Assert.assertEquals(2, archives.length); // Check the file name - TestCase.assertTrue(files[0].getPath().endsWith("distributed.first")); - TestCase.assertTrue(files[1].getPath().endsWith("distributed.second.jar")); + Assert.assertTrue(files[0].getPath().endsWith("distributed.first")); + Assert.assertTrue(files[1].getPath().endsWith("distributed.second.jar")); // Check lengths of the files - TestCase.assertEquals(1, fs.getFileStatus(localFiles[0]).getLen()); - TestCase.assertTrue(fs.getFileStatus(localFiles[1]).getLen() > 1); + Assert.assertEquals(1, fs.getFileStatus(localFiles[0]).getLen()); + Assert.assertTrue(fs.getFileStatus(localFiles[1]).getLen() > 1); // Check extraction of the archive - TestCase.assertTrue(fs.exists(new Path(localArchives[0], + Assert.assertTrue(fs.exists(new Path(localArchives[0], "distributed.jar.inside3"))); - TestCase.assertTrue(fs.exists(new Path(localArchives[1], + Assert.assertTrue(fs.exists(new Path(localArchives[1], "distributed.jar.inside4"))); // Check the class loaders @@ -121,18 +120,18 @@ public class TestMRWithDistributedCache extends TestCase { ClassLoader cl = Thread.currentThread().getContextClassLoader(); // Both the file and the archive were added to classpath, so both // should be reachable via the class loader. - TestCase.assertNotNull(cl.getResource("distributed.jar.inside2")); - TestCase.assertNotNull(cl.getResource("distributed.jar.inside3")); - TestCase.assertNull(cl.getResource("distributed.jar.inside4")); + Assert.assertNotNull(cl.getResource("distributed.jar.inside2")); + Assert.assertNotNull(cl.getResource("distributed.jar.inside3")); + Assert.assertNull(cl.getResource("distributed.jar.inside4")); // Check that the symlink for the renaming was created in the cwd; - TestCase.assertTrue("symlink distributed.first.symlink doesn't exist", + Assert.assertTrue("symlink distributed.first.symlink doesn't exist", symlinkFile.exists()); - TestCase.assertEquals("symlink distributed.first.symlink length not 1", 1, + Assert.assertEquals("symlink distributed.first.symlink length not 1", 1, symlinkFile.length()); //This last one is a difference between MRv2 and MRv1 - TestCase.assertTrue("second file should be symlinked too", + Assert.assertTrue("second file should be symlinked too", expectedAbsentSymlinkFile.exists()); } @@ -188,6 +187,7 @@ public class TestMRWithDistributedCache extends TestCase { } /** Tests using the local job runner. */ + @Test public void testLocalJobRunner() throws Exception { symlinkFile.delete(); // ensure symlink is not present (e.g. if test is // killed part way through) http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestFileOutputCommitter.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestFileOutputCommitter.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestFileOutputCommitter.java index e15f7ab..999561a 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestFileOutputCommitter.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestFileOutputCommitter.java @@ -23,7 +23,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.net.URI; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import org.junit.Assert; import org.apache.hadoop.fs.FileStatus; @@ -38,7 +39,7 @@ import org.apache.hadoop.io.Text; @SuppressWarnings("unchecked") -public class TestFileOutputCommitter extends TestCase { +public class TestFileOutputCommitter { private static Path outDir = new Path(System.getProperty("test.build.data", "/tmp"), "output"); @@ -153,14 +154,18 @@ public class TestFileOutputCommitter extends TestCase { validateContent(outDir); FileUtil.fullyDelete(new File(outDir.toString())); } + + @Test public void testRecoveryV1() throws Exception { testRecoveryInternal(1, 1); } + @Test public void testRecoveryV2() throws Exception { testRecoveryInternal(2, 2); } + @Test public void testRecoveryUpgradeV1V2() throws Exception { testRecoveryInternal(1, 2); } @@ -203,11 +208,13 @@ public class TestFileOutputCommitter extends TestCase { assert(dataFileFound && indexFileFound); } + @Test public void testCommitterWithFailureV1() throws Exception { testCommitterWithFailureInternal(1, 1); testCommitterWithFailureInternal(1, 2); } + @Test public void testCommitterWithFailureV2() throws Exception { testCommitterWithFailureInternal(2, 1); testCommitterWithFailureInternal(2, 2); @@ -256,10 +263,12 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(new File(outDir.toString())); } + @Test public void testCommitterWithDuplicatedCommitV1() throws Exception { testCommitterWithDuplicatedCommitInternal(1); } + @Test public void testCommitterWithDuplicatedCommitV2() throws Exception { testCommitterWithDuplicatedCommitInternal(2); } @@ -340,10 +349,12 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(new File(outDir.toString())); } + @Test public void testCommitterV1() throws Exception { testCommitterInternal(1); } + @Test public void testCommitterV2() throws Exception { testCommitterInternal(2); } @@ -380,18 +391,22 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(new File(outDir.toString())); } + @Test public void testMapFileOutputCommitterV1() throws Exception { testMapFileOutputCommitterInternal(1); } + @Test public void testMapFileOutputCommitterV2() throws Exception { testMapFileOutputCommitterInternal(2); } + @Test public void testMapOnlyNoOutputV1() throws Exception { testMapOnlyNoOutputInternal(1); } + @Test public void testMapOnlyNoOutputV2() throws Exception { testMapOnlyNoOutputInternal(2); } @@ -456,10 +471,12 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(out); } + @Test public void testAbortV1() throws Exception { testAbortInternal(1); } + @Test public void testAbortV2() throws Exception { testAbortInternal(2); } @@ -537,10 +554,12 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(new File(outDir.toString())); } + @Test public void testFailAbortV1() throws Exception { testFailAbortInternal(1); } + @Test public void testFailAbortV2() throws Exception { testFailAbortInternal(2); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestIndexCache.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestIndexCache.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestIndexCache.java index b6a2df0..0cc3c66 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestIndexCache.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestIndexCache.java @@ -32,14 +32,16 @@ import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.mapreduce.server.tasktracker.TTConfig; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; -public class TestIndexCache extends TestCase { +public class TestIndexCache { private JobConf conf; private FileSystem fs; private Path p; - @Override + @Before public void setUp() throws IOException { conf = new JobConf(); fs = FileSystem.getLocal(conf).getRaw(); @@ -47,6 +49,7 @@ public class TestIndexCache extends TestCase { "cache").makeQualified(fs.getUri(), fs.getWorkingDirectory()); } + @Test public void testLRCPolicy() throws Exception { Random r = new Random(); long seed = r.nextLong(); @@ -120,6 +123,7 @@ public class TestIndexCache extends TestCase { checkRecord(rec, totalsize); } + @Test public void testBadIndex() throws Exception { final int parts = 30; fs.delete(p, true); @@ -152,6 +156,7 @@ public class TestIndexCache extends TestCase { } } + @Test public void testInvalidReduceNumberOrLength() throws Exception { fs.delete(p, true); conf.setInt(TTConfig.TT_INDEX_CACHE, 1); @@ -192,6 +197,7 @@ public class TestIndexCache extends TestCase { } } + @Test public void testRemoveMap() throws Exception { // This test case use two thread to call getIndexInformation and // removeMap concurrently, in order to construct race condition. @@ -241,7 +247,8 @@ public class TestIndexCache extends TestCase { assertEquals(true, cache.checkTotalMemoryUsed()); } } - + + @Test public void testCreateRace() throws Exception { fs.delete(p, true); conf.setInt(TTConfig.TT_INDEX_CACHE, 1); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestJobEndNotifier.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestJobEndNotifier.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestJobEndNotifier.java index 7d3e2ed..75893f5 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestJobEndNotifier.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestJobEndNotifier.java @@ -31,12 +31,15 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import static org.junit.Assert.*; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.http.HttpServer2; +import org.junit.Test; -public class TestJobEndNotifier extends TestCase { +public class TestJobEndNotifier { HttpServer2 server; URL baseUrl; @@ -99,6 +102,7 @@ public class TestJobEndNotifier extends TestCase { } } + @Before public void setUp() throws Exception { new File(System.getProperty("build.webapps", "build/webapps") + "/test" ).mkdirs(); @@ -118,6 +122,7 @@ public class TestJobEndNotifier extends TestCase { FailServlet.calledTimes = 0; } + @After public void tearDown() throws Exception { server.stop(); } @@ -125,6 +130,7 @@ public class TestJobEndNotifier extends TestCase { /** * Basic validation for localRunnerNotification. */ + @Test public void testLocalJobRunnerUriSubstitution() throws InterruptedException { JobStatus jobStatus = createTestJobStatus( "job_20130313155005308_0001", JobStatus.SUCCEEDED); @@ -145,6 +151,7 @@ public class TestJobEndNotifier extends TestCase { /** * Validate job.end.retry.attempts for the localJobRunner. */ + @Test public void testLocalJobRunnerRetryCount() throws InterruptedException { int retryAttempts = 3; JobStatus jobStatus = createTestJobStatus( @@ -161,6 +168,7 @@ public class TestJobEndNotifier extends TestCase { * Validate that the notification times out after reaching * mapreduce.job.end-notification.timeout. */ + @Test public void testNotificationTimeout() throws InterruptedException { Configuration conf = new Configuration(); // Reduce the timeout to 1 second http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobMonitorAndPrint.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobMonitorAndPrint.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobMonitorAndPrint.java index 1b533e7..fabe5f2 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobMonitorAndPrint.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobMonitorAndPrint.java @@ -33,7 +33,9 @@ import java.io.IOException; import java.io.LineNumberReader; import java.io.StringReader; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.mapred.TaskReport; @@ -43,8 +45,6 @@ import org.apache.log4j.Layout; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.WriterAppender; -import org.junit.Before; -import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -53,7 +53,7 @@ import org.mockito.stubbing.Answer; * job monitoring is correct and prints 100% for map and reduce before * successful completion. */ -public class TestJobMonitorAndPrint extends TestCase { +public class TestJobMonitorAndPrint { private Job job; private Configuration conf; private ClientProtocol clientProtocol; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestFileOutputCommitter.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestFileOutputCommitter.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestFileOutputCommitter.java index 20d8ab5..abbfcb2 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestFileOutputCommitter.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestFileOutputCommitter.java @@ -27,7 +27,10 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; -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.util.concurrent.HadoopExecutors; import org.junit.Assert; @@ -55,7 +58,7 @@ import org.apache.hadoop.mapreduce.task.JobContextImpl; import org.apache.hadoop.mapreduce.task.TaskAttemptContextImpl; @SuppressWarnings("unchecked") -public class TestFileOutputCommitter extends TestCase { +public class TestFileOutputCommitter { private static final Path outDir = new Path( System.getProperty("test.build.data", System.getProperty("java.io.tmpdir")), @@ -87,12 +90,12 @@ public class TestFileOutputCommitter extends TestCase { fs.delete(outDir, true); } - @Override + @Before public void setUp() throws IOException { cleanup(); } - - @Override + + @After public void tearDown() throws IOException { cleanup(); } @@ -195,14 +198,17 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(new File(outDir.toString())); } + @Test public void testRecoveryV1() throws Exception { testRecoveryInternal(1, 1); } + @Test public void testRecoveryV2() throws Exception { testRecoveryInternal(2, 2); } + @Test public void testRecoveryUpgradeV1V2() throws Exception { testRecoveryInternal(1, 2); } @@ -278,18 +284,22 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(new File(outDir.toString())); } + @Test public void testCommitterV1() throws Exception { testCommitterInternal(1); } + @Test public void testCommitterV2() throws Exception { testCommitterInternal(2); } - + + @Test public void testCommitterWithDuplicatedCommitV1() throws Exception { testCommitterWithDuplicatedCommitInternal(1); } + @Test public void testCommitterWithDuplicatedCommitV2() throws Exception { testCommitterWithDuplicatedCommitInternal(2); } @@ -336,11 +346,13 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(new File(outDir.toString())); } + @Test public void testCommitterWithFailureV1() throws Exception { testCommitterWithFailureInternal(1, 1); testCommitterWithFailureInternal(1, 2); } + @Test public void testCommitterWithFailureV2() throws Exception { testCommitterWithFailureInternal(2, 1); testCommitterWithFailureInternal(2, 2); @@ -390,10 +402,12 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(new File(outDir.toString())); } + @Test public void testCommitterRepeatableV1() throws Exception { testCommitterRetryInternal(1); } + @Test public void testCommitterRepeatableV2() throws Exception { testCommitterRetryInternal(2); } @@ -493,14 +507,17 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(new File(outDir.toString())); } + @Test public void testMapFileOutputCommitterV1() throws Exception { testMapFileOutputCommitterInternal(1); } - + + @Test public void testMapFileOutputCommitterV2() throws Exception { testMapFileOutputCommitterInternal(2); } + @Test public void testInvalidVersionNumber() throws IOException { Job job = Job.getInstance(); FileOutputFormat.setOutputPath(job, outDir); @@ -552,10 +569,12 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(new File(outDir.toString())); } + @Test public void testAbortV1() throws IOException, InterruptedException { testAbortInternal(1); } + @Test public void testAbortV2() throws IOException, InterruptedException { testAbortInternal(2); } @@ -575,7 +594,7 @@ public class TestFileOutputCommitter extends TestCase { } } - + private void testFailAbortInternal(int version) throws IOException, InterruptedException { Job job = Job.getInstance(); @@ -631,10 +650,12 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(new File(outDir.toString())); } + @Test public void testFailAbortV1() throws Exception { testFailAbortInternal(1); } + @Test public void testFailAbortV2() throws Exception { testFailAbortInternal(2); } @@ -732,10 +753,12 @@ public class TestFileOutputCommitter extends TestCase { FileUtil.fullyDelete(new File(outDir.toString())); } + @Test public void testConcurrentCommitTaskWithSubDirV1() throws Exception { testConcurrentCommitTaskWithSubDir(1); } + @Test public void testConcurrentCommitTaskWithSubDirV2() throws Exception { testConcurrentCommitTaskWithSubDir(2); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestFileOutputFormat.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestFileOutputFormat.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestFileOutputFormat.java index a48fe3b..a5a8eb7 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestFileOutputFormat.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestFileOutputFormat.java @@ -19,7 +19,8 @@ package org.apache.hadoop.mapreduce.lib.output; import java.io.IOException; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; @@ -28,8 +29,9 @@ import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.RecordWriter; import org.apache.hadoop.mapreduce.TaskAttemptContext; -public class TestFileOutputFormat extends TestCase { +public class TestFileOutputFormat { + @Test public void testSetOutputPathException() throws Exception { Job job = Job.getInstance(); try { @@ -42,6 +44,7 @@ public class TestFileOutputFormat extends TestCase { } } + @Test public void testCheckOutputSpecsException() throws Exception { Job job = Job.getInstance(); Path outDir = new Path(System.getProperty("test.build.data", "/tmp"), http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/jobcontrol/TestJobControl.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/jobcontrol/TestJobControl.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/jobcontrol/TestJobControl.java index 768448f..96954d5 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/jobcontrol/TestJobControl.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/jobcontrol/TestJobControl.java @@ -38,7 +38,7 @@ import org.junit.Test; * This class performs unit test for Job/JobControl classes. * */ -public class TestJobControl extends junit.framework.TestCase { +public class TestJobControl { /** * This is a main function for testing JobControl class. @@ -263,13 +263,13 @@ public class TestJobControl extends junit.framework.TestCase { JobConf jc = new JobConf(); Job j = new Job(jc); //Just make sure no exception is thrown - assertNull(j.getAssignedJobID()); + Assert.assertNull(j.getAssignedJobID()); org.apache.hadoop.mapreduce.Job mockjob = mock(org.apache.hadoop.mapreduce.Job.class); org.apache.hadoop.mapreduce.JobID jid = new org.apache.hadoop.mapreduce.JobID("test",0); when(mockjob.getJobID()).thenReturn(jid); j.setJob(mockjob); JobID expected = new JobID("test",0); - assertEquals(expected, j.getAssignedJobID()); + Assert.assertEquals(expected, j.getAssignedJobID()); verify(mockjob).getJobID(); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMapCollection.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMapCollection.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMapCollection.java index ecc01db..afe4a10 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMapCollection.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMapCollection.java @@ -17,9 +17,6 @@ */ package org.apache.hadoop.mapreduce; - -import junit.framework.TestCase; - import java.io.IOException; import java.io.DataInput; import java.io.DataOutput; @@ -27,9 +24,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; - -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.*; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/input/TestDelegatingInputFormat.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/input/TestDelegatingInputFormat.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/input/TestDelegatingInputFormat.java index 1428e47..194cdeb 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/input/TestDelegatingInputFormat.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/input/TestDelegatingInputFormat.java @@ -20,8 +20,8 @@ package org.apache.hadoop.mapreduce.lib.input; import java.io.DataOutputStream; import java.io.IOException; import java.util.List; - -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; @@ -30,9 +30,10 @@ import org.apache.hadoop.mapreduce.InputSplit; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; -public class TestDelegatingInputFormat extends TestCase { +public class TestDelegatingInputFormat { @SuppressWarnings("unchecked") + @Test public void testSplitting() throws Exception { Job job = Job.getInstance(); MiniDFSCluster dfs = null; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/jobcontrol/TestMapReduceJobControl.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/jobcontrol/TestMapReduceJobControl.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/jobcontrol/TestMapReduceJobControl.java index d86ddd0..da011a2 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/jobcontrol/TestMapReduceJobControl.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/jobcontrol/TestMapReduceJobControl.java @@ -95,7 +95,7 @@ public class TestMapReduceJobControl extends HadoopTestCase { cjob2 = new ControlledJob(job2, dependingJobs); Job job3 = MapReduceTestUtil.createCopyJob(conf, outdir_3, - outdir_1, outdir_2); + outdir_1, outdir_2); dependingJobs = new ArrayList<ControlledJob>(); dependingJobs.add(cjob1); dependingJobs.add(cjob2); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestMRCJCFileOutputCommitter.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestMRCJCFileOutputCommitter.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestMRCJCFileOutputCommitter.java index ae06812..14f123a 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestMRCJCFileOutputCommitter.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/lib/output/TestMRCJCFileOutputCommitter.java @@ -21,7 +21,10 @@ package org.apache.hadoop.mapreduce.lib.output; import java.io.*; import java.net.URI; -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.*; @@ -38,7 +41,7 @@ import org.apache.hadoop.mapreduce.task.JobContextImpl; import org.apache.hadoop.mapreduce.task.TaskAttemptContextImpl; -public class TestMRCJCFileOutputCommitter extends TestCase { +public class TestMRCJCFileOutputCommitter { private static Path outDir = new Path(System.getProperty("test.build.data", "/tmp"), "output"); @@ -76,17 +79,18 @@ public class TestMRCJCFileOutputCommitter extends TestCase { fs.delete(outDir, true); } - @Override + @Before public void setUp() throws IOException { cleanup(); } - @Override + @After public void tearDown() throws IOException { cleanup(); } @SuppressWarnings("unchecked") + @Test public void testCommitter() throws Exception { Job job = Job.getInstance(); FileOutputFormat.setOutputPath(job, outDir); @@ -122,7 +126,8 @@ public class TestMRCJCFileOutputCommitter extends TestCase { assertEquals(output, expectedOutput.toString()); FileUtil.fullyDelete(new File(outDir.toString())); } - + + @Test public void testEmptyOutput() throws Exception { Job job = Job.getInstance(); FileOutputFormat.setOutputPath(job, outDir); @@ -146,6 +151,7 @@ public class TestMRCJCFileOutputCommitter extends TestCase { } @SuppressWarnings("unchecked") + @Test public void testAbort() throws IOException, InterruptedException { Job job = Job.getInstance(); FileOutputFormat.setOutputPath(job, outDir); @@ -195,6 +201,7 @@ public class TestMRCJCFileOutputCommitter extends TestCase { } @SuppressWarnings("unchecked") + @Test public void testFailAbort() throws IOException, InterruptedException { Job job = Job.getInstance(); Configuration conf = job.getConfiguration(); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/TestTaskContext.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/TestTaskContext.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/TestTaskContext.java index 508ded3..471c68f 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/TestTaskContext.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/TestTaskContext.java @@ -22,23 +22,30 @@ import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; -import junit.framework.TestCase; +import org.junit.Test; +import org.junit.Assert; -public class TestTaskContext extends TestCase { - +public class TestTaskContext { + + @Test public void testTaskContext() { - TaskContext context = new TaskContext(null, null, null, null, null, null, null); + TaskContext context = new TaskContext(null, null, null, null, null, null, + null); context.setInputKeyClass(IntWritable.class); - assertEquals(IntWritable.class.getName(), context.getInputKeyClass().getName()); + Assert.assertEquals(IntWritable.class.getName(), context.getInputKeyClass + ().getName()); context.setInputValueClass(Text.class); - assertEquals(Text.class.getName(), context.getInputValueClass().getName()); + Assert.assertEquals(Text.class.getName(), context.getInputValueClass() + .getName()); context.setOutputKeyClass(LongWritable.class); - assertEquals(LongWritable.class.getName(), context.getOutputKeyClass().getName()); + Assert.assertEquals(LongWritable.class.getName(), context + .getOutputKeyClass().getName()); context.setOutputValueClass(FloatWritable.class); - assertEquals(FloatWritable.class.getName(), context.getOutputValueClass().getName()); + Assert.assertEquals(FloatWritable.class.getName(), context + .getOutputValueClass().getName()); } } http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/buffer/TestInputBuffer.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/buffer/TestInputBuffer.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/buffer/TestInputBuffer.java index 7eb6467..fa68364 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/buffer/TestInputBuffer.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/buffer/TestInputBuffer.java @@ -19,11 +19,12 @@ package org.apache.hadoop.mapred.nativetask.buffer; import java.io.IOException; -import junit.framework.TestCase; - +import org.junit.Test; import org.junit.Assert; -public class TestInputBuffer extends TestCase { +public class TestInputBuffer { + + @Test public void testInputBuffer() throws IOException { final int size = 100; final InputBuffer input1 = new InputBuffer(BufferType.DIRECT_BUFFER, size); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/buffer/TestOutputBuffer.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/buffer/TestOutputBuffer.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/buffer/TestOutputBuffer.java index 39c25a6..af6693e 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/buffer/TestOutputBuffer.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/buffer/TestOutputBuffer.java @@ -17,11 +17,12 @@ */ package org.apache.hadoop.mapred.nativetask.buffer; -import junit.framework.TestCase; - +import org.junit.Test; import org.junit.Assert; -public class TestOutputBuffer extends TestCase { +public class TestOutputBuffer { + + @Test public void testOutputBuffer() { final int size = 100; final OutputBuffer output1 = new OutputBuffer(BufferType.DIRECT_BUFFER, size); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/serde/TestKVSerializer.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/serde/TestKVSerializer.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/serde/TestKVSerializer.java index fd5b100..1a7dace 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/serde/TestKVSerializer.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/serde/TestKVSerializer.java @@ -20,7 +20,8 @@ package org.apache.hadoop.mapred.nativetask.serde; import java.io.ByteArrayOutputStream; import java.io.IOException; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; import org.apache.hadoop.io.BytesWritable; import org.apache.hadoop.mapred.nativetask.Constants; @@ -30,12 +31,11 @@ import org.apache.hadoop.mapred.nativetask.testutil.TestInput; import org.apache.hadoop.mapred.nativetask.testutil.TestInput.KV; import org.apache.hadoop.mapred.nativetask.util.SizedWritable; import org.junit.Assert; -import org.junit.Before; import org.mockito.Matchers; import org.mockito.Mockito; @SuppressWarnings({ "rawtypes", "unchecked" }) -public class TestKVSerializer extends TestCase { +public class TestKVSerializer { int inputArraySize = 1000; // 1000 bytesWriable elements int bufferSize = 100; // bytes @@ -46,7 +46,6 @@ public class TestKVSerializer extends TestCase { private SizedWritable value; private KVSerializer serializer; - @Override @Before public void setUp() throws IOException { this.inputArray = TestInput.getMapInputs(inputArraySize); @@ -60,6 +59,7 @@ public class TestKVSerializer extends TestCase { serializer.updateLength(key, value); } + @Test public void testUpdateLength() throws IOException { Mockito.mock(DataOutputStream.class); @@ -75,6 +75,7 @@ public class TestKVSerializer extends TestCase { } } + @Test public void testSerializeKV() throws IOException { final DataOutputStream dataOut = Mockito.mock(DataOutputStream.class); @@ -92,6 +93,7 @@ public class TestKVSerializer extends TestCase { Assert.assertEquals(written, key.length + value.length + Constants.SIZEOF_KV_LENGTH); } + @Test public void testSerializeNoFlush() throws IOException { final DataOutputStream dataOut = Mockito.mock(DataOutputStream.class); @@ -109,6 +111,7 @@ public class TestKVSerializer extends TestCase { Assert.assertEquals(written, key.length + value.length + Constants.SIZEOF_KV_LENGTH); } + @Test public void testSerializePartitionKV() throws IOException { final DataOutputStream dataOut = Mockito.mock(DataOutputStream.class); @@ -130,12 +133,14 @@ public class TestKVSerializer extends TestCase { + Constants.SIZEOF_PARTITION_LENGTH); } + @Test public void testDeserializerNoData() throws IOException { final DataInputStream in = Mockito.mock(DataInputStream.class); Mockito.when(in.hasUnReadData()).thenReturn(false); Assert.assertEquals(0, serializer.deserializeKV(in, key, value)); } + @Test public void testDeserializer() throws IOException { final DataInputStream in = Mockito.mock(DataInputStream.class); Mockito.when(in.hasUnReadData()).thenReturn(true); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/utils/TestReadWriteBuffer.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/utils/TestReadWriteBuffer.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/utils/TestReadWriteBuffer.java index 6ea8092..584aedd 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/utils/TestReadWriteBuffer.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/utils/TestReadWriteBuffer.java @@ -17,15 +17,16 @@ */ package org.apache.hadoop.mapred.nativetask.utils; -import junit.framework.TestCase; +import org.junit.Test; +import org.junit.Assert; import org.apache.hadoop.mapred.nativetask.util.ReadWriteBuffer; -import org.junit.Assert; -public class TestReadWriteBuffer extends TestCase { +public class TestReadWriteBuffer { private static byte[] bytes = new byte[] { '0', 'a', 'b', 'c', 'd', '9' }; + @Test public void testReadWriteBuffer() { final ReadWriteBuffer buffer = new ReadWriteBuffer(); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/utils/TestSizedWritable.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/utils/TestSizedWritable.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/utils/TestSizedWritable.java index 7b82eff..a6e43ed 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/utils/TestSizedWritable.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/utils/TestSizedWritable.java @@ -17,15 +17,16 @@ */ package org.apache.hadoop.mapred.nativetask.utils; -import junit.framework.TestCase; +import org.junit.Test; import org.apache.hadoop.io.BytesWritable; import org.apache.hadoop.mapred.nativetask.util.SizedWritable; import org.junit.Assert; @SuppressWarnings({ "rawtypes", "unchecked" }) -public class TestSizedWritable extends TestCase { +public class TestSizedWritable { + @Test public void testSizedWritable() { final SizedWritable w = new SizedWritable(BytesWritable.class); Assert.assertTrue(w.length == SizedWritable.INVALID_LENGTH); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestBaileyBorweinPlouffe.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestBaileyBorweinPlouffe.java b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestBaileyBorweinPlouffe.java index 3215bfe..2df2df0 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestBaileyBorweinPlouffe.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestBaileyBorweinPlouffe.java @@ -18,29 +18,35 @@ package org.apache.hadoop.examples; import java.math.BigInteger; +import org.junit.Test; +import org.junit.Assert; /** Tests for BaileyBorweinPlouffe */ -public class TestBaileyBorweinPlouffe extends junit.framework.TestCase { +public class TestBaileyBorweinPlouffe { + @Test public void testMod() { final BigInteger TWO = BigInteger.ONE.add(BigInteger.ONE); for(long n = 3; n < 100; n++) { for (long e = 1; e < 100; e++) { final long r = TWO.modPow( BigInteger.valueOf(e), BigInteger.valueOf(n)).longValue(); - assertEquals("e=" + e + ", n=" + n, r, BaileyBorweinPlouffe.mod(e, n)); + Assert.assertEquals("e=" + e + ", n=" + n, r, BaileyBorweinPlouffe + .mod(e, n)); } } } + @Test public void testHexDigit() { final long[] answers = {0x43F6, 0xA308, 0x29B7, 0x49F1, 0x8AC8, 0x35EA}; long d = 1; for(int i = 0; i < answers.length; i++) { - assertEquals("d=" + d, answers[i], BaileyBorweinPlouffe.hexDigits(d)); + Assert.assertEquals("d=" + d, answers[i], BaileyBorweinPlouffe + .hexDigits(d)); d *= 10; } - assertEquals(0x243FL, BaileyBorweinPlouffe.hexDigits(0)); + Assert.assertEquals(0x243FL, BaileyBorweinPlouffe.hexDigits(0)); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestLongLong.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestLongLong.java b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestLongLong.java index 991121f..d6f284e 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestLongLong.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestLongLong.java @@ -19,24 +19,30 @@ package org.apache.hadoop.examples.pi.math; import java.math.BigInteger; import java.util.Random; +import org.junit.Test; +import org.junit.Assert; -public class TestLongLong extends junit.framework.TestCase { - static final Random RAN = new Random(); +public class TestLongLong { + + static final Random RAN = new Random(); static final long MASK = (1L << (LongLong.SIZE >> 1)) - 1; static long nextPositiveLong() { return RAN.nextLong() & MASK; } - + static void verifyMultiplication(long a, long b) { final LongLong ll = LongLong.multiplication(new LongLong(), a, b); final BigInteger bi = BigInteger.valueOf(a).multiply(BigInteger.valueOf(b)); - final String s = String.format("\na = %x\nb = %x\nll= " + ll + "\nbi= " + bi.toString(16) + "\n", a, b); + final String s = String.format( + "\na = %x\nb = %x\nll= " + ll + "\nbi= " + bi.toString(16) + "\n", a, + b); //System.out.println(s); - assertEquals(s, bi, ll.toBigInteger()); + Assert.assertEquals(s, bi, ll.toBigInteger()); } + @Test public void testMultiplication() { for(int i = 0; i < 100; i++) { final long a = nextPositiveLong(); @@ -50,19 +56,24 @@ public class TestLongLong extends junit.framework.TestCase { static void verifyRightShift(long a, long b) { final LongLong ll = new LongLong().set(a, b); final BigInteger bi = ll.toBigInteger(); - - for(int i = 0; i < LongLong.SIZE >> 1; i++) { + + for (int i = 0; i < LongLong.SIZE >> 1; i++) { final long result = ll.shiftRight(i) & MASK; final long expected = bi.shiftRight(i).longValue() & MASK; - final String s = String.format("\na = %x\nb = %x\nll= " + ll + "\nbi= " + bi.toString(16) + "\n", a, b); - assertEquals(s, expected, result); + final String s = String.format( + "\na = %x\nb = %x\nll= " + ll + "\nbi= " + bi.toString(16) + "\n", a, + b); + Assert.assertEquals(s, expected, result); } - final String s = String.format("\na = %x\nb = %x\nll= " + ll + "\nbi= " + bi.toString(16) + "\n", a, b); + final String s = String.format( + "\na = %x\nb = %x\nll= " + ll + "\nbi= " + bi.toString(16) + "\n", a, + b); //System.out.println(s); - assertEquals(s, bi, ll.toBigInteger()); + Assert.assertEquals(s, bi, ll.toBigInteger()); } + @Test public void testRightShift() { for(int i = 0; i < 1000; i++) { final long a = nextPositiveLong(); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestModular.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestModular.java b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestModular.java index 079eb7f..a75ec29 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestModular.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestModular.java @@ -21,14 +21,16 @@ import java.math.BigInteger; import java.util.Random; import org.apache.hadoop.examples.pi.Util.Timer; +import org.junit.Assert; +import org.junit.Test; -public class TestModular extends junit.framework.TestCase { - private static final Random RANDOM = new Random(); +public class TestModular{ + private static final Random RANDOM = new Random(); private static final BigInteger TWO = BigInteger.valueOf(2); static final int DIV_VALID_BIT = 32; - static final long DIV_LIMIT = 1L << DIV_VALID_BIT; + static final long DIV_LIMIT = 1L << DIV_VALID_BIT; // return r/n for n > r > 0 static long div(long sum, long r, long n) { @@ -36,7 +38,7 @@ public class TestModular extends junit.framework.TestCase { int i = DIV_VALID_BIT - 1; for(r <<= 1; r < n; r <<= 1) i--; //System.out.printf(" r=%d, n=%d, q=%d\n", r, n, q); - + for(; i >= 0 ;) { r -= n; q |= (1L << i); @@ -48,14 +50,15 @@ public class TestModular extends junit.framework.TestCase { sum += q; return sum < DIV_LIMIT? sum: sum - DIV_LIMIT; } - + + @Test public void testDiv() { for(long n = 2; n < 100; n++) for(long r = 1; r < n; r++) { final long a = div(0, r, n); final long b = (long)((r*1.0/n) * (1L << DIV_VALID_BIT)); final String s = String.format("r=%d, n=%d, a=%X, b=%X", r, n, a, b); - assertEquals(s, b, a); + Assert.assertEquals(s, b, a); } } @@ -64,16 +67,16 @@ public class TestModular extends junit.framework.TestCase { for(int i = 0; i < rn.length; i++) { rn[i] = new long[rsize + 1][]; - long n = RANDOM.nextLong() & 0xFFFFFFFFFFFFFFFL; + long n = RANDOM.nextLong() & 0xFFFFFFFFFFFFFFFL; if (n <= 1) n = 0xFFFFFFFFFFFFFFFL - n; rn[i][0] = new long[]{n}; - final BigInteger N = BigInteger.valueOf(n); + final BigInteger N = BigInteger.valueOf(n); for(int j = 1; j < rn[i].length; j++) { long r = RANDOM.nextLong(); if (r < 0) r = -r; if (r >= n) r %= n; - final BigInteger R = BigInteger.valueOf(r); + final BigInteger R = BigInteger.valueOf(r); rn[i][j] = new long[]{r, R.multiply(R).mod(N).longValue()}; } } @@ -102,20 +105,20 @@ public class TestModular extends junit.framework.TestCase { } else { final int HALF = (63 - Long.numberOfLeadingZeros(n)) >> 1; final int FULL = HALF << 1; - final long ONES = (1 << HALF) - 1; - + final long ONES = (1 << HALF) - 1; + final long high = r >>> HALF; final long low = r &= ONES; r *= r; if (r >= n) r %= n; - + if (high != 0) { long s = high * high; if (s >= n) s %= n; for(int i = 0; i < FULL; i++) if ((s <<= 1) >= n) s -= n; - + if (low == 0) r = s; else { @@ -123,7 +126,7 @@ public class TestModular extends junit.framework.TestCase { if (t >= n) t %= n; for(int i = -1; i < HALF; i++) if ((t <<= 1) >= n) t -= n; - + r += s; if (r >= n) r -= n; r += t; @@ -133,7 +136,7 @@ public class TestModular extends junit.framework.TestCase { } return r; } - + static void squareBenchmarks() { final Timer t = new Timer(false); t.tick("squareBenchmarks(), MAX_SQRT=" + Modular.MAX_SQRT_LONG); @@ -147,8 +150,11 @@ public class TestModular extends junit.framework.TestCase { final long r = rn[i][j][0]; final long answer = rn[i][j][1]; final long s = square_slow(r, n); - if (s != answer) - assertEquals("r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, answer, s); + if (s != answer) { + Assert.assertEquals( + "r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, + answer, s); + } } } t.tick("square_slow"); @@ -161,8 +167,11 @@ public class TestModular extends junit.framework.TestCase { final long r = rn[i][j][0]; final long answer = rn[i][j][1]; final long s = square(r, n, r2p64); - if (s != answer) - assertEquals("r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, answer, s); + if (s != answer) { + Assert.assertEquals( + "r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, + answer, s); + } } } t.tick("square"); @@ -175,8 +184,11 @@ public class TestModular extends junit.framework.TestCase { final long answer = rn[i][j][1]; final BigInteger R = BigInteger.valueOf(r); final long s = R.multiply(R).mod(N).longValue(); - if (s != answer) - assertEquals("r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, answer, s); + if (s != answer) { + Assert.assertEquals( + "r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, + answer, s); + } } } t.tick("R.multiply(R).mod(N)"); @@ -189,8 +201,11 @@ public class TestModular extends junit.framework.TestCase { final long answer = rn[i][j][1]; final BigInteger R = BigInteger.valueOf(r); final long s = R.modPow(TWO, N).longValue(); - if (s != answer) - assertEquals("r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, answer, s); + if (s != answer) { + Assert.assertEquals( + "r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, + answer, s); + } } } t.tick("R.modPow(TWO, N)"); @@ -201,15 +216,15 @@ public class TestModular extends junit.framework.TestCase { for(int i = 0; i < en.length; i++) { en[i] = new long[esize + 1][]; - long n = (RANDOM.nextLong() & 0xFFFFFFFFFFFFFFFL) | 1L; + long n = (RANDOM.nextLong() & 0xFFFFFFFFFFFFFFFL) | 1L; if (n == 1) n = 3; en[i][0] = new long[]{n}; - final BigInteger N = BigInteger.valueOf(n); + final BigInteger N = BigInteger.valueOf(n); for(int j = 1; j < en[i].length; j++) { long e = RANDOM.nextLong(); if (e < 0) e = -e; - final BigInteger E = BigInteger.valueOf(e); + final BigInteger E = BigInteger.valueOf(e); en[i][j] = new long[]{e, TWO.modPow(E, N).longValue()}; } } @@ -253,10 +268,10 @@ public class TestModular extends junit.framework.TestCase { static class Montgomery2 extends Montgomery { /** Compute 2^y mod N for N odd. */ long mod2(final long y) { - long r0 = R - N; + long r0 = R - N; long r1 = r0 << 1; if (r1 >= N) r1 -= N; - + for(long mask = Long.highestOneBit(y); mask > 0; mask >>>= 1) { if ((mask & y) == 0) { r1 = product.m(r0, r1); @@ -269,7 +284,7 @@ public class TestModular extends junit.framework.TestCase { return product.m(r0, 1); } } - + static void modBenchmarks() { final Timer t = new Timer(false); t.tick("modBenchmarks()"); @@ -283,12 +298,15 @@ public class TestModular extends junit.framework.TestCase { final long e = en[i][j][0]; final long answer = en[i][j][1]; final long s = Modular.mod(e, n); - if (s != answer) - assertEquals("e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s, answer, s); + if (s != answer) { + Assert.assertEquals( + "e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s, + answer, s); + } } } t.tick("Modular.mod"); - + final Montgomery2 m2 = new Montgomery2(); for(int i = 0; i < en.length; i++) { final long n = en[i][0][0]; @@ -297,8 +315,11 @@ public class TestModular extends junit.framework.TestCase { final long e = en[i][j][0]; final long answer = en[i][j][1]; final long s = m2.mod(e); - if (s != answer) - assertEquals("e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s, answer, s); + if (s != answer) { + Assert.assertEquals( + "e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s, + answer, s); + } } } t.tick("montgomery.mod"); @@ -310,21 +331,27 @@ public class TestModular extends junit.framework.TestCase { final long e = en[i][j][0]; final long answer = en[i][j][1]; final long s = m2.mod2(e); - if (s != answer) - assertEquals("e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s, answer, s); + if (s != answer) { + Assert.assertEquals( + "e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s, + answer, s); + } } } t.tick("montgomery.mod2"); for(int i = 0; i < en.length; i++) { final long n = en[i][0][0]; - final BigInteger N = BigInteger.valueOf(n); + final BigInteger N = BigInteger.valueOf(n); for(int j = 1; j < en[i].length; j++) { final long e = en[i][j][0]; final long answer = en[i][j][1]; final long s = TWO.modPow(BigInteger.valueOf(e), N).longValue(); - if (s != answer) - assertEquals("e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s, answer, s); + if (s != answer) { + Assert.assertEquals( + "e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s, + answer, s); + } } } t.tick("BigInteger.modPow(e, n)"); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestSummation.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestSummation.java b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestSummation.java index e80b9bb..2741962 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestSummation.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestSummation.java @@ -28,14 +28,19 @@ import org.apache.hadoop.examples.pi.Container; import org.apache.hadoop.examples.pi.Util; import org.apache.hadoop.examples.pi.Util.Timer; import org.apache.hadoop.examples.pi.math.TestModular.Montgomery2; +import org.junit.Test; +import org.junit.Assert; -public class TestSummation extends junit.framework.TestCase { +public class TestSummation { static final Random RANDOM = new Random(); static final BigInteger TWO = BigInteger.valueOf(2); + private static final double DOUBLE_DELTA = 0.000000001f; private static Summation2 newSummation(final long base, final long range, final long delta) { - final ArithmeticProgression N = new ArithmeticProgression('n', base+3, delta, base+3+range); - final ArithmeticProgression E = new ArithmeticProgression('e', base+range, -delta, base); + final ArithmeticProgression N = new ArithmeticProgression('n', base + 3, + delta, base + 3 + range); + final ArithmeticProgression E = new ArithmeticProgression('e', base + range, + -delta, base); return new Summation2(N, E); } @@ -53,10 +58,11 @@ public class TestSummation extends junit.framework.TestCase { final List<Summation> combined = Util.combine(a); // Util.out.println("combined=" + combined); - assertEquals(1, combined.size()); - assertEquals(sigma, combined.get(0)); + Assert.assertEquals(1, combined.size()); + Assert.assertEquals(sigma, combined.get(0)); } + @Test public void testSubtract() { final Summation sigma = newSummation(3, 10000, 20); final int size = 10; @@ -112,7 +118,9 @@ public class TestSummation extends junit.framework.TestCase { long n = N.value; double s = 0; for(; e > E.limit; e += E.delta) { - s = Modular.addMod(s, TWO.modPow(BigInteger.valueOf(e), BigInteger.valueOf(n)).doubleValue()/n); + s = Modular.addMod(s, + TWO.modPow(BigInteger.valueOf(e), BigInteger.valueOf(n)) + .doubleValue() / n); n += N.delta; } return s; @@ -124,16 +132,16 @@ public class TestSummation extends junit.framework.TestCase { t.tick("sigma=" + sigma); final double value = sigma.compute(); t.tick("compute=" + value); - assertEquals(value, sigma.compute_modular()); + Assert.assertEquals(value, sigma.compute_modular(), DOUBLE_DELTA); t.tick("compute_modular"); - assertEquals(value, sigma.compute_montgomery()); + Assert.assertEquals(value, sigma.compute_montgomery(), DOUBLE_DELTA); t.tick("compute_montgomery"); - assertEquals(value, sigma.compute_montgomery2()); + Assert.assertEquals(value, sigma.compute_montgomery2(), DOUBLE_DELTA); t.tick("compute_montgomery2"); - assertEquals(value, sigma.compute_modBigInteger()); + Assert.assertEquals(value, sigma.compute_modBigInteger(), DOUBLE_DELTA); t.tick("compute_modBigInteger"); - assertEquals(value, sigma.compute_modPow()); + Assert.assertEquals(value, sigma.compute_modPow(), DOUBLE_DELTA); t.tick("compute_modPow"); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-tools/hadoop-datajoin/src/test/java/org/apache/hadoop/contrib/utils/join/TestDataJoin.java ---------------------------------------------------------------------- diff --git a/hadoop-tools/hadoop-datajoin/src/test/java/org/apache/hadoop/contrib/utils/join/TestDataJoin.java b/hadoop-tools/hadoop-datajoin/src/test/java/org/apache/hadoop/contrib/utils/join/TestDataJoin.java index dbb8ef0..2daae2e 100644 --- a/hadoop-tools/hadoop-datajoin/src/test/java/org/apache/hadoop/contrib/utils/join/TestDataJoin.java +++ b/hadoop-tools/hadoop-datajoin/src/test/java/org/apache/hadoop/contrib/utils/join/TestDataJoin.java @@ -20,10 +20,10 @@ package org.apache.hadoop.contrib.utils.join; import java.io.IOException; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import junit.extensions.TestSetup; +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.hdfs.MiniDFSCluster; @@ -36,24 +36,27 @@ import org.apache.hadoop.io.SequenceFile; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapred.*; -public class TestDataJoin extends TestCase { - +/** + * Class to test JOIN between 2 data + * sources. + */ +public class TestDataJoin { private static MiniDFSCluster cluster = null; - public static Test suite() { - TestSetup setup = new TestSetup(new TestSuite(TestDataJoin.class)) { - protected void setUp() throws Exception { - Configuration conf = new Configuration(); - cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); - } - protected void tearDown() throws Exception { - if (cluster != null) { - cluster.shutdown(); - } - } - }; - return setup; + + @Before + public void setUp() throws Exception { + Configuration conf = new Configuration(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); + } + + @After + public void tearDown() throws Exception { + if (cluster != null) { + cluster.shutdown(); + } } + @Test public void testDataJoin() throws Exception { final int srcs = 4; JobConf job = new JobConf(); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-tools/hadoop-extras/src/test/java/org/apache/hadoop/tools/TestDistCh.java ---------------------------------------------------------------------- diff --git a/hadoop-tools/hadoop-extras/src/test/java/org/apache/hadoop/tools/TestDistCh.java b/hadoop-tools/hadoop-extras/src/test/java/org/apache/hadoop/tools/TestDistCh.java index 3704c5b..3e52b3c 100644 --- a/hadoop-tools/hadoop-extras/src/test/java/org/apache/hadoop/tools/TestDistCh.java +++ b/hadoop-tools/hadoop-extras/src/test/java/org/apache/hadoop/tools/TestDistCh.java @@ -38,11 +38,13 @@ import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.mapred.MiniMRClientClusterFactory; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; +import org.junit.Assert; +import org.junit.Test; import org.slf4j.event.Level; import static org.slf4j.LoggerFactory.getLogger; -public class TestDistCh extends junit.framework.TestCase { +public class TestDistCh { { GenericTestUtils.setLogLevel( getLogger("org.apache.hadoop.hdfs.StateChange"), Level.ERROR); @@ -75,20 +77,20 @@ public class TestDistCh extends junit.framework.TestCase { Path createSmallFile(Path dir) throws IOException { final Path f = new Path(dir, "f" + ++fcount); - assertTrue(!fs.exists(f)); + Assert.assertTrue(!fs.exists(f)); final DataOutputStream out = fs.create(f); try { out.writeBytes("createSmallFile: f=" + f); } finally { out.close(); } - assertTrue(fs.exists(f)); + Assert.assertTrue(fs.exists(f)); return f; } Path mkdir(Path dir) throws IOException { - assertTrue(fs.mkdirs(dir)); - assertTrue(fs.getFileStatus(dir).isDirectory()); + Assert.assertTrue(fs.mkdirs(dir)); + Assert.assertTrue(fs.getFileStatus(dir).isDirectory()); return dir; } @@ -127,7 +129,8 @@ public class TestDistCh extends junit.framework.TestCase { defaultPerm = permission == null || "".equals(permission); } } - + + @Test public void testDistCh() throws Exception { final Configuration conf = new Configuration(); @@ -190,13 +193,13 @@ public class TestDistCh extends junit.framework.TestCase { } static void checkFileStatus(ChPermissionStatus expected, FileStatus actual) { - assertEquals(expected.getUserName(), actual.getOwner()); - assertEquals(expected.getGroupName(), actual.getGroup()); + Assert.assertEquals(expected.getUserName(), actual.getOwner()); + Assert.assertEquals(expected.getGroupName(), actual.getGroup()); FsPermission perm = expected.getPermission(); if (actual.isFile() && expected.defaultPerm) { perm = perm.applyUMask(UMASK); } - assertEquals(perm, actual.getPermission()); + Assert.assertEquals(perm, actual.getPermission()); } private static String runLsr(final FsShell shell, String root, int returnvalue @@ -210,7 +213,7 @@ public class TestDistCh extends junit.framework.TestCase { System.setErr(out); final String results; try { - assertEquals(returnvalue, shell.run(new String[]{"-lsr", root})); + Assert.assertEquals(returnvalue, shell.run(new String[]{"-lsr", root})); results = bytes.toString(); } finally { IOUtils.closeStream(out); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-tools/hadoop-streaming/src/test/java/org/apache/hadoop/typedbytes/TestTypedBytesWritable.java ---------------------------------------------------------------------- diff --git a/hadoop-tools/hadoop-streaming/src/test/java/org/apache/hadoop/typedbytes/TestTypedBytesWritable.java b/hadoop-tools/hadoop-streaming/src/test/java/org/apache/hadoop/typedbytes/TestTypedBytesWritable.java index 3a81e42..1ca5436 100644 --- a/hadoop-tools/hadoop-streaming/src/test/java/org/apache/hadoop/typedbytes/TestTypedBytesWritable.java +++ b/hadoop-tools/hadoop-streaming/src/test/java/org/apache/hadoop/typedbytes/TestTypedBytesWritable.java @@ -26,10 +26,12 @@ import java.io.DataOutput; import java.io.DataOutputStream; import java.io.IOException; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; -public class TestTypedBytesWritable extends TestCase { +public class TestTypedBytesWritable { + @Test public void testToString() { TypedBytesWritable tbw = new TypedBytesWritable(); tbw.setValue(true); @@ -46,6 +48,7 @@ public class TestTypedBytesWritable extends TestCase { assertEquals("random text", tbw.toString()); } + @Test public void testIO() throws IOException { TypedBytesWritable tbw = new TypedBytesWritable(); tbw.setValue(12345); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8b7cbe38/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilterInitializer.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilterInitializer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilterInitializer.java index 63c2cf3..07478ca 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilterInitializer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilterInitializer.java @@ -22,20 +22,23 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.http.FilterContainer; import org.apache.hadoop.http.HttpConfig; import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.webapp.util.WebAppUtils; -import org.junit.Test; -public class TestAmFilterInitializer extends TestCase { +/** + * Test class for {@Link AmFilterInitializer}. + */ +public class TestAmFilterInitializer { - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { NetUtils.addStaticResolution("host1", "172.0.0.1"); NetUtils.addStaticResolution("host2", "172.0.0.1"); NetUtils.addStaticResolution("host3", "172.0.0.1"); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
