From dcde414570510ff538e078a1e09a27dfff2b38b2 Mon Sep 17 00:00:00 2001 From: Ashutosh Gupta Date: Mon, 21 Nov 2022 05:36:35 +0000 Subject: [PATCH] MAPREDUCE-7422. Upgrade Junit 4 to 5 in hadoop-mapreduce-examples (#5029) Co-authored-by: Ashutosh Gupta Signed-off-by: Akira Ajisaka --- .../hadoop-mapreduce-examples/pom.xml | 75 +++++++++++-------- .../examples/TestAggregateWordCount.java | 18 +++-- .../examples/TestBaileyBorweinPlouffe.java | 25 ++++--- .../apache/hadoop/examples/TestWordStats.java | 23 +++--- .../hadoop/examples/pi/math/TestLongLong.java | 19 ++--- .../hadoop/examples/pi/math/TestModular.java | 55 ++++++-------- .../examples/pi/math/TestSummation.java | 27 +++---- .../examples/terasort/TestTeraSort.java | 22 ++++-- 8 files changed, 145 insertions(+), 119 deletions(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-examples/pom.xml b/hadoop-mapreduce-project/hadoop-mapreduce-examples/pom.xml index 16ce47579f..e5426a08b3 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-examples/pom.xml +++ b/hadoop-mapreduce-project/hadoop-mapreduce-examples/pom.xml @@ -70,40 +70,40 @@ runtime - org.apache.hadoop - hadoop-hdfs - test - test-jar - - - org.ow2.asm - asm-commons - - - - - org.apache.hadoop - hadoop-yarn-server-tests - test - test-jar - - - org.apache.hadoop - hadoop-mapreduce-client-app - provided - - - org.apache.hadoop - hadoop-mapreduce-client-app - test-jar - test - + org.apache.hadoop + hadoop-hdfs + test + test-jar + + + org.ow2.asm + asm-commons + + + + + org.apache.hadoop + hadoop-yarn-server-tests + test + test-jar + + + org.apache.hadoop + hadoop-mapreduce-client-app + provided + + + org.apache.hadoop + hadoop-mapreduce-client-app + test-jar + test + com.sun.jersey.jersey-test-framework jersey-test-framework-grizzly2 test - + org.apache.hadoop hadoop-mapreduce-client-hs test @@ -118,7 +118,7 @@ org.apache.hadoop.thirdparty hadoop-shaded-guava provided - + org.slf4j slf4j-api @@ -128,6 +128,21 @@ assertj-core test + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.platform + junit-platform-launcher + test + diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestAggregateWordCount.java b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestAggregateWordCount.java index 2bc909c0c3..9828b24d98 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestAggregateWordCount.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestAggregateWordCount.java @@ -21,8 +21,9 @@ import java.io.IOException; import java.nio.charset.Charset; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.apache.commons.io.IOUtils; import org.apache.hadoop.fs.FSDataInputStream; @@ -33,14 +34,19 @@ import org.apache.hadoop.util.ExitUtil; import org.apache.hadoop.util.ExitUtil.ExitException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestAggregateWordCount extends HadoopTestCase { public TestAggregateWordCount() throws IOException { super(LOCAL_MR, LOCAL_FS, 1, 1); } - @After + @BeforeEach + public void setUp() throws Exception { + super.setUp(); + } + + @AfterEach public void tearDown() throws Exception { FileSystem fs = getFileSystem(); if (fs != null) { @@ -58,7 +64,7 @@ public void tearDown() throws Exception { private static final Path OUTPUT_PATH = new Path(TEST_DIR, "outPath"); @Test - public void testAggregateTestCount() + void testAggregateTestCount() throws IOException, ClassNotFoundException, InterruptedException { ExitUtil.disableSystemExit(); @@ -70,7 +76,7 @@ public void testAggregateTestCount() FileUtil.write(fs, file2, "Hello Hadoop"); String[] args = - new String[] {INPUT_PATH.toString(), OUTPUT_PATH.toString(), "1", + new String[]{INPUT_PATH.toString(), OUTPUT_PATH.toString(), "1", "textinputformat"}; // Run AggregateWordCount Job. 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 2df2df0911..ffec884795 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,35 +18,36 @@ package org.apache.hadoop.examples; import java.math.BigInteger; -import org.junit.Test; -import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** Tests for BaileyBorweinPlouffe */ public class TestBaileyBorweinPlouffe { @Test - public void testMod() { + void testMod() { final BigInteger TWO = BigInteger.ONE.add(BigInteger.ONE); - for(long n = 3; n < 100; n++) { + 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(); - Assert.assertEquals("e=" + e + ", n=" + n, r, BaileyBorweinPlouffe - .mod(e, n)); + assertEquals(r, BaileyBorweinPlouffe + .mod(e, n), "e=" + e + ", n=" + n); } } } @Test - public void testHexDigit() { + void testHexDigit() { final long[] answers = {0x43F6, 0xA308, 0x29B7, 0x49F1, 0x8AC8, 0x35EA}; long d = 1; - for(int i = 0; i < answers.length; i++) { - Assert.assertEquals("d=" + d, answers[i], BaileyBorweinPlouffe - .hexDigits(d)); + for (int i = 0; i < answers.length; i++) { + assertEquals(answers[i], BaileyBorweinPlouffe + .hexDigits(d), "d=" + d); d *= 10; } - Assert.assertEquals(0x243FL, BaileyBorweinPlouffe.hexDigits(0)); - } + assertEquals(0x243FL, BaileyBorweinPlouffe.hexDigits(0)); + } } \ No newline at end of file diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestWordStats.java b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestWordStats.java index 3f0ffd63f6..45aa4102bd 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestWordStats.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/TestWordStats.java @@ -17,8 +17,6 @@ */ package org.apache.hadoop.examples; -import static org.junit.Assert.assertEquals; - import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -31,9 +29,11 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.util.ToolRunner; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestWordStats { @@ -241,13 +241,14 @@ public static boolean deleteDir(File dir) { return dir.delete(); } - @Before public void setup() throws Exception { + @BeforeEach public void setup() throws Exception { deleteDir(new File(MEAN_OUTPUT)); deleteDir(new File(MEDIAN_OUTPUT)); deleteDir(new File(STDDEV_OUTPUT)); } - @Test public void testGetTheMean() throws Exception { + @Test + void testGetTheMean() throws Exception { String args[] = new String[2]; args[0] = INPUT; args[1] = MEAN_OUTPUT; @@ -261,7 +262,8 @@ public static boolean deleteDir(File dir) { assertEquals(mean, wr.read(INPUT), 0.0); } - @Test public void testGetTheMedian() throws Exception { + @Test + void testGetTheMedian() throws Exception { String args[] = new String[2]; args[0] = INPUT; args[1] = MEDIAN_OUTPUT; @@ -275,7 +277,8 @@ public static boolean deleteDir(File dir) { assertEquals(median, wr.read(INPUT), 0.0); } - @Test public void testGetTheStandardDeviation() throws Exception { + @Test + void testGetTheStandardDeviation() throws Exception { String args[] = new String[2]; args[0] = INPUT; args[1] = STDDEV_OUTPUT; @@ -289,7 +292,7 @@ public static boolean deleteDir(File dir) { assertEquals(stddev, wr.read(INPUT), 0.0); } - @AfterClass public static void cleanup() throws Exception { + @AfterAll public static void cleanup() throws Exception { deleteDir(new File(MEAN_OUTPUT)); deleteDir(new File(MEDIAN_OUTPUT)); deleteDir(new File(STDDEV_OUTPUT)); 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 232c53f4d4..318306cf9c 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,8 +19,9 @@ import java.math.BigInteger; import java.util.Random; -import org.junit.Test; -import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestLongLong { @@ -39,12 +40,12 @@ static void verifyMultiplication(long a, long b) { "\na = %x\nb = %x\nll= " + ll + "\nbi= " + bi.toString(16) + "\n", a, b); //System.out.println(s); - Assert.assertEquals(s, bi, ll.toBigInteger()); + assertEquals(bi, ll.toBigInteger(), s); } @Test - public void testMultiplication() { - for(int i = 0; i < 100; i++) { + void testMultiplication() { + for (int i = 0; i < 100; i++) { final long a = nextPositiveLong(); final long b = nextPositiveLong(); verifyMultiplication(a, b); @@ -54,8 +55,8 @@ public void testMultiplication() { } @Test - public void testRightShift() { - for(int i = 0; i < 1000; i++) { + void testRightShift() { + for (int i = 0; i < 1000; i++) { final long a = nextPositiveLong(); final long b = nextPositiveLong(); verifyRightShift(a, b); @@ -69,12 +70,12 @@ private static void verifyRightShift(long a, long b) { final String s = String.format( "\na = %x\nb = %x\nll= " + ll + "\nbi= " + bi.toString(16) + "\n", a, b); - Assert.assertEquals(s, bi, ll.toBigInteger()); + assertEquals(bi, ll.toBigInteger(), s); for (int i = 0; i < LongLong.SIZE >> 1; i++) { final long result = ll.shiftRight(i) & MASK; final long expected = bi.shiftRight(i).longValue() & MASK; - Assert.assertEquals(s, expected, result); + assertEquals(expected, result, s); } } } 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 a75ec29d1c..96e70efc76 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,8 +21,9 @@ import java.util.Random; import org.apache.hadoop.examples.pi.Util.Timer; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestModular{ private static final Random RANDOM = new Random(); @@ -52,13 +53,13 @@ static long div(long sum, long r, long n) { } @Test - public void testDiv() { - for(long n = 2; n < 100; n++) - for(long r = 1; r < n; r++) { + 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 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); - Assert.assertEquals(s, b, a); + assertEquals(b, a, s); } } @@ -151,9 +152,8 @@ static void squareBenchmarks() { final long answer = rn[i][j][1]; final long s = square_slow(r, n); if (s != answer) { - Assert.assertEquals( - "r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, - answer, s); + assertEquals( + answer, s, "r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s); } } } @@ -168,9 +168,8 @@ static void squareBenchmarks() { final long answer = rn[i][j][1]; final long s = square(r, n, r2p64); if (s != answer) { - Assert.assertEquals( - "r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, - answer, s); + assertEquals( + answer, s, "r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s); } } } @@ -185,9 +184,8 @@ static void squareBenchmarks() { final BigInteger R = BigInteger.valueOf(r); final long s = R.multiply(R).mod(N).longValue(); if (s != answer) { - Assert.assertEquals( - "r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, - answer, s); + assertEquals( + answer, s, "r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s); } } } @@ -202,9 +200,8 @@ static void squareBenchmarks() { final BigInteger R = BigInteger.valueOf(r); final long s = R.modPow(TWO, N).longValue(); if (s != answer) { - Assert.assertEquals( - "r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s, - answer, s); + assertEquals( + answer, s, "r=" + r + ", n=" + n + ", answer=" + answer + " but s=" + s); } } } @@ -299,9 +296,8 @@ static void modBenchmarks() { final long answer = en[i][j][1]; final long s = Modular.mod(e, n); if (s != answer) { - Assert.assertEquals( - "e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s, - answer, s); + assertEquals( + answer, s, "e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s); } } } @@ -316,9 +312,8 @@ static void modBenchmarks() { final long answer = en[i][j][1]; final long s = m2.mod(e); if (s != answer) { - Assert.assertEquals( - "e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s, - answer, s); + assertEquals( + answer, s, "e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s); } } } @@ -332,9 +327,8 @@ static void modBenchmarks() { final long answer = en[i][j][1]; final long s = m2.mod2(e); if (s != answer) { - Assert.assertEquals( - "e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s, - answer, s); + assertEquals( + answer, s, "e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s); } } } @@ -348,9 +342,8 @@ static void modBenchmarks() { final long answer = en[i][j][1]; final long s = TWO.modPow(BigInteger.valueOf(e), N).longValue(); if (s != answer) { - Assert.assertEquals( - "e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s, - answer, s); + assertEquals( + answer, s, "e=" + e + ", n=" + n + ", answer=" + answer + " but s=" + s); } } } 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 2741962b32..92012ac4d9 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,8 +28,9 @@ 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; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestSummation { static final Random RANDOM = new Random(); @@ -58,12 +59,12 @@ private static void runTestSubtract(Summation sigma, List diff) { final List combined = Util.combine(a); // Util.out.println("combined=" + combined); - Assert.assertEquals(1, combined.size()); - Assert.assertEquals(sigma, combined.get(0)); + assertEquals(1, combined.size()); + assertEquals(sigma, combined.get(0)); } @Test - public void testSubtract() { + void testSubtract() { final Summation sigma = newSummation(3, 10000, 20); final int size = 10; final List parts = Arrays.asList(sigma.partition(size)); @@ -72,10 +73,10 @@ public void testSubtract() { runTestSubtract(sigma, new ArrayList()); runTestSubtract(sigma, parts); - for(int n = 1; n < size; n++) { - for(int j = 0; j < 10; j++) { + for (int n = 1; n < size; n++) { + for (int j = 0; j < 10; j++) { final List diff = new ArrayList(parts); - for(int i = 0; i < n; i++) + for (int i = 0; i < n; i++) diff.remove(RANDOM.nextInt(diff.size())); /// Collections.sort(diff); runTestSubtract(sigma, diff); @@ -132,16 +133,16 @@ private static void computeBenchmarks(final Summation2 sigma) { t.tick("sigma=" + sigma); final double value = sigma.compute(); t.tick("compute=" + value); - Assert.assertEquals(value, sigma.compute_modular(), DOUBLE_DELTA); + assertEquals(value, sigma.compute_modular(), DOUBLE_DELTA); t.tick("compute_modular"); - Assert.assertEquals(value, sigma.compute_montgomery(), DOUBLE_DELTA); + assertEquals(value, sigma.compute_montgomery(), DOUBLE_DELTA); t.tick("compute_montgomery"); - Assert.assertEquals(value, sigma.compute_montgomery2(), DOUBLE_DELTA); + assertEquals(value, sigma.compute_montgomery2(), DOUBLE_DELTA); t.tick("compute_montgomery2"); - Assert.assertEquals(value, sigma.compute_modBigInteger(), DOUBLE_DELTA); + assertEquals(value, sigma.compute_modBigInteger(), DOUBLE_DELTA); t.tick("compute_modBigInteger"); - Assert.assertEquals(value, sigma.compute_modPow(), DOUBLE_DELTA); + assertEquals(value, sigma.compute_modPow(), DOUBLE_DELTA); t.tick("compute_modPow"); } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/terasort/TestTeraSort.java b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/terasort/TestTeraSort.java index 1bc9f2f56a..ef1688c092 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/terasort/TestTeraSort.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/terasort/TestTeraSort.java @@ -25,14 +25,15 @@ import org.apache.hadoop.mapred.FileAlreadyExistsException; import org.apache.hadoop.mapred.HadoopTestCase; import org.apache.hadoop.util.ToolRunner; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class TestTeraSort extends HadoopTestCase { private static final Logger LOG = LoggerFactory.getLogger(TestTeraSort.class); @@ -42,7 +43,12 @@ public TestTeraSort() super(LOCAL_MR, LOCAL_FS, 1, 1); } - @After + @BeforeEach + public void setUp() throws Exception { + super.setUp(); + } + + @AfterEach public void tearDown() throws Exception { getFileSystem().delete(TEST_DIR, true); super.tearDown(); @@ -85,7 +91,7 @@ private void runTeraValidator(Configuration job, } @Test - public void testTeraSort() throws Exception { + void testTeraSort() throws Exception { // Run TeraGen to generate input for 'terasort' runTeraGen(createJobConf(), SORT_INPUT_PATH); @@ -110,11 +116,11 @@ public void testTeraSort() throws Exception { // Run tera-validator to check if sort worked correctly runTeraValidator(createJobConf(), SORT_OUTPUT_PATH, - TERA_OUTPUT_PATH); + TERA_OUTPUT_PATH); } @Test - public void testTeraSortWithLessThanTwoArgs() throws Exception { + void testTeraSortWithLessThanTwoArgs() throws Exception { String[] args = new String[1]; assertThat(new TeraSort().run(args)).isEqualTo(2); }