|
@@ -21,6 +21,7 @@ package org.apache.hadoop.tools;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.FilterInputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.io.PrintStream;
|
|
|
import java.net.URI;
|
|
|
import java.util.ArrayList;
|
|
@@ -175,8 +176,47 @@ public class TestHadoopArchives {
|
|
|
final List<String> harPaths = lsr(shell, fullHarPathStr);
|
|
|
Assert.assertEquals(originalPaths, harPaths);
|
|
|
}
|
|
|
-
|
|
|
-@Test
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testOutputPathValidity() throws Exception {
|
|
|
+ final String inputPathStr = inputPath.toUri().getPath();
|
|
|
+ final URI uri = fs.getUri();
|
|
|
+ final String harName = "foo.har";
|
|
|
+ System.setProperty(HadoopArchives.TEST_HADOOP_ARCHIVES_JAR_PATH,
|
|
|
+ HADOOP_ARCHIVES_JAR);
|
|
|
+ final HadoopArchives har = new HadoopArchives(conf);
|
|
|
+
|
|
|
+ PrintStream stderr = System.err;
|
|
|
+ ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
|
|
+ PrintStream newErr = new PrintStream(byteStream);
|
|
|
+ System.setErr(newErr);
|
|
|
+
|
|
|
+ // fail if the archive path already exists
|
|
|
+ createFile(archivePath, fs, harName);
|
|
|
+ final String[] args = { "-archiveName", harName, "-p", inputPathStr, "*",
|
|
|
+ archivePath.toString() };
|
|
|
+ Assert.assertEquals(-1, ToolRunner.run(har, args));
|
|
|
+ String output = byteStream.toString();
|
|
|
+ final Path outputPath = new Path(archivePath, harName);
|
|
|
+ Assert.assertTrue(output.indexOf("Archive path: " + outputPath.toString()
|
|
|
+ + " already exists") != -1);
|
|
|
+
|
|
|
+ byteStream.reset();
|
|
|
+
|
|
|
+ // fail if the destination directory is a file
|
|
|
+ createFile(archivePath, fs, "sub1");
|
|
|
+ final Path archivePath2 = new Path(archivePath, "sub1");
|
|
|
+ final String[] args2 = { "-archiveName", harName, "-p", inputPathStr, "*",
|
|
|
+ archivePath2.toString() };
|
|
|
+ Assert.assertEquals(-1, ToolRunner.run(har, args2));
|
|
|
+ output = byteStream.toString();
|
|
|
+ Assert.assertTrue(output.indexOf("Destination " + archivePath2.toString()
|
|
|
+ + " should be a directory but is a file") != -1);
|
|
|
+
|
|
|
+ System.setErr(stderr);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
public void testPathWithSpaces() throws Exception {
|
|
|
// create files/directories with spaces
|
|
|
createFile(inputPath, fs, "c c");
|