Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 45 additions & 30 deletions hadoop-mapreduce-project/hadoop-mapreduce-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,40 +70,40 @@
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<scope>test</scope>
<type>test-jar</type>
<exclusions>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-server-tests</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-app</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-app</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<scope>test</scope>
<type>test-jar</type>
<exclusions>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-server-tests</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-app</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-app</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-grizzly2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-hs</artifactId>
<scope>test</scope>
Expand All @@ -118,7 +118,7 @@
<groupId>org.apache.hadoop.thirdparty</groupId>
<artifactId>hadoop-shaded-guava</artifactId>
<scope>provided</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
}
}
Loading