HADOOP-12564. Upgrade JUnit3 TestCase to JUnit 4 in org.apache.hadoop.io package. Contributed by Dustin Cote.

This commit is contained in:
Tsuyoshi Ozawa 2015-11-19 01:22:39 +09:00
parent 169921e8ab
commit 989b9e3e11
33 changed files with 398 additions and 207 deletions

View File

@ -959,6 +959,9 @@ Release 2.8.0 - UNRELEASED
HADOOP-12568. Update core-default.xml to describe posixGroups support. HADOOP-12568. Update core-default.xml to describe posixGroups support.
(Wei-Chiu Chuang via aajisaka) (Wei-Chiu Chuang via aajisaka)
HADOOP-12564. Upgrade JUnit3 TestCase to JUnit 4 in
org.apache.hadoop.io package. (Dustin Cote via ozawa)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-11785. Reduce the number of listStatus operation in distcp HADOOP-11785. Reduce the number of listStatus operation in distcp

View File

@ -28,7 +28,7 @@ import org.apache.avro.reflect.ReflectDatumWriter;
import org.apache.avro.reflect.ReflectDatumReader; import org.apache.avro.reflect.ReflectDatumReader;
import org.apache.avro.io.DecoderFactory; import org.apache.avro.io.DecoderFactory;
import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.assertEquals;
public class AvroTestUtil { public class AvroTestUtil {

View File

@ -20,16 +20,22 @@ package org.apache.hadoop.io;
import java.io.*; import java.io.*;
import junit.framework.TestCase;
import org.apache.commons.logging.*; import org.apache.commons.logging.*;
import org.apache.hadoop.fs.*; import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.SequenceFile.CompressionType; import org.apache.hadoop.io.SequenceFile.CompressionType;
import org.apache.hadoop.util.Progressable; import org.apache.hadoop.util.Progressable;
import org.apache.hadoop.conf.*; 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. */ /** 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 Log LOG = LogFactory.getLog(TestArrayFile.class);
private static final Path TEST_DIR = new Path( private static final Path TEST_DIR = new Path(
@ -37,10 +43,7 @@ public class TestArrayFile extends TestCase {
TestMapFile.class.getSimpleName()); TestMapFile.class.getSimpleName());
private static String TEST_FILE = new Path(TEST_DIR, "test.array").toString(); private static String TEST_FILE = new Path(TEST_DIR, "test.array").toString();
public TestArrayFile(String name) { @Test
super(name);
}
public void testArrayFile() throws Exception { public void testArrayFile() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);
@ -49,6 +52,7 @@ public class TestArrayFile extends TestCase {
readTest(fs, data, TEST_FILE, conf); readTest(fs, data, TEST_FILE, conf);
} }
@Test
public void testEmptyFile() throws Exception { public void testEmptyFile() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);
@ -119,6 +123,7 @@ public class TestArrayFile extends TestCase {
* {@code next(), seek()} in and out of range. * {@code next(), seek()} in and out of range.
* </pre> * </pre>
*/ */
@Test
public void testArrayFileIteration() { public void testArrayFileIteration() {
int SIZE = 10; int SIZE = 10;
Configuration conf = new Configuration(); Configuration conf = new Configuration();

View File

@ -22,13 +22,15 @@ import java.io.*;
import java.util.Arrays; import java.util.Arrays;
import org.apache.hadoop.util.StringUtils; 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} */ /** Unit tests for {@link ArrayPrimitiveWritable} */
public class TestArrayPrimitiveWritable extends TestCase { public class TestArrayPrimitiveWritable {
static final boolean[] b = {true, true, false}; static final boolean[] b = {true, true, false};
static final char[] c = {'a', 'b', 'c'}; static final char[] c = {'a', 'b', 'c'};
static final byte[] by = {1, 2, 3}; static final byte[] by = {1, 2, 3};

View File

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

View File

@ -27,8 +27,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.LocalFileSystem; import org.apache.hadoop.fs.LocalFileSystem;
@ -41,9 +39,15 @@ import org.apache.hadoop.io.compress.CompressionOutputStream;
import org.apache.hadoop.io.compress.Compressor; import org.apache.hadoop.io.compress.Compressor;
import org.apache.hadoop.io.compress.Decompressor; import org.apache.hadoop.io.compress.Decompressor;
import org.apache.hadoop.util.Progressable; 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 Configuration conf = new Configuration();
private static final Path TEST_ROOT = new Path( private static final Path TEST_ROOT = new Path(
System.getProperty("test.build.data", "/tmp"), System.getProperty("test.build.data", "/tmp"),
@ -51,16 +55,17 @@ public class TestBloomMapFile extends TestCase {
private static final Path TEST_DIR = new Path(TEST_ROOT, "testfile"); private static final Path TEST_DIR = new Path(TEST_ROOT, "testfile");
private static final Path TEST_FILE = new Path(TEST_ROOT, "testfile"); private static final Path TEST_FILE = new Path(TEST_ROOT, "testfile");
@Override @Before
public void setUp() throws Exception { public void setUp() throws Exception {
LocalFileSystem fs = FileSystem.getLocal(conf); LocalFileSystem fs = FileSystem.getLocal(conf);
if (fs.exists(TEST_ROOT) && !fs.delete(TEST_ROOT, true)) { 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); fs.mkdirs(TEST_ROOT);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Test
public void testMembershipTest() throws Exception { public void testMembershipTest() throws Exception {
// write the file // write the file
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);
@ -107,7 +112,7 @@ public class TestBloomMapFile extends TestCase {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void checkMembershipVaryingSizedKeys(String name, List<Text> keys) private void checkMembershipVaryingSizedKeys(List<Text> keys)
throws Exception { throws Exception {
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);
Path qualifiedDirName = fs.makeQualified(TEST_DIR); Path qualifiedDirName = fs.makeQualified(TEST_DIR);
@ -135,23 +140,26 @@ public class TestBloomMapFile extends TestCase {
} }
} }
@Test
public void testMembershipVaryingSizedKeysTest1() throws Exception { public void testMembershipVaryingSizedKeysTest1() throws Exception {
ArrayList<Text> list = new ArrayList<Text>(); ArrayList<Text> list = new ArrayList<Text>();
list.add(new Text("A")); list.add(new Text("A"));
list.add(new Text("BB")); list.add(new Text("BB"));
checkMembershipVaryingSizedKeys(getName(), list); checkMembershipVaryingSizedKeys(list);
} }
@Test
public void testMembershipVaryingSizedKeysTest2() throws Exception { public void testMembershipVaryingSizedKeysTest2() throws Exception {
ArrayList<Text> list = new ArrayList<Text>(); ArrayList<Text> list = new ArrayList<Text>();
list.add(new Text("AA")); list.add(new Text("AA"));
list.add(new Text("B")); list.add(new Text("B"));
checkMembershipVaryingSizedKeys(getName(), list); checkMembershipVaryingSizedKeys(list);
} }
/** /**
* test {@code BloomMapFile.delete()} method * test {@code BloomMapFile.delete()} method
*/ */
@Test
public void testDeleteFile() { public void testDeleteFile() {
BloomMapFile.Writer writer = null; BloomMapFile.Writer writer = null;
try { try {
@ -173,6 +181,7 @@ public class TestBloomMapFile extends TestCase {
* test {@link BloomMapFile.Reader} constructor with * test {@link BloomMapFile.Reader} constructor with
* IOException * IOException
*/ */
@Test
public void testIOExceptionInWriterConstructor() { public void testIOExceptionInWriterConstructor() {
Path dirNameSpy = spy(TEST_FILE); Path dirNameSpy = spy(TEST_FILE);
BloomMapFile.Reader reader = null; BloomMapFile.Reader reader = null;
@ -198,8 +207,9 @@ public class TestBloomMapFile extends TestCase {
} }
/** /**
* test {@link BloomMapFile.Reader.get()} method * test {@link BloomMapFile.Reader#get(WritableComparable, Writable)} method
*/ */
@Test
public void testGetBloomMapFile() { public void testGetBloomMapFile() {
int SIZE = 10; int SIZE = 10;
BloomMapFile.Reader reader = null; BloomMapFile.Reader reader = null;
@ -235,6 +245,7 @@ public class TestBloomMapFile extends TestCase {
* test {@code BloomMapFile.Writer} constructors * test {@code BloomMapFile.Writer} constructors
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Test
public void testBloomMapFileConstructors() { public void testBloomMapFileConstructors() {
BloomMapFile.Writer writer = null; BloomMapFile.Writer writer = null;
try { try {

View File

@ -18,15 +18,17 @@
package org.apache.hadoop.io; package org.apache.hadoop.io;
import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import junit.framework.TestCase; import static org.junit.Assert.assertTrue;
import java.util.Arrays; import java.util.Arrays;
import java.util.Random; import java.util.Random;
/** Unit tests for BoundedByteArrayOutputStream */ /** Unit tests for BoundedByteArrayOutputStream */
public class TestBoundedByteArrayOutputStream extends TestCase { public class TestBoundedByteArrayOutputStream {
private static final int SIZE = 1024; private static final int SIZE = 1024;
private static final byte[] INPUT = new byte[SIZE]; private static final byte[] INPUT = new byte[SIZE];
@ -34,6 +36,7 @@ public class TestBoundedByteArrayOutputStream extends TestCase {
new Random().nextBytes(INPUT); new Random().nextBytes(INPUT);
} }
@Test
public void testBoundedStream() throws IOException { public void testBoundedStream() throws IOException {
BoundedByteArrayOutputStream stream = BoundedByteArrayOutputStream stream =
@ -103,6 +106,7 @@ public class TestBoundedByteArrayOutputStream extends TestCase {
} }
@Test
public void testResetBuffer() throws IOException { public void testResetBuffer() throws IOException {
ResettableBoundedByteArrayOutputStream stream = ResettableBoundedByteArrayOutputStream stream =

View File

@ -21,19 +21,20 @@ package org.apache.hadoop.io;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; 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 Configuration conf = new Configuration();
private static final Log LOG = LogFactory.getLog(TestDefaultStringifier.class); private static final Log LOG = LogFactory.getLog(TestDefaultStringifier.class);
private char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray(); private char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
@Test
public void testWithWritable() throws Exception { public void testWithWritable() throws Exception {
conf.set("io.serializations", "org.apache.hadoop.io.serializer.WritableSerialization"); conf.set("io.serializations", "org.apache.hadoop.io.serializer.WritableSerialization");
@ -61,6 +62,7 @@ public class TestDefaultStringifier extends TestCase {
} }
} }
@Test
public void testWithJavaSerialization() throws Exception { public void testWithJavaSerialization() throws Exception {
conf.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization"); conf.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization");
@ -77,6 +79,7 @@ public class TestDefaultStringifier extends TestCase {
assertEquals(testInt, claimedInt); assertEquals(testInt, claimedInt);
} }
@Test
public void testStoreLoad() throws IOException { public void testStoreLoad() throws IOException {
LOG.info("Testing DefaultStringifier#store() and #load()"); LOG.info("Testing DefaultStringifier#store() and #load()");
@ -92,6 +95,7 @@ public class TestDefaultStringifier extends TestCase {
} }
@Test
public void testStoreLoadArray() throws IOException { public void testStoreLoadArray() throws IOException {
LOG.info("Testing DefaultStringifier#storeArray() and #loadArray()"); LOG.info("Testing DefaultStringifier#storeArray() and #loadArray()");
conf.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization"); conf.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization");

View File

@ -18,15 +18,20 @@
package org.apache.hadoop.io; package org.apache.hadoop.io;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import java.io.IOException; import java.io.IOException;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import junit.framework.TestCase;
/** Unit test for EnumSetWritable */ /** Unit test for EnumSetWritable */
public class TestEnumSetWritable extends TestCase { public class TestEnumSetWritable {
enum TestEnumSet { enum TestEnumSet {
CREATE, OVERWRITE, APPEND; CREATE, OVERWRITE, APPEND;
@ -37,6 +42,7 @@ public class TestEnumSetWritable extends TestCase {
new EnumSetWritable<TestEnumSet>(nonEmptyFlag); new EnumSetWritable<TestEnumSet>(nonEmptyFlag);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test
public void testSerializeAndDeserializeNonEmpty() throws IOException { public void testSerializeAndDeserializeNonEmpty() throws IOException {
DataOutputBuffer out = new DataOutputBuffer(); DataOutputBuffer out = new DataOutputBuffer();
ObjectWritable.writeObject(out, nonEmptyFlagWritable, nonEmptyFlagWritable ObjectWritable.writeObject(out, nonEmptyFlagWritable, nonEmptyFlagWritable
@ -51,6 +57,7 @@ public class TestEnumSetWritable extends TestCase {
EnumSet<TestEnumSet> emptyFlag = EnumSet.noneOf(TestEnumSet.class); EnumSet<TestEnumSet> emptyFlag = EnumSet.noneOf(TestEnumSet.class);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test
public void testSerializeAndDeserializeEmpty() throws IOException { public void testSerializeAndDeserializeEmpty() throws IOException {
boolean gotException = false; boolean gotException = false;
@ -78,6 +85,7 @@ public class TestEnumSetWritable extends TestCase {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test
public void testSerializeAndDeserializeNull() throws IOException { public void testSerializeAndDeserializeNull() throws IOException {
boolean gotException = false; boolean gotException = false;
@ -107,6 +115,7 @@ public class TestEnumSetWritable extends TestCase {
public EnumSetWritable<TestEnumSet> testField; public EnumSetWritable<TestEnumSet> testField;
@Test
public void testAvroReflect() throws Exception { public void testAvroReflect() throws Exception {
String schema = "{\"type\":\"array\",\"items\":{\"type\":\"enum\"," String schema = "{\"type\":\"array\",\"items\":{\"type\":\"enum\","
+ "\"name\":\"TestEnumSet\"," + "\"name\":\"TestEnumSet\","
@ -121,6 +130,7 @@ public class TestEnumSetWritable extends TestCase {
/** /**
* test {@link EnumSetWritable} equals() method * test {@link EnumSetWritable} equals() method
*/ */
@Test
public void testEnumSetWritableEquals() { public void testEnumSetWritableEquals() {
EnumSetWritable<TestEnumSet> eset1 = new EnumSetWritable<TestEnumSet>( EnumSetWritable<TestEnumSet> eset1 = new EnumSetWritable<TestEnumSet>(
EnumSet.of(TestEnumSet.APPEND, TestEnumSet.CREATE), TestEnumSet.class); EnumSet.of(TestEnumSet.APPEND, TestEnumSet.CREATE), TestEnumSet.class);
@ -139,6 +149,7 @@ public class TestEnumSetWritable extends TestCase {
* test {@code EnumSetWritable.write(DataOutputBuffer out)} * test {@code EnumSetWritable.write(DataOutputBuffer out)}
* and iteration by TestEnumSet through iterator(). * and iteration by TestEnumSet through iterator().
*/ */
@Test
public void testEnumSetWritableWriteRead() throws Exception { public void testEnumSetWritableWriteRead() throws Exception {
EnumSetWritable<TestEnumSet> srcSet = new EnumSetWritable<TestEnumSet>( EnumSetWritable<TestEnumSet> srcSet = new EnumSetWritable<TestEnumSet>(
EnumSet.of(TestEnumSet.APPEND, TestEnumSet.CREATE), TestEnumSet.class); EnumSet.of(TestEnumSet.APPEND, TestEnumSet.CREATE), TestEnumSet.class);

View File

@ -22,24 +22,27 @@ import java.io.DataInput;
import java.io.DataOutput; import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
/** /**
* TestCase for {@link GenericWritable} class. * TestCase for {@link GenericWritable} class.
* @see TestWritable#testWritable(Writable) * @see TestWritable#testWritable(Writable)
*/ */
public class TestGenericWritable extends TestCase { public class TestGenericWritable {
private Configuration conf; private Configuration conf;
public static final String CONF_TEST_KEY = "test.generic.writable"; public static final String CONF_TEST_KEY = "test.generic.writable";
public static final String CONF_TEST_VALUE = "dummy"; public static final String CONF_TEST_VALUE = "dummy";
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
conf = new Configuration(); conf = new Configuration();
//set the configuration parameter //set the configuration parameter
conf.set(CONF_TEST_KEY, CONF_TEST_VALUE); conf.set(CONF_TEST_KEY, CONF_TEST_VALUE);
@ -121,6 +124,7 @@ public class TestGenericWritable extends TestCase {
} }
} }
@Test
public void testFooWritable() throws Exception { public void testFooWritable() throws Exception {
System.out.println("Testing Writable wrapped in GenericWritable"); System.out.println("Testing Writable wrapped in GenericWritable");
FooGenericWritable generic = new FooGenericWritable(); FooGenericWritable generic = new FooGenericWritable();
@ -130,6 +134,7 @@ public class TestGenericWritable extends TestCase {
TestWritable.testWritable(generic); TestWritable.testWritable(generic);
} }
@Test
public void testBarWritable() throws Exception { public void testBarWritable() throws Exception {
System.out.println("Testing Writable, Configurable wrapped in GenericWritable"); System.out.println("Testing Writable, Configurable wrapped in GenericWritable");
FooGenericWritable generic = new FooGenericWritable(); FooGenericWritable generic = new FooGenericWritable();
@ -148,6 +153,7 @@ public class TestGenericWritable extends TestCase {
assertNotNull(((Configurable)after.get()).getConf()); assertNotNull(((Configurable)after.get()).getConf());
} }
@Test
public void testBazWritable() throws Exception { public void testBazWritable() throws Exception {
System.out.println("Testing for GenericWritable to find class names"); System.out.println("Testing for GenericWritable to find class names");
FooGenericWritable generic = new FooGenericWritable(); FooGenericWritable generic = new FooGenericWritable();
@ -157,6 +163,7 @@ public class TestGenericWritable extends TestCase {
TestWritable.testWritable(generic, conf); TestWritable.testWritable(generic, conf);
} }
@Test
public void testSet() throws Exception { public void testSet() throws Exception {
Foo foo = new Foo(); Foo foo = new Foo();
FooGenericWritable generic = new FooGenericWritable(); FooGenericWritable generic = new FooGenericWritable();
@ -174,6 +181,7 @@ public class TestGenericWritable extends TestCase {
} }
@Test
public void testGet() throws Exception { public void testGet() throws Exception {
Foo foo = new Foo(); Foo foo = new Foo();
FooGenericWritable generic = new FooGenericWritable(); FooGenericWritable generic = new FooGenericWritable();

View File

@ -18,8 +18,11 @@
package org.apache.hadoop.io; package org.apache.hadoop.io;
import org.apache.hadoop.io.TestWritable; import org.junit.Test;
import junit.framework.TestCase; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
@ -27,8 +30,7 @@ import java.security.MessageDigest;
import java.util.Random; import java.util.Random;
/** Unit tests for MD5Hash. */ /** Unit tests for MD5Hash. */
public class TestMD5Hash extends TestCase { public class TestMD5Hash {
public TestMD5Hash(String name) { super(name); }
private static final Random RANDOM = new Random(); private static final Random RANDOM = new Random();
@ -43,6 +45,7 @@ public class TestMD5Hash extends TestCase {
protected static byte[] D00 = new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; protected static byte[] D00 = new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
protected static byte[] DFF = new byte[] {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; protected static byte[] DFF = new byte[] {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
@Test
public void testMD5Hash() throws Exception { public void testMD5Hash() throws Exception {
MD5Hash md5Hash = getTestHash(); MD5Hash md5Hash = getTestHash();
@ -116,6 +119,7 @@ public class TestMD5Hash extends TestCase {
t2.join(); t2.join();
} }
@Test
public void testFactoryReturnsClearedHashes() throws IOException { public void testFactoryReturnsClearedHashes() throws IOException {
// A stream that will throw an IOE after reading some bytes // A stream that will throw an IOE after reading some bytes
ByteArrayInputStream failingStream = new ByteArrayInputStream( ByteArrayInputStream failingStream = new ByteArrayInputStream(

View File

@ -17,20 +17,25 @@
*/ */
package org.apache.hadoop.io; package org.apache.hadoop.io;
import org.junit.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.util.Map; import java.util.Map;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
/** /**
* Tests MapWritable * Tests MapWritable
*/ */
public class TestMapWritable extends TestCase { public class TestMapWritable {
/** the test */ /** the test */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test
public void testMapWritable() { public void testMapWritable() {
Text[] keys = { Text[] keys = {
new Text("key1"), new Text("key1"),
@ -91,6 +96,7 @@ public class TestMapWritable extends TestCase {
* Test that number of "unknown" classes is propagated across multiple copies. * Test that number of "unknown" classes is propagated across multiple copies.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Test
public void testForeignClass() { public void testForeignClass() {
MapWritable inMap = new MapWritable(); MapWritable inMap = new MapWritable();
inMap.put(new Text("key"), new UTF8("value")); inMap.put(new Text("key"), new UTF8("value"));
@ -105,10 +111,11 @@ public class TestMapWritable extends TestCase {
* @throws Exception * @throws Exception
* @see <a href="https://issues.apache.org/jira/browse/HADOOP-2244">HADOOP-2244</a> * @see <a href="https://issues.apache.org/jira/browse/HADOOP-2244">HADOOP-2244</a>
*/ */
@Test
public void testMultipleCallsToReadFieldsAreSafe() throws Exception { public void testMultipleCallsToReadFieldsAreSafe() throws Exception {
// Create an instance and add a key/value. // Create an instance and add a key/value.
MapWritable m = new MapWritable(); MapWritable m = new MapWritable();
final Text t = new Text(getName()); final Text t = new Text("testMultipleCallsToReadFieldsAreSafe");
m.put(t, t); m.put(t, t);
// Get current size of map. Key values are 't'. // Get current size of map. Key values are 't'.
int count = m.size(); int count = m.size();
@ -130,6 +137,7 @@ public class TestMapWritable extends TestCase {
dis.close(); dis.close();
} }
@Test
public void testEquality() { public void testEquality() {
MapWritable map1 = new MapWritable(); MapWritable map1 = new MapWritable();
MapWritable map2 = new MapWritable(); MapWritable map2 = new MapWritable();
@ -151,6 +159,7 @@ public class TestMapWritable extends TestCase {
} }
/** Verify text command outputs a useful representation for MapWritable. */ /** Verify text command outputs a useful representation for MapWritable. */
@Test
public void testToString() { public void testToString() {
MapWritable map = new MapWritable(); MapWritable map = new MapWritable();
final IntWritable key = new IntWritable(5); final IntWritable key = new IntWritable(5);

View File

@ -20,7 +20,6 @@ package org.apache.hadoop.io;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import junit.framework.TestCase;
import org.apache.commons.logging.*; import org.apache.commons.logging.*;
@ -32,20 +31,23 @@ import org.apache.hadoop.io.compress.DefaultCodec;
import org.apache.hadoop.io.serializer.avro.AvroReflectSerialization; import org.apache.hadoop.io.serializer.avro.AvroReflectSerialization;
import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.ReflectionUtils;
import org.apache.hadoop.conf.*; import org.apache.hadoop.conf.*;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNotNull;
import org.mockito.Mockito; import org.mockito.Mockito;
/** Support for flat files of binary key/value pairs. */ /** Support for flat files of binary key/value pairs. */
public class TestSequenceFile extends TestCase { public class TestSequenceFile {
private static final Log LOG = LogFactory.getLog(TestSequenceFile.class); private static final Log LOG = LogFactory.getLog(TestSequenceFile.class);
private Configuration conf = new Configuration(); private Configuration conf = new Configuration();
public TestSequenceFile() { }
public TestSequenceFile(String name) { super(name); }
/** Unit tests for SequenceFile. */ /** Unit tests for SequenceFile. */
@Test
public void testZlibSequenceFile() throws Exception { public void testZlibSequenceFile() throws Exception {
LOG.info("Testing SequenceFile with DefaultCodec"); LOG.info("Testing SequenceFile with DefaultCodec");
compressedSeqFileTest(new DefaultCodec()); compressedSeqFileTest(new DefaultCodec());
@ -309,6 +311,7 @@ public class TestSequenceFile extends TestCase {
} }
/** Unit tests for SequenceFile metadata. */ /** Unit tests for SequenceFile metadata. */
@Test
public void testSequenceFileMetadata() throws Exception { public void testSequenceFileMetadata() throws Exception {
LOG.info("Testing SequenceFile with metadata"); LOG.info("Testing SequenceFile with metadata");
int count = 1024 * 10; int count = 1024 * 10;
@ -410,6 +413,7 @@ public class TestSequenceFile extends TestCase {
sorter.sort(new Path[] { unsortedFile }, sortedFile, false); sorter.sort(new Path[] { unsortedFile }, sortedFile, false);
} }
@Test
public void testClose() throws IOException { public void testClose() throws IOException {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
LocalFileSystem fs = FileSystem.getLocal(conf); LocalFileSystem fs = FileSystem.getLocal(conf);
@ -466,6 +470,7 @@ public class TestSequenceFile extends TestCase {
* Test that makes sure the FileSystem passed to createWriter * Test that makes sure the FileSystem passed to createWriter
* @throws Exception * @throws Exception
*/ */
@Test
public void testCreateUsesFsArg() throws Exception { public void testCreateUsesFsArg() throws Exception {
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);
FileSystem spyFs = Mockito.spy(fs); FileSystem spyFs = Mockito.spy(fs);
@ -494,6 +499,7 @@ public class TestSequenceFile extends TestCase {
} }
} }
@Test
public void testCloseForErroneousSequenceFile() public void testCloseForErroneousSequenceFile()
throws IOException { throws IOException {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
@ -526,6 +532,7 @@ public class TestSequenceFile extends TestCase {
* Test to makes sure zero length sequence file is handled properly while * Test to makes sure zero length sequence file is handled properly while
* initializing. * initializing.
*/ */
@Test
public void testInitZeroLengthSequenceFile() throws IOException { public void testInitZeroLengthSequenceFile() throws IOException {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
LocalFileSystem fs = FileSystem.getLocal(conf); LocalFileSystem fs = FileSystem.getLocal(conf);
@ -548,6 +555,7 @@ public class TestSequenceFile extends TestCase {
* already created * already created
* @throws IOException * @throws IOException
*/ */
@Test
public void testCreateWriterOnExistingFile() throws IOException { public void testCreateWriterOnExistingFile() throws IOException {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);
@ -560,6 +568,7 @@ public class TestSequenceFile extends TestCase {
CompressionType.NONE, null, new Metadata()); CompressionType.NONE, null, new Metadata());
} }
@Test
public void testRecursiveSeqFileCreate() throws IOException { public void testRecursiveSeqFileCreate() throws IOException {
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);
Path name = new Path(new Path(System.getProperty("test.build.data","."), Path name = new Path(new Path(System.getProperty("test.build.data","."),
@ -582,6 +591,7 @@ public class TestSequenceFile extends TestCase {
// should succeed, fails if exception thrown // should succeed, fails if exception thrown
} }
@Test
public void testSerializationAvailability() throws IOException { public void testSerializationAvailability() throws IOException {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
Path path = new Path(System.getProperty("test.build.data", "."), Path path = new Path(System.getProperty("test.build.data", "."),

View File

@ -18,32 +18,37 @@
package org.apache.hadoop.io; package org.apache.hadoop.io;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile.Reader; import org.apache.hadoop.io.SequenceFile.Reader;
import org.apache.hadoop.io.SequenceFile.Writer; import org.apache.hadoop.io.SequenceFile.Writer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TestSequenceFileSerialization extends TestCase { import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertEquals;
public class TestSequenceFileSerialization {
private Configuration conf; private Configuration conf;
private FileSystem fs; private FileSystem fs;
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
conf = new Configuration(); conf = new Configuration();
conf.set("io.serializations", conf.set("io.serializations",
"org.apache.hadoop.io.serializer.JavaSerialization"); "org.apache.hadoop.io.serializer.JavaSerialization");
fs = FileSystem.getLocal(conf); fs = FileSystem.getLocal(conf);
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
fs.close(); fs.close();
} }
@Test
public void testJavaSerialization() throws Exception { public void testJavaSerialization() throws Exception {
Path file = new Path(System.getProperty("test.build.data",".") + Path file = new Path(System.getProperty("test.build.data",".") +
"/testseqser.seq"); "/testseqser.seq");

View File

@ -22,24 +22,28 @@ import java.io.*;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import junit.framework.TestCase;
import org.apache.commons.logging.*; import org.apache.commons.logging.*;
import org.apache.hadoop.fs.*; import org.apache.hadoop.fs.*;
import org.apache.hadoop.conf.*; import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.SequenceFile.CompressionType; import org.apache.hadoop.io.SequenceFile.CompressionType;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
/** Support for flat files of binary key/value pairs. */ /** Support for flat files of binary key/value pairs. */
public class TestSetFile extends TestCase { public class TestSetFile {
private static final Log LOG = LogFactory.getLog(TestSetFile.class); private static final Log LOG = LogFactory.getLog(TestSetFile.class);
private static String FILE = private static String FILE =
System.getProperty("test.build.data",".") + "/test.set"; System.getProperty("test.build.data",".") + "/test.set";
private static Configuration conf = new Configuration(); private static Configuration conf = new Configuration();
public TestSetFile(String name) { super(name); } @Test
public void testSetFile() throws Exception { public void testSetFile() throws Exception {
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);
try { try {
@ -58,6 +62,7 @@ public class TestSetFile extends TestCase {
* test {@code SetFile.Reader} methods * test {@code SetFile.Reader} methods
* next(), get() in combination * next(), get() in combination
*/ */
@Test
public void testSetFileAccessMethods() { public void testSetFileAccessMethods() {
try { try {
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);

View File

@ -18,7 +18,6 @@
package org.apache.hadoop.io; package org.apache.hadoop.io;
import junit.framework.TestCase;
import java.io.IOException; import java.io.IOException;
import java.nio.BufferUnderflowException; import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -26,11 +25,14 @@ import java.nio.charset.CharacterCodingException;
import java.util.Random; import java.util.Random;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/** Unit tests for LargeUTF8. */ /** Unit tests for LargeUTF8. */
public class TestText extends TestCase { public class TestText {
private static final int NUM_ITERATIONS = 100; private static final int NUM_ITERATIONS = 100;
public TestText(String name) { super(name); }
private static final Random RANDOM = new Random(1); private static final Random RANDOM = new Random(1);
@ -70,6 +72,7 @@ public class TestText extends TestCase {
return buffer.toString(); return buffer.toString();
} }
@Test
public void testWritable() throws Exception { public void testWritable() throws Exception {
for (int i = 0; i < NUM_ITERATIONS; i++) { for (int i = 0; i < NUM_ITERATIONS; i++) {
String str; String str;
@ -82,6 +85,7 @@ public class TestText extends TestCase {
} }
@Test
public void testCoding() throws Exception { public void testCoding() throws Exception {
String before = "Bad \t encoding \t testcase"; String before = "Bad \t encoding \t testcase";
Text text = new Text(before); Text text = new Text(before);
@ -101,15 +105,15 @@ public class TestText extends TestCase {
byte[] utf8Text = bb.array(); byte[] utf8Text = bb.array();
byte[] utf8Java = before.getBytes("UTF-8"); byte[] utf8Java = before.getBytes("UTF-8");
assertEquals(0, WritableComparator.compareBytes( assertEquals(0, WritableComparator.compareBytes(
utf8Text, 0, bb.limit(), utf8Text, 0, bb.limit(),
utf8Java, 0, utf8Java.length)); utf8Java, 0, utf8Java.length));
// test utf8 to string // test utf8 to string
after = Text.decode(utf8Java); after = Text.decode(utf8Java);
assertTrue(before.equals(after)); assertTrue(before.equals(after));
} }
} }
@Test
public void testIO() throws Exception { public void testIO() throws Exception {
DataOutputBuffer out = new DataOutputBuffer(); DataOutputBuffer out = new DataOutputBuffer();
DataInputBuffer in = new DataInputBuffer(); DataInputBuffer in = new DataInputBuffer();
@ -167,12 +171,14 @@ public class TestText extends TestCase {
assertTrue(str.equals(after)); assertTrue(str.equals(after));
} }
@Test
public void testLimitedIO() throws Exception { public void testLimitedIO() throws Exception {
doTestLimitedIO("abcd", 3); doTestLimitedIO("abcd", 3);
doTestLimitedIO("foo bar baz", 10); doTestLimitedIO("foo bar baz", 10);
doTestLimitedIO("1", 0); doTestLimitedIO("1", 0);
} }
@Test
public void testCompare() throws Exception { public void testCompare() throws Exception {
DataOutputBuffer out1 = new DataOutputBuffer(); DataOutputBuffer out1 = new DataOutputBuffer();
DataOutputBuffer out2 = new DataOutputBuffer(); DataOutputBuffer out2 = new DataOutputBuffer();
@ -223,14 +229,16 @@ public class TestText extends TestCase {
} }
} }
@Test
public void testFind() throws Exception { public void testFind() throws Exception {
Text text = new Text("abcd\u20acbdcd\u20ac"); Text text = new Text("abcd\u20acbdcd\u20ac");
assertTrue(text.find("abd")==-1); assertTrue(text.find("abd")==-1);
assertTrue(text.find("ac")==-1); assertTrue(text.find("ac") ==-1);
assertTrue(text.find("\u20ac")==4); assertTrue(text.find("\u20ac") == 4);
assertTrue(text.find("\u20ac", 5)==11); assertTrue(text.find("\u20ac", 5)==11);
} }
@Test
public void testFindAfterUpdatingContents() throws Exception { public void testFindAfterUpdatingContents() throws Exception {
Text text = new Text("abcd"); Text text = new Text("abcd");
text.set("a".getBytes()); text.set("a".getBytes());
@ -239,6 +247,7 @@ public class TestText extends TestCase {
assertEquals(text.find("b"), -1); assertEquals(text.find("b"), -1);
} }
@Test
public void testValidate() throws Exception { public void testValidate() throws Exception {
Text text = new Text("abcd\u20acbdcd\u20ac"); Text text = new Text("abcd\u20acbdcd\u20ac");
byte [] utf8 = text.getBytes(); byte [] utf8 = text.getBytes();
@ -246,14 +255,15 @@ public class TestText extends TestCase {
Text.validateUTF8(utf8, 0, length); Text.validateUTF8(utf8, 0, length);
} }
@Test
public void testClear() throws Exception { public void testClear() throws Exception {
// Test lengths on an empty text object // Test lengths on an empty text object
Text text = new Text(); Text text = new Text();
assertEquals( assertEquals(
"Actual string on an empty text object must be an empty string", "Actual string on an empty text object must be an empty string",
"", text.toString()); "", text.toString());
assertEquals("Underlying byte array length must be zero", assertEquals("Underlying byte array length must be zero",
0, text.getBytes().length); 0, text.getBytes().length);
assertEquals("String's length must be zero", assertEquals("String's length must be zero",
0, text.getLength()); 0, text.getLength());
@ -262,14 +272,15 @@ public class TestText extends TestCase {
int len = text.getLength(); int len = text.getLength();
text.clear(); text.clear();
assertEquals("String must be empty after clear()", assertEquals("String must be empty after clear()",
"", text.toString()); "", text.toString());
assertTrue( assertTrue(
"Length of the byte array must not decrease after clear()", "Length of the byte array must not decrease after clear()",
text.getBytes().length >= len); text.getBytes().length >= len);
assertEquals("Length of the string must be reset to 0 after clear()", assertEquals("Length of the string must be reset to 0 after clear()",
0, text.getLength()); 0, text.getLength());
} }
@Test
public void testTextText() throws CharacterCodingException { public void testTextText() throws CharacterCodingException {
Text a=new Text("abc"); Text a=new Text("abc");
Text b=new Text("a"); Text b=new Text("a");
@ -310,6 +321,7 @@ public class TestText extends TestCase {
} }
} }
@Test
public void testConcurrentEncodeDecode() throws Exception{ public void testConcurrentEncodeDecode() throws Exception{
Thread thread1 = new ConcurrentEncodeDecodeThread("apache"); Thread thread1 = new ConcurrentEncodeDecodeThread("apache");
Thread thread2 = new ConcurrentEncodeDecodeThread("hadoop"); Thread thread2 = new ConcurrentEncodeDecodeThread("hadoop");
@ -321,15 +333,17 @@ public class TestText extends TestCase {
thread2.join(); thread2.join();
} }
@Test
public void testAvroReflect() throws Exception { public void testAvroReflect() throws Exception {
AvroTestUtil.testReflect AvroTestUtil.testReflect
(new Text("foo"), (new Text("foo"),
"{\"type\":\"string\",\"java-class\":\"org.apache.hadoop.io.Text\"}"); "{\"type\":\"string\",\"java-class\":\"org.apache.hadoop.io.Text\"}");
} }
/** /**
* *
*/ */
@Test
public void testCharAt() { public void testCharAt() {
String line = "adsawseeeeegqewgasddga"; String line = "adsawseeeeegqewgasddga";
Text text = new Text(line); Text text = new Text(line);
@ -343,6 +357,7 @@ public class TestText extends TestCase {
/** /**
* test {@code Text} readFields/write operations * test {@code Text} readFields/write operations
*/ */
@Test
public void testReadWriteOperations() { public void testReadWriteOperations() {
String line = "adsawseeeeegqewgasddga"; String line = "adsawseeeeegqewgasddga";
byte[] inputBytes = line.getBytes(); byte[] inputBytes = line.getBytes();
@ -365,6 +380,7 @@ public class TestText extends TestCase {
} }
} }
@Test
public void testReadWithKnownLength() throws IOException { public void testReadWithKnownLength() throws IOException {
String line = "hello world"; String line = "hello world";
byte[] inputBytes = line.getBytes(Charsets.UTF_8); byte[] inputBytes = line.getBytes(Charsets.UTF_8);
@ -391,6 +407,7 @@ public class TestText extends TestCase {
* with {@code BufferUnderflowException} * with {@code BufferUnderflowException}
* *
*/ */
@Test
public void testBytesToCodePoint() { public void testBytesToCodePoint() {
try { try {
ByteBuffer bytes = ByteBuffer.wrap(new byte[] {-2, 45, 23, 12, 76, 89}); ByteBuffer bytes = ByteBuffer.wrap(new byte[] {-2, 45, 23, 12, 76, 89});
@ -403,6 +420,7 @@ public class TestText extends TestCase {
} }
} }
@Test
public void testbytesToCodePointWithInvalidUTF() { public void testbytesToCodePointWithInvalidUTF() {
try { try {
Text.bytesToCodePoint(ByteBuffer.wrap(new byte[] {-2})); Text.bytesToCodePoint(ByteBuffer.wrap(new byte[] {-2}));
@ -413,29 +431,20 @@ public class TestText extends TestCase {
} }
} }
@Test
public void testUtf8Length() { public void testUtf8Length() {
assertEquals("testUtf8Length1 error !!!", assertEquals("testUtf8Length1 error !!!",
1, Text.utf8Length(new String(new char[]{(char)1}))); 1, Text.utf8Length(new String(new char[]{(char) 1})));
assertEquals("testUtf8Length127 error !!!", assertEquals("testUtf8Length127 error !!!",
1, Text.utf8Length(new String(new char[]{(char)127}))); 1, Text.utf8Length(new String(new char[]{(char) 127})));
assertEquals("testUtf8Length128 error !!!", assertEquals("testUtf8Length128 error !!!",
2, Text.utf8Length(new String(new char[]{(char)128}))); 2, Text.utf8Length(new String(new char[]{(char) 128})));
assertEquals("testUtf8Length193 error !!!", assertEquals("testUtf8Length193 error !!!",
2, Text.utf8Length(new String(new char[]{(char)193}))); 2, Text.utf8Length(new String(new char[]{(char) 193})));
assertEquals("testUtf8Length225 error !!!", assertEquals("testUtf8Length225 error !!!",
2, Text.utf8Length(new String(new char[]{(char)225}))); 2, Text.utf8Length(new String(new char[]{(char) 225})));
assertEquals("testUtf8Length254 error !!!", assertEquals("testUtf8Length254 error !!!",
2, Text.utf8Length(new String(new char[]{(char)254}))); 2, Text.utf8Length(new String(new char[]{(char)254})));
} }
public static void main(String[] args) throws Exception
{
TestText test = new TestText("main");
test.testIO();
test.testCompare();
test.testCoding();
test.testWritable();
test.testFind();
test.testValidate();
}
} }

View File

@ -18,14 +18,17 @@
package org.apache.hadoop.io; package org.apache.hadoop.io;
import junit.framework.TestCase; import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.nio.charset.MalformedInputException; import java.nio.charset.MalformedInputException;
import java.util.Arrays; import java.util.Arrays;
/** Unit tests for NonUTF8. */ /** Unit tests for NonUTF8. */
public class TestTextNonUTF8 extends TestCase { public class TestTextNonUTF8 {
@Test
public void testNonUTF8() throws Exception{ public void testNonUTF8() throws Exception{
// this is a non UTF8 byte array // this is a non UTF8 byte array
byte b[] = {-0x01, -0x01, -0x01, -0x01, -0x01, -0x01, -0x01}; byte b[] = {-0x01, -0x01, -0x01, -0x01, -0x01, -0x01, -0x01};
@ -44,9 +47,4 @@ public class TestTextNonUTF8 extends TestCase {
assertTrue(Arrays.equals(b, ret)); assertTrue(Arrays.equals(b, ret));
} }
public static void main(String[] args) throws Exception
{
TestTextNonUTF8 test = new TestTextNonUTF8();
test.testNonUTF8();
}
} }

View File

@ -18,7 +18,6 @@
package org.apache.hadoop.io; package org.apache.hadoop.io;
import junit.framework.TestCase;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
@ -28,11 +27,14 @@ import java.util.Random;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/** Unit tests for UTF8. */ /** Unit tests for UTF8. */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class TestUTF8 extends TestCase { public class TestUTF8 {
public TestUTF8(String name) { super(name); }
private static final Random RANDOM = new Random(); private static final Random RANDOM = new Random();
@ -45,12 +47,14 @@ public class TestUTF8 extends TestCase {
return buffer.toString(); return buffer.toString();
} }
@Test
public void testWritable() throws Exception { public void testWritable() throws Exception {
for (int i = 0; i < 10000; i++) { for (int i = 0; i < 10000; i++) {
TestWritable.testWritable(new UTF8(getTestString())); TestWritable.testWritable(new UTF8(getTestString()));
} }
} }
@Test
public void testGetBytes() throws Exception { public void testGetBytes() throws Exception {
for (int i = 0; i < 10000; i++) { for (int i = 0; i < 10000; i++) {
@ -73,6 +77,7 @@ public class TestUTF8 extends TestCase {
return dis.readUTF(); return dis.readUTF();
} }
@Test
public void testIO() throws Exception { public void testIO() throws Exception {
DataOutputBuffer out = new DataOutputBuffer(); DataOutputBuffer out = new DataOutputBuffer();
DataInputBuffer in = new DataInputBuffer(); DataInputBuffer in = new DataInputBuffer();
@ -98,6 +103,7 @@ public class TestUTF8 extends TestCase {
} }
@Test
public void testNullEncoding() throws Exception { public void testNullEncoding() throws Exception {
String s = new String(new char[] { 0 }); String s = new String(new char[] { 0 });
@ -112,6 +118,7 @@ public class TestUTF8 extends TestCase {
* *
* This is a regression test for HADOOP-9103. * This is a regression test for HADOOP-9103.
*/ */
@Test
public void testNonBasicMultilingualPlane() throws Exception { public void testNonBasicMultilingualPlane() throws Exception {
// Test using the "CAT FACE" character (U+1F431) // Test using the "CAT FACE" character (U+1F431)
// See http://www.fileformat.info/info/unicode/char/1f431/index.htm // See http://www.fileformat.info/info/unicode/char/1f431/index.htm
@ -130,6 +137,7 @@ public class TestUTF8 extends TestCase {
/** /**
* Test that decoding invalid UTF8 throws an appropriate error message. * Test that decoding invalid UTF8 throws an appropriate error message.
*/ */
@Test
public void testInvalidUTF8() throws Exception { public void testInvalidUTF8() throws Exception {
byte[] invalid = new byte[] { byte[] invalid = new byte[] {
0x01, 0x02, (byte)0xff, (byte)0xff, 0x01, 0x02, 0x03, 0x04, 0x05 }; 0x01, 0x02, (byte)0xff, (byte)0xff, 0x01, 0x02, 0x03, 0x04, 0x05 };
@ -145,6 +153,7 @@ public class TestUTF8 extends TestCase {
/** /**
* Test for a 5-byte UTF8 sequence, which is now considered illegal. * Test for a 5-byte UTF8 sequence, which is now considered illegal.
*/ */
@Test
public void test5ByteUtf8Sequence() throws Exception { public void test5ByteUtf8Sequence() throws Exception {
byte[] invalid = new byte[] { byte[] invalid = new byte[] {
0x01, 0x02, (byte)0xf8, (byte)0x88, (byte)0x80, 0x01, 0x02, (byte)0xf8, (byte)0x88, (byte)0x80,
@ -162,6 +171,7 @@ public class TestUTF8 extends TestCase {
* Test that decoding invalid UTF8 due to truncation yields the correct * Test that decoding invalid UTF8 due to truncation yields the correct
* exception type. * exception type.
*/ */
@Test
public void testInvalidUTF8Truncated() throws Exception { public void testInvalidUTF8Truncated() throws Exception {
// Truncated CAT FACE character -- this is a 4-byte sequence, but we // Truncated CAT FACE character -- this is a 4-byte sequence, but we
// only have the first three bytes. // only have the first three bytes.

View File

@ -18,16 +18,14 @@
package org.apache.hadoop.io; package org.apache.hadoop.io;
import org.junit.Test;
import java.io.*; import java.io.*;
import java.util.Random; import java.util.Random;
import junit.framework.TestCase;
/** Unit tests for VersionedWritable. */ /** Unit tests for VersionedWritable. */
public class TestVersionedWritable extends TestCase { public class TestVersionedWritable {
public TestVersionedWritable(String name) { super(name); }
/** Example class used in test cases below. */ /** Example class used in test cases below. */
public static class SimpleVersionedWritable extends VersionedWritable { public static class SimpleVersionedWritable extends VersionedWritable {
@ -149,16 +147,19 @@ public class TestVersionedWritable extends TestCase {
/** Test 1: Check that SimpleVersionedWritable. */ /** Test 1: Check that SimpleVersionedWritable. */
@Test
public void testSimpleVersionedWritable() throws Exception { public void testSimpleVersionedWritable() throws Exception {
TestWritable.testWritable(new SimpleVersionedWritable()); TestWritable.testWritable(new SimpleVersionedWritable());
} }
/** Test 2: Check that AdvancedVersionedWritable Works (well, why wouldn't it!). */ /** Test 2: Check that AdvancedVersionedWritable Works (well, why wouldn't it!). */
@Test
public void testAdvancedVersionedWritable() throws Exception { public void testAdvancedVersionedWritable() throws Exception {
TestWritable.testWritable(new AdvancedVersionedWritable()); TestWritable.testWritable(new AdvancedVersionedWritable());
} }
/** Test 3: Check that SimpleVersionedWritable throws an Exception. */ /** Test 3: Check that SimpleVersionedWritable throws an Exception. */
@Test
public void testSimpleVersionedWritableMismatch() throws Exception { public void testSimpleVersionedWritableMismatch() throws Exception {
TestVersionedWritable.testVersionedWritable(new SimpleVersionedWritable(), new SimpleVersionedWritableV2()); TestVersionedWritable.testVersionedWritable(new SimpleVersionedWritable(), new SimpleVersionedWritableV2());
} }

View File

@ -27,17 +27,20 @@ import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.ReflectionUtils;
import junit.framework.TestCase; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/** Unit tests for Writable. */ /** Unit tests for Writable. */
public class TestWritable extends TestCase { public class TestWritable {
private static final String TEST_CONFIG_PARAM = "frob.test"; private static final String TEST_CONFIG_PARAM = "frob.test";
private static final String TEST_CONFIG_VALUE = "test"; private static final String TEST_CONFIG_VALUE = "test";
private static final String TEST_WRITABLE_CONFIG_PARAM = "test.writable"; private static final String TEST_WRITABLE_CONFIG_PARAM = "test.writable";
private static final String TEST_WRITABLE_CONFIG_VALUE = TEST_CONFIG_VALUE; private static final String TEST_WRITABLE_CONFIG_VALUE = TEST_CONFIG_VALUE;
public TestWritable(String name) { super(name); }
/** Example class used in test cases below. */ /** Example class used in test cases below. */
public static class SimpleWritable implements Writable { public static class SimpleWritable implements Writable {
private static final Random RANDOM = new Random(); private static final Random RANDOM = new Random();
@ -90,18 +93,19 @@ private static final String TEST_WRITABLE_CONFIG_VALUE = TEST_CONFIG_VALUE;
} }
/** Test 1: Check that SimpleWritable. */ /** Test 1: Check that SimpleWritable. */
@Test
public void testSimpleWritable() throws Exception { public void testSimpleWritable() throws Exception {
testWritable(new SimpleWritable()); testWritable(new SimpleWritable());
} }
@Test
public void testByteWritable() throws Exception { public void testByteWritable() throws Exception {
testWritable(new ByteWritable((byte)128)); testWritable(new ByteWritable((byte)128));
} }
@Test
public void testShortWritable() throws Exception { public void testShortWritable() throws Exception {
testWritable(new ShortWritable((byte)256)); testWritable(new ShortWritable((byte)256));
} }
@Test
public void testDoubleWritable() throws Exception { public void testDoubleWritable() throws Exception {
testWritable(new DoubleWritable(1.0)); testWritable(new DoubleWritable(1.0));
} }
@ -180,6 +184,7 @@ private static final String TEST_WRITABLE_CONFIG_VALUE = TEST_CONFIG_VALUE;
* Test a user comparator that relies on deserializing both arguments for each * Test a user comparator that relies on deserializing both arguments for each
* compare. * compare.
*/ */
@Test
public void testShortWritableComparator() throws Exception { public void testShortWritableComparator() throws Exception {
ShortWritable writable1 = new ShortWritable((short)256); ShortWritable writable1 = new ShortWritable((short)256);
ShortWritable writable2 = new ShortWritable((short) 128); ShortWritable writable2 = new ShortWritable((short) 128);
@ -206,6 +211,7 @@ private static final String TEST_WRITABLE_CONFIG_VALUE = TEST_CONFIG_VALUE;
/** /**
* Test that Writable's are configured by Comparator. * Test that Writable's are configured by Comparator.
*/ */
@Test
public void testConfigurableWritableComparator() throws Exception { public void testConfigurableWritableComparator() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set(TEST_WRITABLE_CONFIG_PARAM, TEST_WRITABLE_CONFIG_VALUE); conf.set(TEST_WRITABLE_CONFIG_PARAM, TEST_WRITABLE_CONFIG_VALUE);

View File

@ -24,14 +24,12 @@ import java.io.IOException;
import java.util.Random; import java.util.Random;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.junit.Test;
import junit.framework.TestCase; import static org.junit.Assert.assertTrue;
/** Unit tests for WritableName. */ /** Unit tests for WritableName. */
public class TestWritableName extends TestCase { public class TestWritableName {
public TestWritableName(String name) {
super(name);
}
/** Example class used in test cases below. */ /** Example class used in test cases below. */
public static class SimpleWritable implements Writable { public static class SimpleWritable implements Writable {
@ -67,12 +65,14 @@ public class TestWritableName extends TestCase {
private static final String testName = "mystring"; private static final String testName = "mystring";
@Test
public void testGoodName() throws Exception { public void testGoodName() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
Class<?> test = WritableName.getClass("long",conf); Class<?> test = WritableName.getClass("long",conf);
assertTrue(test != null); assertTrue(test != null);
} }
@Test
public void testSetName() throws Exception { public void testSetName() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
WritableName.setName(SimpleWritable.class, testName); WritableName.setName(SimpleWritable.class, testName);
@ -81,7 +81,7 @@ public class TestWritableName extends TestCase {
assertTrue(test.equals(SimpleWritable.class)); assertTrue(test.equals(SimpleWritable.class));
} }
@Test
public void testAddName() throws Exception { public void testAddName() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
String altName = testName + ".alt"; String altName = testName + ".alt";
@ -98,6 +98,7 @@ public class TestWritableName extends TestCase {
} }
@Test
public void testBadName() throws Exception { public void testBadName() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
try { try {

View File

@ -22,13 +22,15 @@ import java.io.IOException;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class TestWritableUtils extends TestCase { public class TestWritableUtils {
private static final Log LOG = LogFactory.getLog(TestWritableUtils.class); private static final Log LOG = LogFactory.getLog(TestWritableUtils.class);
public static void testValue(int val, int vintlen) throws IOException { private void testValue(int val, int vintlen) throws IOException {
DataOutputBuffer buf = new DataOutputBuffer(); DataOutputBuffer buf = new DataOutputBuffer();
DataInputBuffer inbuf = new DataInputBuffer(); DataInputBuffer inbuf = new DataInputBuffer();
WritableUtils.writeVInt(buf, val); WritableUtils.writeVInt(buf, val);
@ -44,8 +46,7 @@ public class TestWritableUtils extends TestCase {
assertEquals(vintlen, WritableUtils.getVIntSize(val)); assertEquals(vintlen, WritableUtils.getVIntSize(val));
assertEquals(vintlen, WritableUtils.decodeVIntSize(buf.getData()[0])); assertEquals(vintlen, WritableUtils.decodeVIntSize(buf.getData()[0]));
} }
private void testReadInRange(long val, int lower,
public static void testReadInRange(long val, int lower,
int upper, boolean expectSuccess) throws IOException { int upper, boolean expectSuccess) throws IOException {
DataOutputBuffer buf = new DataOutputBuffer(); DataOutputBuffer buf = new DataOutputBuffer();
DataInputBuffer inbuf = new DataInputBuffer(); DataInputBuffer inbuf = new DataInputBuffer();
@ -65,7 +66,8 @@ public class TestWritableUtils extends TestCase {
} }
} }
public static void testVInt() throws Exception { @Test
public void testVInt() throws Exception {
testValue(12, 1); testValue(12, 1);
testValue(127, 1); testValue(127, 1);
testValue(-112, 1); testValue(-112, 1);

View File

@ -23,12 +23,15 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.*; import java.util.*;
import junit.framework.TestCase;
import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
public class TestCodecFactory extends TestCase { import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class TestCodecFactory {
private static class BaseCodec implements CompressionCodec { private static class BaseCodec implements CompressionCodec {
private Configuration conf; private Configuration conf;
@ -139,7 +142,8 @@ public class TestCodecFactory extends TestCase {
actual.getClass().getName()); actual.getClass().getName());
} }
public static void testFinding() { @Test
public void testFinding() {
CompressionCodecFactory factory = CompressionCodecFactory factory =
new CompressionCodecFactory(new Configuration()); new CompressionCodecFactory(new Configuration());
CompressionCodec codec = factory.getCodec(new Path("/tmp/foo.bar")); CompressionCodec codec = factory.getCodec(new Path("/tmp/foo.bar"));

View File

@ -35,9 +35,10 @@ import org.apache.hadoop.io.compress.zlib.ZlibCompressor.CompressionLevel;
import org.apache.hadoop.io.compress.zlib.ZlibCompressor.CompressionStrategy; import org.apache.hadoop.io.compress.zlib.ZlibCompressor.CompressionStrategy;
import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.ReflectionUtils;
import junit.framework.TestCase; import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class TestCompressionStreamReuse extends TestCase { public class TestCompressionStreamReuse {
private static final Log LOG = LogFactory private static final Log LOG = LogFactory
.getLog(TestCompressionStreamReuse.class); .getLog(TestCompressionStreamReuse.class);
@ -45,16 +46,19 @@ public class TestCompressionStreamReuse extends TestCase {
private int count = 10000; private int count = 10000;
private int seed = new Random().nextInt(); private int seed = new Random().nextInt();
@Test
public void testBZip2Codec() throws IOException { public void testBZip2Codec() throws IOException {
resetStateTest(conf, seed, count, resetStateTest(conf, seed, count,
"org.apache.hadoop.io.compress.BZip2Codec"); "org.apache.hadoop.io.compress.BZip2Codec");
} }
@Test
public void testGzipCompressStreamReuse() throws IOException { public void testGzipCompressStreamReuse() throws IOException {
resetStateTest(conf, seed, count, resetStateTest(conf, seed, count,
"org.apache.hadoop.io.compress.GzipCodec"); "org.apache.hadoop.io.compress.GzipCodec");
} }
@Test
public void testGzipCompressStreamReuseWithParam() throws IOException { public void testGzipCompressStreamReuseWithParam() throws IOException {
Configuration conf = new Configuration(this.conf); Configuration conf = new Configuration(this.conf);
ZlibFactory ZlibFactory
@ -65,7 +69,7 @@ public class TestCompressionStreamReuse extends TestCase {
"org.apache.hadoop.io.compress.GzipCodec"); "org.apache.hadoop.io.compress.GzipCodec");
} }
private static void resetStateTest(Configuration conf, int seed, int count, private void resetStateTest(Configuration conf, int seed, int count,
String codecClass) throws IOException { String codecClass) throws IOException {
// Create the codec // Create the codec
CompressionCodec codec = null; CompressionCodec codec = null;

View File

@ -22,7 +22,6 @@ import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataInputStream;
@ -32,12 +31,18 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.file.tfile.TFile.Reader; import org.apache.hadoop.io.file.tfile.TFile.Reader;
import org.apache.hadoop.io.file.tfile.TFile.Writer; import org.apache.hadoop.io.file.tfile.TFile.Writer;
import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner; import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
/** /**
* test tfile features. * test tfile features.
* *
*/ */
public class TestTFile extends TestCase { public class TestTFile {
private static String ROOT = private static String ROOT =
System.getProperty("test.build.data", "/tmp/tfile-test"); System.getProperty("test.build.data", "/tmp/tfile-test");
private FileSystem fs; private FileSystem fs;
@ -46,13 +51,13 @@ public class TestTFile extends TestCase {
private static final int largeVal = 3 * 1024 * 1024; private static final int largeVal = 3 * 1024 * 1024;
private static final String localFormatter = "%010d"; private static final String localFormatter = "%010d";
@Override @Before
public void setUp() throws IOException { public void setUp() throws IOException {
conf = new Configuration(); conf = new Configuration();
fs = FileSystem.get(conf); fs = FileSystem.get(conf);
} }
@Override @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
// do nothing // do nothing
} }
@ -348,12 +353,14 @@ public class TestTFile extends TestCase {
fs.delete(uTfile, true); fs.delete(uTfile, true);
} }
@Test
public void testTFileFeatures() throws IOException { public void testTFileFeatures() throws IOException {
basicWithSomeCodec("none"); basicWithSomeCodec("none");
basicWithSomeCodec("gz"); basicWithSomeCodec("gz");
} }
// test unsorted t files. // test unsorted t files.
@Test
public void testUnsortedTFileFeatures() throws IOException { public void testUnsortedTFileFeatures() throws IOException {
unsortedWithSomeCodec("none"); unsortedWithSomeCodec("none");
unsortedWithSomeCodec("gz"); unsortedWithSomeCodec("gz");
@ -414,6 +421,7 @@ public class TestTFile extends TestCase {
} }
// test meta blocks for tfiles // test meta blocks for tfiles
@Test
public void testMetaBlocks() throws IOException { public void testMetaBlocks() throws IOException {
Path mFile = new Path(ROOT, "meta.tfile"); Path mFile = new Path(ROOT, "meta.tfile");
FSDataOutputStream fout = createFSOutput(mFile); FSDataOutputStream fout = createFSOutput(mFile);

View File

@ -20,7 +20,10 @@ package org.apache.hadoop.io.file.tfile;
import java.io.IOException; import java.io.IOException;
import org.junit.Assert; import org.junit.Assert;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
@ -34,7 +37,7 @@ import org.apache.hadoop.io.file.tfile.TFile.Writer;
* and LZO compression classes. * and LZO compression classes.
* *
*/ */
public class TestTFileComparators extends TestCase { public class TestTFileComparators {
private static String ROOT = private static String ROOT =
System.getProperty("test.build.data", "/tmp/tfile-test"); System.getProperty("test.build.data", "/tmp/tfile-test");
@ -56,7 +59,7 @@ public class TestTFileComparators extends TestCase {
private int records1stBlock = 4480; private int records1stBlock = 4480;
private int records2ndBlock = 4263; private int records2ndBlock = 4263;
@Override @Before
public void setUp() throws IOException { public void setUp() throws IOException {
conf = new Configuration(); conf = new Configuration();
path = new Path(ROOT, outputFile); path = new Path(ROOT, outputFile);
@ -64,12 +67,13 @@ public class TestTFileComparators extends TestCase {
out = fs.create(path); out = fs.create(path);
} }
@Override @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
fs.delete(path, true); fs.delete(path, true);
} }
// bad comparator format // bad comparator format
@Test
public void testFailureBadComparatorNames() throws IOException { public void testFailureBadComparatorNames() throws IOException {
try { try {
writer = new Writer(out, BLOCK_SIZE, compression, "badcmp", conf); writer = new Writer(out, BLOCK_SIZE, compression, "badcmp", conf);
@ -82,6 +86,7 @@ public class TestTFileComparators extends TestCase {
} }
// jclass that doesn't exist // jclass that doesn't exist
@Test
public void testFailureBadJClassNames() throws IOException { public void testFailureBadJClassNames() throws IOException {
try { try {
writer = writer =
@ -96,6 +101,7 @@ public class TestTFileComparators extends TestCase {
} }
// class exists but not a RawComparator // class exists but not a RawComparator
@Test
public void testFailureBadJClasses() throws IOException { public void testFailureBadJClasses() throws IOException {
try { try {
writer = writer =

View File

@ -21,7 +21,11 @@ import java.io.IOException;
import java.util.Random; import java.util.Random;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.CommandLineParser;
@ -46,7 +50,7 @@ import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner;
* test the performance for seek. * test the performance for seek.
* *
*/ */
public class TestTFileSeek extends TestCase { public class TestTFileSeek {
private MyOptions options; private MyOptions options;
private Configuration conf; private Configuration conf;
private Path path; private Path path;
@ -56,7 +60,7 @@ public class TestTFileSeek extends TestCase {
private DiscreteRNG keyLenGen; private DiscreteRNG keyLenGen;
private KVGenerator kvGen; private KVGenerator kvGen;
@Override @Before
public void setUp() throws IOException { public void setUp() throws IOException {
if (options == null) { if (options == null) {
options = new MyOptions(new String[0]); options = new MyOptions(new String[0]);
@ -83,7 +87,7 @@ public class TestTFileSeek extends TestCase {
options.dictSize); options.dictSize);
} }
@Override @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
fs.delete(path, true); fs.delete(path, true);
} }
@ -176,6 +180,7 @@ public class TestTFileSeek extends TestCase {
} }
@Test
public void testSeeks() throws IOException { public void testSeeks() throws IOException {
String[] supported = TFile.getSupportedCompressionAlgorithms(); String[] supported = TFile.getSupportedCompressionAlgorithms();
boolean proceed = false; boolean proceed = false;

View File

@ -23,7 +23,10 @@ import java.text.SimpleDateFormat;
import java.util.Random; import java.util.Random;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.CommandLineParser;
@ -33,7 +36,6 @@ import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
@ -45,7 +47,7 @@ import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner.Entry; import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner.Entry;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
public class TestTFileSeqFileComparison extends TestCase { public class TestTFileSeqFileComparison {
MyOptions options; MyOptions options;
private FileSystem fs; private FileSystem fs;
@ -55,7 +57,7 @@ public class TestTFileSeqFileComparison extends TestCase {
private DateFormat formatter; private DateFormat formatter;
byte[][] dictionary; byte[][] dictionary;
@Override @Before
public void setUp() throws IOException { public void setUp() throws IOException {
if (options == null) { if (options == null) {
options = new MyOptions(new String[0]); options = new MyOptions(new String[0]);
@ -82,7 +84,7 @@ public class TestTFileSeqFileComparison extends TestCase {
} }
} }
@Override @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
// do nothing // do nothing
} }
@ -479,6 +481,7 @@ public class TestTFileSeqFileComparison extends TestCase {
readSeqFile(parameters, true); readSeqFile(parameters, true);
} }
@Test
public void testRunComparisons() throws IOException { public void testRunComparisons() throws IOException {
String[] compresses = new String[] { "none", "lzo", "gz" }; String[] compresses = new String[] { "none", "lzo", "gz" };
for (String compress : compresses) { for (String compress : compresses) {

View File

@ -19,8 +19,10 @@ package org.apache.hadoop.io.file.tfile;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import org.junit.Assert; import org.junit.Test;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
@ -31,7 +33,7 @@ import org.apache.hadoop.io.file.tfile.TFile.Reader;
import org.apache.hadoop.io.file.tfile.TFile.Writer; import org.apache.hadoop.io.file.tfile.TFile.Writer;
import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner; import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner;
public class TestTFileSplit extends TestCase { public class TestTFileSplit {
private static String ROOT = private static String ROOT =
System.getProperty("test.build.data", "/tmp/tfile-test"); System.getProperty("test.build.data", "/tmp/tfile-test");
@ -86,10 +88,10 @@ public class TestTFileSplit extends TestCase {
scanner.advance(); scanner.advance();
} }
scanner.close(); scanner.close();
Assert.assertTrue(count > 0); assertTrue(count > 0);
rowCount += count; rowCount += count;
} }
Assert.assertEquals(rowCount, reader.getEntryCount()); assertEquals(rowCount, reader.getEntryCount());
reader.close(); reader.close();
} }
@ -122,11 +124,11 @@ public class TestTFileSplit extends TestCase {
++x; ++x;
} }
scanner.close(); scanner.close();
Assert.assertTrue(count == (endRec - startRec)); assertTrue(count == (endRec - startRec));
} }
// make sure specifying range at the end gives zero records. // make sure specifying range at the end gives zero records.
Scanner scanner = reader.createScannerByRecordNum(totalRecords, -1); Scanner scanner = reader.createScannerByRecordNum(totalRecords, -1);
Assert.assertTrue(scanner.atEnd()); assertTrue(scanner.atEnd());
} }
static String composeSortedKey(String prefix, int total, int value) { static String composeSortedKey(String prefix, int total, int value) {
@ -176,6 +178,7 @@ public class TestTFileSplit extends TestCase {
} }
} }
@Test
public void testSplit() throws IOException { public void testSplit() throws IOException {
System.out.println("testSplit"); System.out.println("testSplit");
createFile(100000, Compression.Algorithm.NONE.getName()); createFile(100000, Compression.Algorithm.NONE.getName());

View File

@ -22,8 +22,12 @@ import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import org.junit.Assert; import static org.junit.Assert.fail;
import junit.framework.TestCase; import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
@ -41,7 +45,7 @@ import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner;
* *
*/ */
public class TestTFileStreams extends TestCase { public class TestTFileStreams {
private static String ROOT = private static String ROOT =
System.getProperty("test.build.data", "/tmp/tfile-test"); System.getProperty("test.build.data", "/tmp/tfile-test");
@ -64,7 +68,7 @@ public class TestTFileStreams extends TestCase {
this.comparator = comparator; this.comparator = comparator;
} }
@Override @Before
public void setUp() throws IOException { public void setUp() throws IOException {
conf = new Configuration(); conf = new Configuration();
path = new Path(ROOT, outputFile); path = new Path(ROOT, outputFile);
@ -73,7 +77,7 @@ public class TestTFileStreams extends TestCase {
writer = new Writer(out, BLOCK_SIZE, compression, comparator, conf); writer = new Writer(out, BLOCK_SIZE, compression, comparator, conf);
} }
@Override @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
if (!skip) { if (!skip) {
try { try {
@ -85,6 +89,7 @@ public class TestTFileStreams extends TestCase {
} }
} }
@Test
public void testNoEntry() throws IOException { public void testNoEntry() throws IOException {
if (skip) if (skip)
return; return;
@ -92,6 +97,7 @@ public class TestTFileStreams extends TestCase {
TestTFileByteArrays.readRecords(fs, path, 0, conf); TestTFileByteArrays.readRecords(fs, path, 0, conf);
} }
@Test
public void testOneEntryKnownLength() throws IOException { public void testOneEntryKnownLength() throws IOException {
if (skip) if (skip)
return; return;
@ -100,6 +106,7 @@ public class TestTFileStreams extends TestCase {
TestTFileByteArrays.readRecords(fs, path, 1, conf); TestTFileByteArrays.readRecords(fs, path, 1, conf);
} }
@Test
public void testOneEntryUnknownLength() throws IOException { public void testOneEntryUnknownLength() throws IOException {
if (skip) if (skip)
return; return;
@ -111,6 +118,7 @@ public class TestTFileStreams extends TestCase {
} }
// known key length, unknown value length // known key length, unknown value length
@Test
public void testOneEntryMixedLengths1() throws IOException { public void testOneEntryMixedLengths1() throws IOException {
if (skip) if (skip)
return; return;
@ -120,6 +128,7 @@ public class TestTFileStreams extends TestCase {
} }
// unknown key length, known value length // unknown key length, known value length
@Test
public void testOneEntryMixedLengths2() throws IOException { public void testOneEntryMixedLengths2() throws IOException {
if (skip) if (skip)
return; return;
@ -128,6 +137,7 @@ public class TestTFileStreams extends TestCase {
TestTFileByteArrays.readRecords(fs, path, 1, conf); TestTFileByteArrays.readRecords(fs, path, 1, conf);
} }
@Test
public void testTwoEntriesKnownLength() throws IOException { public void testTwoEntriesKnownLength() throws IOException {
if (skip) if (skip)
return; return;
@ -137,6 +147,7 @@ public class TestTFileStreams extends TestCase {
} }
// Negative test // Negative test
@Test
public void testFailureAddKeyWithoutValue() throws IOException { public void testFailureAddKeyWithoutValue() throws IOException {
if (skip) if (skip)
return; return;
@ -151,6 +162,7 @@ public class TestTFileStreams extends TestCase {
} }
} }
@Test
public void testFailureAddValueWithoutKey() throws IOException { public void testFailureAddValueWithoutKey() throws IOException {
if (skip) if (skip)
return; return;
@ -170,6 +182,7 @@ public class TestTFileStreams extends TestCase {
} }
} }
@Test
public void testFailureOneEntryKnownLength() throws IOException { public void testFailureOneEntryKnownLength() throws IOException {
if (skip) if (skip)
return; return;
@ -192,6 +205,7 @@ public class TestTFileStreams extends TestCase {
} }
} }
@Test
public void testFailureKeyTooLong() throws IOException { public void testFailureKeyTooLong() throws IOException {
if (skip) if (skip)
return; return;
@ -199,7 +213,7 @@ public class TestTFileStreams extends TestCase {
try { try {
outKey.write("key0".getBytes()); outKey.write("key0".getBytes());
outKey.close(); outKey.close();
Assert.fail("Key is longer than requested."); fail("Key is longer than requested.");
} }
catch (Exception e) { catch (Exception e) {
// noop, expecting an exception // noop, expecting an exception
@ -208,6 +222,7 @@ public class TestTFileStreams extends TestCase {
} }
} }
@Test
public void testFailureKeyTooShort() throws IOException { public void testFailureKeyTooShort() throws IOException {
if (skip) if (skip)
return; return;
@ -218,7 +233,7 @@ public class TestTFileStreams extends TestCase {
try { try {
outValue.write("value0".getBytes()); outValue.write("value0".getBytes());
outValue.close(); outValue.close();
Assert.fail("Value is shorter than expected."); fail("Value is shorter than expected.");
} }
catch (Exception e) { catch (Exception e) {
// noop, expecting an exception // noop, expecting an exception
@ -227,6 +242,7 @@ public class TestTFileStreams extends TestCase {
} }
} }
@Test
public void testFailureValueTooLong() throws IOException { public void testFailureValueTooLong() throws IOException {
if (skip) if (skip)
return; return;
@ -237,7 +253,7 @@ public class TestTFileStreams extends TestCase {
try { try {
outValue.write("value0".getBytes()); outValue.write("value0".getBytes());
outValue.close(); outValue.close();
Assert.fail("Value is longer than expected."); fail("Value is longer than expected.");
} }
catch (Exception e) { catch (Exception e) {
// noop, expecting an exception // noop, expecting an exception
@ -248,10 +264,11 @@ public class TestTFileStreams extends TestCase {
outKey.close(); outKey.close();
} }
catch (Exception e) { catch (Exception e) {
Assert.fail("Second or more close() should have no effect."); fail("Second or more close() should have no effect.");
} }
} }
@Test
public void testFailureValueTooShort() throws IOException { public void testFailureValueTooShort() throws IOException {
if (skip) if (skip)
return; return;
@ -259,7 +276,7 @@ public class TestTFileStreams extends TestCase {
try { try {
outKey.write("key0".getBytes()); outKey.write("key0".getBytes());
outKey.close(); outKey.close();
Assert.fail("Key is shorter than expected."); fail("Key is shorter than expected.");
} }
catch (Exception e) { catch (Exception e) {
// noop, expecting an exception // noop, expecting an exception
@ -268,6 +285,7 @@ public class TestTFileStreams extends TestCase {
} }
} }
@Test
public void testFailureCloseKeyStreamManyTimesInWriter() throws IOException { public void testFailureCloseKeyStreamManyTimesInWriter() throws IOException {
if (skip) if (skip)
return; return;
@ -289,15 +307,16 @@ public class TestTFileStreams extends TestCase {
} }
outKey.close(); outKey.close();
outKey.close(); outKey.close();
Assert.assertTrue("Multiple close should have no effect.", true); assertTrue("Multiple close should have no effect.", true);
} }
@Test
public void testFailureKeyLongerThan64K() throws IOException { public void testFailureKeyLongerThan64K() throws IOException {
if (skip) if (skip)
return; return;
try { try {
DataOutputStream outKey = writer.prepareAppendKey(64 * K + 1); DataOutputStream outKey = writer.prepareAppendKey(64 * K + 1);
Assert.fail("Failed to handle key longer than 64K."); fail("Failed to handle key longer than 64K.");
} }
catch (IndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
// noop, expecting exceptions // noop, expecting exceptions
@ -305,6 +324,7 @@ public class TestTFileStreams extends TestCase {
closeOutput(); closeOutput();
} }
@Test
public void testFailureKeyLongerThan64K_2() throws IOException { public void testFailureKeyLongerThan64K_2() throws IOException {
if (skip) if (skip)
return; return;
@ -317,7 +337,7 @@ public class TestTFileStreams extends TestCase {
outKey.write(buf); outKey.write(buf);
} }
outKey.close(); outKey.close();
Assert.fail("Failed to handle key longer than 64K."); fail("Failed to handle key longer than 64K.");
} }
catch (EOFException e) { catch (EOFException e) {
// noop, expecting exceptions // noop, expecting exceptions
@ -332,6 +352,7 @@ public class TestTFileStreams extends TestCase {
} }
} }
@Test
public void testFailureNegativeOffset() throws IOException { public void testFailureNegativeOffset() throws IOException {
if (skip) if (skip)
return; return;
@ -342,7 +363,7 @@ public class TestTFileStreams extends TestCase {
byte[] buf = new byte[K]; byte[] buf = new byte[K];
try { try {
scanner.entry().getKey(buf, -1); scanner.entry().getKey(buf, -1);
Assert.fail("Failed to handle key negative offset."); fail("Failed to handle key negative offset.");
} }
catch (Exception e) { catch (Exception e) {
// noop, expecting exceptions // noop, expecting exceptions
@ -358,22 +379,24 @@ public class TestTFileStreams extends TestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testFailureCompressionNotWorking() throws IOException { public void testFailureCompressionNotWorking() throws IOException {
if (skip) if (skip)
return; return;
long rawDataSize = writeRecords(10000, false, false, false); long rawDataSize = writeRecords(10000, false, false, false);
if (!compression.equalsIgnoreCase(Compression.Algorithm.NONE.getName())) { if (!compression.equalsIgnoreCase(Compression.Algorithm.NONE.getName())) {
Assert.assertTrue(out.getPos() < rawDataSize); assertTrue(out.getPos() < rawDataSize);
} }
closeOutput(); closeOutput();
} }
@Test
public void testFailureCompressionNotWorking2() throws IOException { public void testFailureCompressionNotWorking2() throws IOException {
if (skip) if (skip)
return; return;
long rawDataSize = writeRecords(10000, true, true, false); long rawDataSize = writeRecords(10000, true, true, false);
if (!compression.equalsIgnoreCase(Compression.Algorithm.NONE.getName())) { if (!compression.equalsIgnoreCase(Compression.Algorithm.NONE.getName())) {
Assert.assertTrue(out.getPos() < rawDataSize); assertTrue(out.getPos() < rawDataSize);
} }
closeOutput(); closeOutput();
} }

View File

@ -19,8 +19,8 @@ package org.apache.hadoop.io.file.tfile;
import java.io.IOException; import java.io.IOException;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
@ -29,8 +29,10 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.file.tfile.TFile.Reader; import org.apache.hadoop.io.file.tfile.TFile.Reader;
import org.apache.hadoop.io.file.tfile.TFile.Writer; import org.apache.hadoop.io.file.tfile.TFile.Writer;
import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner; import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner;
import org.junit.Before;
import org.junit.Test;
public class TestTFileUnsortedByteArrays extends TestCase { public class TestTFileUnsortedByteArrays {
private static String ROOT = private static String ROOT =
System.getProperty("test.build.data", "/tmp/tfile-test"); System.getProperty("test.build.data", "/tmp/tfile-test");
@ -61,7 +63,7 @@ public class TestTFileUnsortedByteArrays extends TestCase {
this.records2ndBlock = numRecords2ndBlock; this.records2ndBlock = numRecords2ndBlock;
} }
@Override @Before
public void setUp() throws IOException { public void setUp() throws IOException {
conf = new Configuration(); conf = new Configuration();
path = new Path(ROOT, outputFile); path = new Path(ROOT, outputFile);
@ -75,12 +77,13 @@ public class TestTFileUnsortedByteArrays extends TestCase {
closeOutput(); closeOutput();
} }
@Override @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
fs.delete(path, true); fs.delete(path, true);
} }
// we still can scan records in an unsorted TFile // we still can scan records in an unsorted TFile
@Test
public void testFailureScannerWithKeys() throws IOException { public void testFailureScannerWithKeys() throws IOException {
Reader reader = Reader reader =
new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf);
@ -101,6 +104,7 @@ public class TestTFileUnsortedByteArrays extends TestCase {
} }
// we still can scan records in an unsorted TFile // we still can scan records in an unsorted TFile
@Test
public void testScan() throws IOException { public void testScan() throws IOException {
Reader reader = Reader reader =
new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf);
@ -142,6 +146,7 @@ public class TestTFileUnsortedByteArrays extends TestCase {
} }
// we still can scan records in an unsorted TFile // we still can scan records in an unsorted TFile
@Test
public void testScanRange() throws IOException { public void testScanRange() throws IOException {
Reader reader = Reader reader =
new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf);
@ -182,6 +187,7 @@ public class TestTFileUnsortedByteArrays extends TestCase {
} }
} }
@Test
public void testFailureSeek() throws IOException { public void testFailureSeek() throws IOException {
Reader reader = Reader reader =
new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf);

View File

@ -21,16 +21,18 @@ package org.apache.hadoop.io.file.tfile;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.junit.Before;
import org.junit.Test;
public class TestVLong extends TestCase { public class TestVLong {
private static String ROOT = private static String ROOT =
System.getProperty("test.build.data", "/tmp/tfile-test"); System.getProperty("test.build.data", "/tmp/tfile-test");
private Configuration conf; private Configuration conf;
@ -38,7 +40,7 @@ public class TestVLong extends TestCase {
private Path path; private Path path;
private String outputFile = "TestVLong"; private String outputFile = "TestVLong";
@Override @Before
public void setUp() throws IOException { public void setUp() throws IOException {
conf = new Configuration(); conf = new Configuration();
path = new Path(ROOT, outputFile); path = new Path(ROOT, outputFile);
@ -48,13 +50,14 @@ public class TestVLong extends TestCase {
} }
} }
@Override @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
if (fs.exists(path)) { if (fs.exists(path)) {
fs.delete(path, false); fs.delete(path, false);
} }
} }
@Test
public void testVLongByte() throws IOException { public void testVLongByte() throws IOException {
FSDataOutputStream out = fs.create(path); FSDataOutputStream out = fs.create(path);
for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; ++i) { for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; ++i) {
@ -91,6 +94,7 @@ public class TestVLong extends TestCase {
return ret; return ret;
} }
@Test
public void testVLongShort() throws IOException { public void testVLongShort() throws IOException {
long size = writeAndVerify(0); long size = writeAndVerify(0);
Assert.assertEquals("Incorrect encoded size", (1 << Short.SIZE) * 2 Assert.assertEquals("Incorrect encoded size", (1 << Short.SIZE) * 2
@ -98,18 +102,21 @@ public class TestVLong extends TestCase {
* (1 << Byte.SIZE) - 128 - 32, size); * (1 << Byte.SIZE) - 128 - 32, size);
} }
@Test
public void testVLong3Bytes() throws IOException { public void testVLong3Bytes() throws IOException {
long size = writeAndVerify(Byte.SIZE); long size = writeAndVerify(Byte.SIZE);
Assert.assertEquals("Incorrect encoded size", (1 << Short.SIZE) * 3 Assert.assertEquals("Incorrect encoded size", (1 << Short.SIZE) * 3
+ ((1 << Byte.SIZE) - 32) * (1 << Byte.SIZE) - 40 - 1, size); + ((1 << Byte.SIZE) - 32) * (1 << Byte.SIZE) - 40 - 1, size);
} }
@Test
public void testVLong4Bytes() throws IOException { public void testVLong4Bytes() throws IOException {
long size = writeAndVerify(Byte.SIZE * 2); long size = writeAndVerify(Byte.SIZE * 2);
Assert.assertEquals("Incorrect encoded size", (1 << Short.SIZE) * 4 Assert.assertEquals("Incorrect encoded size", (1 << Short.SIZE) * 4
+ ((1 << Byte.SIZE) - 16) * (1 << Byte.SIZE) - 32 - 2, size); + ((1 << Byte.SIZE) - 16) * (1 << Byte.SIZE) - 32 - 2, size);
} }
@Test
public void testVLong5Bytes() throws IOException { public void testVLong5Bytes() throws IOException {
long size = writeAndVerify(Byte.SIZE * 3); long size = writeAndVerify(Byte.SIZE * 3);
Assert.assertEquals("Incorrect encoded size", (1 << Short.SIZE) * 6 - 256 Assert.assertEquals("Incorrect encoded size", (1 << Short.SIZE) * 6 - 256
@ -121,18 +128,23 @@ public class TestVLong extends TestCase {
Assert.assertEquals("Incorrect encoded size", (1 << Short.SIZE) Assert.assertEquals("Incorrect encoded size", (1 << Short.SIZE)
* (bytes + 1) - 256 - bytes + 1, size); * (bytes + 1) - 256 - bytes + 1, size);
} }
@Test
public void testVLong6Bytes() throws IOException { public void testVLong6Bytes() throws IOException {
verifySixOrMoreBytes(6); verifySixOrMoreBytes(6);
} }
@Test
public void testVLong7Bytes() throws IOException { public void testVLong7Bytes() throws IOException {
verifySixOrMoreBytes(7); verifySixOrMoreBytes(7);
} }
@Test
public void testVLong8Bytes() throws IOException { public void testVLong8Bytes() throws IOException {
verifySixOrMoreBytes(8); verifySixOrMoreBytes(8);
} }
@Test
public void testVLongRandom() throws IOException { public void testVLongRandom() throws IOException {
int count = 1024 * 1024; int count = 1024 * 1024;
long data[] = new long[count]; long data[] = new long[count];

View File

@ -18,16 +18,19 @@
package org.apache.hadoop.io.serializer.avro; package org.apache.hadoop.io.serializer.avro;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.serializer.SerializationFactory; import org.apache.hadoop.io.serializer.SerializationFactory;
import org.apache.hadoop.io.serializer.SerializationTestUtil; import org.apache.hadoop.io.serializer.SerializationTestUtil;
import org.junit.Test;
public class TestAvroSerialization extends TestCase { public class TestAvroSerialization {
private static final Configuration conf = new Configuration(); private static final Configuration conf = new Configuration();
@Test
public void testSpecific() throws Exception { public void testSpecific() throws Exception {
AvroRecord before = new AvroRecord(); AvroRecord before = new AvroRecord();
before.intField = 5; before.intField = 5;
@ -35,6 +38,7 @@ public class TestAvroSerialization extends TestCase {
assertEquals(before, after); assertEquals(before, after);
} }
@Test
public void testReflectPkg() throws Exception { public void testReflectPkg() throws Exception {
Record before = new Record(); Record before = new Record();
before.x = 10; before.x = 10;
@ -44,12 +48,14 @@ public class TestAvroSerialization extends TestCase {
assertEquals(before, after); assertEquals(before, after);
} }
@Test
public void testAcceptHandlingPrimitivesAndArrays() throws Exception { public void testAcceptHandlingPrimitivesAndArrays() throws Exception {
SerializationFactory factory = new SerializationFactory(conf); SerializationFactory factory = new SerializationFactory(conf);
assertNull(factory.getSerializer(byte[].class)); assertNull(factory.getSerializer(byte[].class));
assertNull(factory.getSerializer(byte.class)); assertNull(factory.getSerializer(byte.class));
} }
@Test
public void testReflectInnerClass() throws Exception { public void testReflectInnerClass() throws Exception {
InnerRecord before = new InnerRecord(); InnerRecord before = new InnerRecord();
before.x = 10; before.x = 10;
@ -59,6 +65,7 @@ public class TestAvroSerialization extends TestCase {
assertEquals(before, after); assertEquals(before, after);
} }
@Test
public void testReflect() throws Exception { public void testReflect() throws Exception {
RefSerializable before = new RefSerializable(); RefSerializable before = new RefSerializable();
before.x = 10; before.x = 10;