|
@@ -19,19 +19,12 @@
|
|
package org.apache.hadoop.mapred;
|
|
package org.apache.hadoop.mapred;
|
|
|
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
-import java.util.*;
|
|
|
|
import junit.framework.TestCase;
|
|
import junit.framework.TestCase;
|
|
|
|
|
|
-import org.apache.commons.logging.*;
|
|
|
|
import org.apache.hadoop.fs.*;
|
|
import org.apache.hadoop.fs.*;
|
|
import org.apache.hadoop.io.*;
|
|
import org.apache.hadoop.io.*;
|
|
-import org.apache.hadoop.io.compress.*;
|
|
|
|
-import org.apache.hadoop.util.ReflectionUtils;
|
|
|
|
|
|
|
|
public class TestTextOutputFormat extends TestCase {
|
|
public class TestTextOutputFormat extends TestCase {
|
|
- private static final Log LOG = LogFactory.getLog(TestTextOutputFormat.class
|
|
|
|
- .getName());
|
|
|
|
-
|
|
|
|
private static JobConf defaultConf = new JobConf();
|
|
private static JobConf defaultConf = new JobConf();
|
|
|
|
|
|
private static FileSystem localFs = null;
|
|
private static FileSystem localFs = null;
|
|
@@ -43,9 +36,11 @@ public class TestTextOutputFormat extends TestCase {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private static Path workDir = new Path(new Path(System.getProperty(
|
|
|
|
- "test.build.data", "."), "data"), "TestTextOutputFormat");
|
|
|
|
|
|
+ private static Path workDir =
|
|
|
|
+ new Path(new Path(System.getProperty("test.build.data", "."), "data"),
|
|
|
|
+ "TestTextOutputFormat");
|
|
|
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
public void testFormat() throws Exception {
|
|
public void testFormat() throws Exception {
|
|
JobConf job = new JobConf();
|
|
JobConf job = new JobConf();
|
|
job.setOutputPath(workDir);
|
|
job.setOutputPath(workDir);
|
|
@@ -54,19 +49,22 @@ public class TestTextOutputFormat extends TestCase {
|
|
// A reporter that does nothing
|
|
// A reporter that does nothing
|
|
Reporter reporter = Reporter.NULL;
|
|
Reporter reporter = Reporter.NULL;
|
|
|
|
|
|
- TextOutputFormat<Text, Text> theOutputFormat =
|
|
|
|
- new TextOutputFormat<Text, Text>();
|
|
|
|
- RecordWriter<Text, Text> theRecordWriter =
|
|
|
|
|
|
+ TextOutputFormat theOutputFormat = new TextOutputFormat();
|
|
|
|
+ RecordWriter theRecordWriter =
|
|
theOutputFormat.getRecordWriter(localFs, job, file, reporter);
|
|
theOutputFormat.getRecordWriter(localFs, job, file, reporter);
|
|
|
|
|
|
Text key1 = new Text("key1");
|
|
Text key1 = new Text("key1");
|
|
Text key2 = new Text("key2");
|
|
Text key2 = new Text("key2");
|
|
Text val1 = new Text("val1");
|
|
Text val1 = new Text("val1");
|
|
Text val2 = new Text("val2");
|
|
Text val2 = new Text("val2");
|
|
|
|
+ NullWritable nullWritable = NullWritable.get();
|
|
|
|
|
|
try {
|
|
try {
|
|
theRecordWriter.write(key1, val1);
|
|
theRecordWriter.write(key1, val1);
|
|
|
|
+ theRecordWriter.write(null, nullWritable);
|
|
theRecordWriter.write(null, val1);
|
|
theRecordWriter.write(null, val1);
|
|
|
|
+ theRecordWriter.write(nullWritable, val2);
|
|
|
|
+ theRecordWriter.write(key2, nullWritable);
|
|
theRecordWriter.write(key1, null);
|
|
theRecordWriter.write(key1, null);
|
|
theRecordWriter.write(null, null);
|
|
theRecordWriter.write(null, null);
|
|
theRecordWriter.write(key2, val2);
|
|
theRecordWriter.write(key2, val2);
|
|
@@ -78,6 +76,8 @@ public class TestTextOutputFormat extends TestCase {
|
|
StringBuffer expectedOutput = new StringBuffer();
|
|
StringBuffer expectedOutput = new StringBuffer();
|
|
expectedOutput.append(key1).append('\t').append(val1).append("\n");
|
|
expectedOutput.append(key1).append('\t').append(val1).append("\n");
|
|
expectedOutput.append(val1).append("\n");
|
|
expectedOutput.append(val1).append("\n");
|
|
|
|
+ expectedOutput.append(val2).append("\n");
|
|
|
|
+ expectedOutput.append(key2).append("\n");
|
|
expectedOutput.append(key1).append("\n");
|
|
expectedOutput.append(key1).append("\n");
|
|
expectedOutput.append(key2).append('\t').append(val2).append("\n");
|
|
expectedOutput.append(key2).append('\t').append(val2).append("\n");
|
|
String output = UtilsForTests.slurp(expectedFile);
|
|
String output = UtilsForTests.slurp(expectedFile);
|