|
@@ -35,6 +35,7 @@ import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
import java.util.Scanner;
|
|
import java.util.Scanner;
|
|
|
|
+import java.util.zip.DeflaterOutputStream;
|
|
import java.util.zip.GZIPOutputStream;
|
|
import java.util.zip.GZIPOutputStream;
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.Log;
|
|
@@ -52,7 +53,10 @@ import org.apache.hadoop.hdfs.tools.DFSAdmin;
|
|
import org.apache.hadoop.io.IOUtils;
|
|
import org.apache.hadoop.io.IOUtils;
|
|
import org.apache.hadoop.io.SequenceFile;
|
|
import org.apache.hadoop.io.SequenceFile;
|
|
import org.apache.hadoop.io.Text;
|
|
import org.apache.hadoop.io.Text;
|
|
|
|
+import org.apache.hadoop.io.compress.BZip2Codec;
|
|
|
|
+import org.apache.hadoop.io.compress.CompressionCodec;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
|
+import org.apache.hadoop.util.ReflectionUtils;
|
|
import org.apache.hadoop.util.StringUtils;
|
|
import org.apache.hadoop.util.StringUtils;
|
|
import org.apache.hadoop.util.ToolRunner;
|
|
import org.apache.hadoop.util.ToolRunner;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
@@ -577,6 +581,8 @@ public class TestDFSShell {
|
|
try {
|
|
try {
|
|
final FileSystem fs = root.getFileSystem(conf);
|
|
final FileSystem fs = root.getFileSystem(conf);
|
|
fs.mkdirs(root);
|
|
fs.mkdirs(root);
|
|
|
|
+
|
|
|
|
+ // Test the gzip type of files. Magic detection.
|
|
OutputStream zout = new GZIPOutputStream(
|
|
OutputStream zout = new GZIPOutputStream(
|
|
fs.create(new Path(root, "file.gz")));
|
|
fs.create(new Path(root, "file.gz")));
|
|
Random r = new Random();
|
|
Random r = new Random();
|
|
@@ -601,7 +607,7 @@ public class TestDFSShell {
|
|
Arrays.equals(file.toByteArray(), out.toByteArray()));
|
|
Arrays.equals(file.toByteArray(), out.toByteArray()));
|
|
|
|
|
|
// Create a sequence file with a gz extension, to test proper
|
|
// Create a sequence file with a gz extension, to test proper
|
|
- // container detection
|
|
|
|
|
|
+ // container detection. Magic detection.
|
|
SequenceFile.Writer writer = SequenceFile.createWriter(
|
|
SequenceFile.Writer writer = SequenceFile.createWriter(
|
|
conf,
|
|
conf,
|
|
SequenceFile.Writer.file(new Path(root, "file.gz")),
|
|
SequenceFile.Writer.file(new Path(root, "file.gz")),
|
|
@@ -619,6 +625,45 @@ public class TestDFSShell {
|
|
assertTrue("Output doesn't match input",
|
|
assertTrue("Output doesn't match input",
|
|
Arrays.equals("Foo\tBar\n".getBytes(), out.toByteArray()));
|
|
Arrays.equals("Foo\tBar\n".getBytes(), out.toByteArray()));
|
|
out.reset();
|
|
out.reset();
|
|
|
|
+
|
|
|
|
+ // Test deflate. Extension-based detection.
|
|
|
|
+ OutputStream dout = new DeflaterOutputStream(
|
|
|
|
+ fs.create(new Path(root, "file.deflate")));
|
|
|
|
+ byte[] outbytes = "foo".getBytes();
|
|
|
|
+ dout.write(outbytes);
|
|
|
|
+ dout.close();
|
|
|
|
+ out = new ByteArrayOutputStream();
|
|
|
|
+ System.setOut(new PrintStream(out));
|
|
|
|
+ argv = new String[2];
|
|
|
|
+ argv[0] = "-text";
|
|
|
|
+ argv[1] = new Path(root, "file.deflate").toString();
|
|
|
|
+ ret = ToolRunner.run(new FsShell(conf), argv);
|
|
|
|
+ assertEquals("'-text " + argv[1] + " returned " + ret, 0, ret);
|
|
|
|
+ assertTrue("Output doesn't match input",
|
|
|
|
+ Arrays.equals(outbytes, out.toByteArray()));
|
|
|
|
+ out.reset();
|
|
|
|
+
|
|
|
|
+ // Test a simple codec. Extension based detection. We use
|
|
|
|
+ // Bzip2 cause its non-native.
|
|
|
|
+ CompressionCodec codec = (CompressionCodec)
|
|
|
|
+ ReflectionUtils.newInstance(BZip2Codec.class, conf);
|
|
|
|
+ String extension = codec.getDefaultExtension();
|
|
|
|
+ Path p = new Path(root, "file." + extension);
|
|
|
|
+ OutputStream fout = new DataOutputStream(codec.createOutputStream(
|
|
|
|
+ fs.create(p, true)));
|
|
|
|
+ byte[] writebytes = "foo".getBytes();
|
|
|
|
+ fout.write(writebytes);
|
|
|
|
+ fout.close();
|
|
|
|
+ out = new ByteArrayOutputStream();
|
|
|
|
+ System.setOut(new PrintStream(out));
|
|
|
|
+ argv = new String[2];
|
|
|
|
+ argv[0] = "-text";
|
|
|
|
+ argv[1] = new Path(root, p).toString();
|
|
|
|
+ ret = ToolRunner.run(new FsShell(conf), argv);
|
|
|
|
+ assertEquals("'-text " + argv[1] + " returned " + ret, 0, ret);
|
|
|
|
+ assertTrue("Output doesn't match input",
|
|
|
|
+ Arrays.equals(writebytes, out.toByteArray()));
|
|
|
|
+ out.reset();
|
|
} finally {
|
|
} finally {
|
|
if (null != bak) {
|
|
if (null != bak) {
|
|
System.setOut(bak);
|
|
System.setOut(bak);
|