MAPREDUCE-7422. Upgrade Junit 4 to 5 in hadoop-mapreduce-examples (#5029)
Co-authored-by: Ashutosh Gupta <ashugpt@amazon.com> Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
This commit is contained in:
parent
c71a68ca80
commit
dcde414570
|
@ -128,6 +128,21 @@
|
|||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-launcher</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -21,8 +21,9 @@ import java.io.File;
|
|||
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.mapred.HadoopTestCase;
|
|||
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 class TestAggregateWordCount extends HadoopTestCase {
|
|||
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 class TestAggregateWordCount extends HadoopTestCase {
|
|||
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.
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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.FileStatus;
|
|||
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 class TestWordStats {
|
|||
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 class TestWordStats {
|
|||
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 class TestWordStats {
|
|||
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 class TestWordStats {
|
|||
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));
|
||||
|
|
|
@ -19,8 +19,9 @@ package org.apache.hadoop.examples.pi.math;
|
|||
|
||||
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 @@ public class TestLongLong {
|
|||
"\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 class TestLongLong {
|
|||
}
|
||||
|
||||
@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 @@ public class TestLongLong {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,9 @@ import java.math.BigInteger;
|
|||
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 @@ public class TestModular{
|
|||
}
|
||||
|
||||
@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 @@ public class TestModular{
|
|||
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 @@ public class TestModular{
|
|||
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 @@ public class TestModular{
|
|||
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 @@ public class TestModular{
|
|||
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 @@ public class TestModular{
|
|||
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 @@ public class TestModular{
|
|||
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 @@ public class TestModular{
|
|||
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 @@ public class TestModular{
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,9 @@ 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;
|
||||
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 @@ public class TestSummation {
|
|||
|
||||
final List<Summation> 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<Summation> parts = Arrays.asList(sigma.partition(size));
|
||||
|
@ -72,10 +73,10 @@ public class TestSummation {
|
|||
runTestSubtract(sigma, new ArrayList<Summation>());
|
||||
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<Summation> diff = new ArrayList<Summation>(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 @@ public class TestSummation {
|
|||
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");
|
||||
}
|
||||
|
||||
|
|
|
@ -25,14 +25,15 @@ import org.apache.hadoop.fs.Path;
|
|||
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 class TestTeraSort extends HadoopTestCase {
|
|||
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 @@ public class TestTeraSort extends HadoopTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTeraSort() throws Exception {
|
||||
void testTeraSort() throws Exception {
|
||||
// Run TeraGen to generate input for 'terasort'
|
||||
runTeraGen(createJobConf(), SORT_INPUT_PATH);
|
||||
|
||||
|
@ -114,7 +120,7 @@ public class TestTeraSort extends HadoopTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTeraSortWithLessThanTwoArgs() throws Exception {
|
||||
void testTeraSortWithLessThanTwoArgs() throws Exception {
|
||||
String[] args = new String[1];
|
||||
assertThat(new TeraSort().run(args)).isEqualTo(2);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue