|
@@ -24,6 +24,7 @@ import java.io.IOException;
|
|
import java.io.DataOutputStream;
|
|
import java.io.DataOutputStream;
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.jar.JarOutputStream;
|
|
import java.util.jar.JarOutputStream;
|
|
import java.util.zip.ZipOutputStream;
|
|
import java.util.zip.ZipOutputStream;
|
|
@@ -43,10 +44,11 @@ public class TestMultipleArchiveFiles extends TestStreaming
|
|
{
|
|
{
|
|
|
|
|
|
private StreamJob job;
|
|
private StreamJob job;
|
|
- private String INPUT_FILE = "input.txt";
|
|
|
|
- private String CACHE_ARCHIVE_1 = "cacheArchive1.zip";
|
|
|
|
|
|
+ private String INPUT_DIR = "multiple-archive-files/";
|
|
|
|
+ private String INPUT_FILE = INPUT_DIR + "input.txt";
|
|
|
|
+ private String CACHE_ARCHIVE_1 = INPUT_DIR + "cacheArchive1.zip";
|
|
private File CACHE_FILE_1 = null;
|
|
private File CACHE_FILE_1 = null;
|
|
- private String CACHE_ARCHIVE_2 = "cacheArchive2.zip";
|
|
|
|
|
|
+ private String CACHE_ARCHIVE_2 = INPUT_DIR + "cacheArchive2.zip";
|
|
private File CACHE_FILE_2 = null;
|
|
private File CACHE_FILE_2 = null;
|
|
private String expectedOutput = null;
|
|
private String expectedOutput = null;
|
|
private String OUTPUT_DIR = "out";
|
|
private String OUTPUT_DIR = "out";
|
|
@@ -58,27 +60,23 @@ public class TestMultipleArchiveFiles extends TestStreaming
|
|
private String strNamenode = null;
|
|
private String strNamenode = null;
|
|
private String namenode = null;
|
|
private String namenode = null;
|
|
|
|
|
|
- public TestMultipleArchiveFiles() throws IOException {
|
|
|
|
|
|
+ public TestMultipleArchiveFiles() throws Exception {
|
|
CACHE_FILE_1 = new File("cacheArchive1");
|
|
CACHE_FILE_1 = new File("cacheArchive1");
|
|
CACHE_FILE_2 = new File("cacheArchive2");
|
|
CACHE_FILE_2 = new File("cacheArchive2");
|
|
input = "HADOOP";
|
|
input = "HADOOP";
|
|
expectedOutput = "HADOOP\t\nHADOOP\t\n";
|
|
expectedOutput = "HADOOP\t\nHADOOP\t\n";
|
|
- try {
|
|
|
|
- conf = new Configuration();
|
|
|
|
- dfs = new MiniDFSCluster(conf, 1, true, null);
|
|
|
|
- fileSys = dfs.getFileSystem();
|
|
|
|
- namenode = fileSys.getUri().getAuthority();
|
|
|
|
- mr = new MiniMRCluster(1, namenode, 3);
|
|
|
|
- strJobTracker = "mapred.job.tracker=" + "localhost:" + mr.getJobTrackerPort();
|
|
|
|
- strNamenode = "fs.default.name=" + namenode;
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
|
|
+ conf = new Configuration();
|
|
|
|
+ dfs = new MiniDFSCluster(conf, 1, true, null);
|
|
|
|
+ fileSys = dfs.getFileSystem();
|
|
|
|
+ namenode = fileSys.getUri().getAuthority();
|
|
|
|
+ mr = new MiniMRCluster(1, namenode, 3);
|
|
|
|
+ strJobTracker = "mapred.job.tracker=" + "localhost:" + mr.getJobTrackerPort();
|
|
|
|
+ strNamenode = "fs.default.name=" + namenode;
|
|
}
|
|
}
|
|
|
|
|
|
protected void createInput() throws IOException
|
|
protected void createInput() throws IOException
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ fileSys.delete(new Path(INPUT_DIR), true);
|
|
DataOutputStream dos = fileSys.create(new Path(INPUT_FILE));
|
|
DataOutputStream dos = fileSys.create(new Path(INPUT_FILE));
|
|
String inputFileString = "symlink1/cacheArchive1\nsymlink2/cacheArchive2";
|
|
String inputFileString = "symlink1/cacheArchive1\nsymlink2/cacheArchive2";
|
|
dos.write(inputFileString.getBytes("UTF-8"));
|
|
dos.write(inputFileString.getBytes("UTF-8"));
|
|
@@ -102,14 +100,9 @@ public class TestMultipleArchiveFiles extends TestStreaming
|
|
}
|
|
}
|
|
|
|
|
|
protected String[] genArgs() {
|
|
protected String[] genArgs() {
|
|
- String cacheArchiveString1 = null;
|
|
|
|
- String cacheArchiveString2 = null;
|
|
|
|
- try {
|
|
|
|
- cacheArchiveString1 = fileSys.getUri().toString()+fileSys.getWorkingDirectory().toString()+"/"+CACHE_ARCHIVE_1+"#symlink1";
|
|
|
|
- cacheArchiveString2 = fileSys.getUri().toString()+fileSys.getWorkingDirectory().toString()+"/"+CACHE_ARCHIVE_2+"#symlink2";
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
|
|
+ String workDir = fileSys.getWorkingDirectory().toString() + "/";
|
|
|
|
+ String cache1 = workDir + CACHE_ARCHIVE_1 + "#symlink1";
|
|
|
|
+ String cache2 = workDir + CACHE_ARCHIVE_2 + "#symlink2";
|
|
|
|
|
|
return new String[] {
|
|
return new String[] {
|
|
"-input", INPUT_FILE.toString(),
|
|
"-input", INPUT_FILE.toString(),
|
|
@@ -117,39 +110,28 @@ public class TestMultipleArchiveFiles extends TestStreaming
|
|
"-mapper", "xargs cat",
|
|
"-mapper", "xargs cat",
|
|
"-reducer", "cat",
|
|
"-reducer", "cat",
|
|
"-jobconf", "mapred.reduce.tasks=1",
|
|
"-jobconf", "mapred.reduce.tasks=1",
|
|
- "-cacheArchive", cacheArchiveString1,
|
|
|
|
- "-cacheArchive", cacheArchiveString2,
|
|
|
|
|
|
+ "-cacheArchive", cache1,
|
|
|
|
+ "-cacheArchive", cache2,
|
|
"-jobconf", strNamenode,
|
|
"-jobconf", strNamenode,
|
|
"-jobconf", strJobTracker,
|
|
"-jobconf", strJobTracker,
|
|
"-jobconf", "stream.tmpdir=" + System.getProperty("test.build.data","/tmp")
|
|
"-jobconf", "stream.tmpdir=" + System.getProperty("test.build.data","/tmp")
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
- public void testCommandLine() {
|
|
|
|
- try {
|
|
|
|
- createInput();
|
|
|
|
- job = new StreamJob(genArgs(), true);
|
|
|
|
- if(job.go() != 0) {
|
|
|
|
- throw new Exception("Job Failed");
|
|
|
|
- }
|
|
|
|
- StringBuffer output = new StringBuffer(256);
|
|
|
|
- Path[] fileList = FileUtil.stat2Paths(fileSys.listStatus(
|
|
|
|
- new Path(OUTPUT_DIR)));
|
|
|
|
- for (int i = 0; i < fileList.length; i++){
|
|
|
|
- BufferedReader bread =
|
|
|
|
- new BufferedReader(new InputStreamReader(fileSys.open(fileList[i])));
|
|
|
|
- output.append(bread.readLine());
|
|
|
|
- output.append("\n");
|
|
|
|
- output.append(bread.readLine());
|
|
|
|
- output.append("\n");
|
|
|
|
- }
|
|
|
|
- assertEquals(expectedOutput, output.toString());
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } finally {
|
|
|
|
- CACHE_FILE_1.delete();
|
|
|
|
- CACHE_FILE_2.delete();
|
|
|
|
- }
|
|
|
|
|
|
+ public void testCommandLine() throws IOException {
|
|
|
|
+ createInput();
|
|
|
|
+ job = new StreamJob(genArgs(), true);
|
|
|
|
+ if(job.go() != 0) {
|
|
|
|
+ throw new IOException("Job Failed");
|
|
|
|
+ }
|
|
|
|
+ StringBuffer output = new StringBuffer(256);
|
|
|
|
+ Path[] fileList = FileUtil.stat2Paths(fileSys.listStatus(
|
|
|
|
+ new Path(OUTPUT_DIR)));
|
|
|
|
+ for (int i = 0; i < fileList.length; i++){
|
|
|
|
+ if (fileList[i].getName().equals("_logs")) continue;
|
|
|
|
+ output.append(StreamUtil.slurpHadoop(fileList[i], fileSys));
|
|
|
|
+ }
|
|
|
|
+ assertEquals(expectedOutput, output.toString());
|
|
}
|
|
}
|
|
|
|
|
|
public static void main(String[]args) throws Exception
|
|
public static void main(String[]args) throws Exception
|