Skip to content

Commit

Permalink
HADOOP-12564. Upgrade JUnit3 TestCase to JUnit 4 in org.apache.hadoop…
Browse files Browse the repository at this point in the history
….io package. Contributed by Dustin Cote.
  • Loading branch information
oza committed Nov 18, 2015
1 parent 169921e commit 989b9e3
Show file tree
Hide file tree
Showing 33 changed files with 398 additions and 207 deletions.
3 changes: 3 additions & 0 deletions hadoop-common-project/hadoop-common/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,9 @@ Release 2.8.0 - UNRELEASED
HADOOP-12568. Update core-default.xml to describe posixGroups support.
(Wei-Chiu Chuang via aajisaka)

HADOOP-12564. Upgrade JUnit3 TestCase to JUnit 4 in
org.apache.hadoop.io package. (Dustin Cote via ozawa)

OPTIMIZATIONS

HADOOP-11785. Reduce the number of listStatus operation in distcp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.avro.reflect.ReflectDatumReader;
import org.apache.avro.io.DecoderFactory;

import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertEquals;

public class AvroTestUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,30 @@

import java.io.*;

import junit.framework.TestCase;

import org.apache.commons.logging.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.SequenceFile.CompressionType;
import org.apache.hadoop.util.Progressable;
import org.apache.hadoop.conf.*;
import org.junit.Test;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;

/** Support for flat files of binary key/value pairs. */
public class TestArrayFile extends TestCase {
public class TestArrayFile {
private static final Log LOG = LogFactory.getLog(TestArrayFile.class);

private static final Path TEST_DIR = new Path(
System.getProperty("test.build.data", "/tmp"),
TestMapFile.class.getSimpleName());
private static String TEST_FILE = new Path(TEST_DIR, "test.array").toString();

public TestArrayFile(String name) {
super(name);
}

@Test
public void testArrayFile() throws Exception {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.getLocal(conf);
Expand All @@ -49,6 +52,7 @@ public void testArrayFile() throws Exception {
readTest(fs, data, TEST_FILE, conf);
}

@Test
public void testEmptyFile() throws Exception {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.getLocal(conf);
Expand Down Expand Up @@ -119,6 +123,7 @@ private static void readTest(FileSystem fs, RandomDatum[] data, String file, Con
* {@code next(), seek()} in and out of range.
* </pre>
*/
@Test
public void testArrayFileIteration() {
int SIZE = 10;
Configuration conf = new Configuration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import java.util.Arrays;

import org.apache.hadoop.util.StringUtils;
import org.junit.*;
import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import junit.framework.TestCase;

/** Unit tests for {@link ArrayPrimitiveWritable} */
public class TestArrayPrimitiveWritable extends TestCase {

public class TestArrayPrimitiveWritable {
static final boolean[] b = {true, true, false};
static final char[] c = {'a', 'b', 'c'};
static final byte[] by = {1, 2, 3};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,26 @@

import java.io.*;

import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertArrayEquals;
import org.junit.Test;

import junit.framework.TestCase;

/** Unit tests for ArrayWritable */
public class TestArrayWritable extends TestCase {

public class TestArrayWritable {
static class TextArrayWritable extends ArrayWritable {
public TextArrayWritable() {
super(Text.class);
}
}

public TestArrayWritable(String name) {
super(name);
}

/**
* If valueClass is undefined, readFields should throw an exception indicating
* that the field is null. Otherwise, readFields should succeed.
*/
@Test
public void testThrowUndefinedValueException() throws IOException {
// Get a buffer containing a simple text array
Text[] elements = {new Text("zero"), new Text("one"), new Text("two")};
Expand All @@ -67,6 +66,7 @@ public void testThrowUndefinedValueException() throws IOException {
/**
* test {@link ArrayWritable} toArray() method
*/
@Test
public void testArrayWritableToArray() {
Text[] elements = {new Text("zero"), new Text("one"), new Text("two")};
TextArrayWritable arrayWritable = new TextArrayWritable();
Expand All @@ -84,6 +84,7 @@ public void testArrayWritableToArray() {
/**
* test {@link ArrayWritable} constructor with null
*/
@Test
public void testNullArgument() {
try {
Class<? extends Writable> valueClass = null;
Expand All @@ -100,12 +101,13 @@ public void testNullArgument() {
* test {@link ArrayWritable} constructor with {@code String[]} as a parameter
*/
@SuppressWarnings("deprecation")
@Test
public void testArrayWritableStringConstructor() {
String[] original = { "test1", "test2", "test3" };
ArrayWritable arrayWritable = new ArrayWritable(original);
assertEquals("testArrayWritableStringConstructor class error!!!",
UTF8.class, arrayWritable.getValueClass());
Assert.assertArrayEquals("testArrayWritableStringConstructor toString error!!!",
assertArrayEquals("testArrayWritableStringConstructor toString error!!!",
original, arrayWritable.toStrings());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import java.util.Collections;
import java.util.List;

import junit.framework.TestCase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.LocalFileSystem;
Expand All @@ -41,26 +39,33 @@
import org.apache.hadoop.io.compress.Compressor;
import org.apache.hadoop.io.compress.Decompressor;
import org.apache.hadoop.util.Progressable;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Before;
import org.junit.Test;

public class TestBloomMapFile extends TestCase {
public class TestBloomMapFile {
private static Configuration conf = new Configuration();
private static final Path TEST_ROOT = new Path(
System.getProperty("test.build.data", "/tmp"),
TestMapFile.class.getSimpleName());
private static final Path TEST_DIR = new Path(TEST_ROOT, "testfile");
private static final Path TEST_FILE = new Path(TEST_ROOT, "testfile");

@Override
@Before
public void setUp() throws Exception {
LocalFileSystem fs = FileSystem.getLocal(conf);
if (fs.exists(TEST_ROOT) && !fs.delete(TEST_ROOT, true)) {
Assert.fail("Can't clean up test root dir");
fail("Can't clean up test root dir");
}
fs.mkdirs(TEST_ROOT);
}

@SuppressWarnings("deprecation")
@Test
public void testMembershipTest() throws Exception {
// write the file
FileSystem fs = FileSystem.getLocal(conf);
Expand Down Expand Up @@ -107,7 +112,7 @@ public void testMembershipTest() throws Exception {
}

@SuppressWarnings("deprecation")
private void checkMembershipVaryingSizedKeys(String name, List<Text> keys)
private void checkMembershipVaryingSizedKeys(List<Text> keys)
throws Exception {
FileSystem fs = FileSystem.getLocal(conf);
Path qualifiedDirName = fs.makeQualified(TEST_DIR);
Expand Down Expand Up @@ -135,23 +140,26 @@ private void checkMembershipVaryingSizedKeys(String name, List<Text> keys)
}
}

@Test
public void testMembershipVaryingSizedKeysTest1() throws Exception {
ArrayList<Text> list = new ArrayList<Text>();
list.add(new Text("A"));
list.add(new Text("BB"));
checkMembershipVaryingSizedKeys(getName(), list);
checkMembershipVaryingSizedKeys(list);
}

@Test
public void testMembershipVaryingSizedKeysTest2() throws Exception {
ArrayList<Text> list = new ArrayList<Text>();
list.add(new Text("AA"));
list.add(new Text("B"));
checkMembershipVaryingSizedKeys(getName(), list);
checkMembershipVaryingSizedKeys(list);
}

/**
* test {@code BloomMapFile.delete()} method
*/
@Test
public void testDeleteFile() {
BloomMapFile.Writer writer = null;
try {
Expand All @@ -173,6 +181,7 @@ public void testDeleteFile() {
* test {@link BloomMapFile.Reader} constructor with
* IOException
*/
@Test
public void testIOExceptionInWriterConstructor() {
Path dirNameSpy = spy(TEST_FILE);
BloomMapFile.Reader reader = null;
Expand All @@ -198,8 +207,9 @@ public void testIOExceptionInWriterConstructor() {
}

/**
* test {@link BloomMapFile.Reader.get()} method
* test {@link BloomMapFile.Reader#get(WritableComparable, Writable)} method
*/
@Test
public void testGetBloomMapFile() {
int SIZE = 10;
BloomMapFile.Reader reader = null;
Expand Down Expand Up @@ -235,6 +245,7 @@ public void testGetBloomMapFile() {
* test {@code BloomMapFile.Writer} constructors
*/
@SuppressWarnings("deprecation")
@Test
public void testBloomMapFileConstructors() {
BloomMapFile.Writer writer = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,25 @@

package org.apache.hadoop.io;

import org.junit.Test;

import java.io.IOException;

import junit.framework.TestCase;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Random;


/** Unit tests for BoundedByteArrayOutputStream */
public class TestBoundedByteArrayOutputStream extends TestCase {
public class TestBoundedByteArrayOutputStream {

private static final int SIZE = 1024;
private static final byte[] INPUT = new byte[SIZE];
static {
new Random().nextBytes(INPUT);
}


@Test
public void testBoundedStream() throws IOException {

BoundedByteArrayOutputStream stream =
Expand Down Expand Up @@ -102,7 +105,8 @@ public void resetBuffer(byte[] buf, int offset, int length) {
}

}


@Test
public void testResetBuffer() throws IOException {

ResettableBoundedByteArrayOutputStream stream =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@
import java.io.IOException;
import java.util.Random;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class TestDefaultStringifier extends TestCase {
public class TestDefaultStringifier {

private static Configuration conf = new Configuration();
private static final Log LOG = LogFactory.getLog(TestDefaultStringifier.class);

private char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();

@Test
public void testWithWritable() throws Exception {

conf.set("io.serializations", "org.apache.hadoop.io.serializer.WritableSerialization");
Expand Down Expand Up @@ -61,6 +62,7 @@ public void testWithWritable() throws Exception {
}
}

@Test
public void testWithJavaSerialization() throws Exception {
conf.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization");

Expand All @@ -77,6 +79,7 @@ public void testWithJavaSerialization() throws Exception {
assertEquals(testInt, claimedInt);
}

@Test
public void testStoreLoad() throws IOException {

LOG.info("Testing DefaultStringifier#store() and #load()");
Expand All @@ -92,6 +95,7 @@ public void testStoreLoad() throws IOException {

}

@Test
public void testStoreLoadArray() throws IOException {
LOG.info("Testing DefaultStringifier#storeArray() and #loadArray()");
conf.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization");
Expand Down
Loading

0 comments on commit 989b9e3

Please sign in to comment.