mirror of
https://github.com/apache/sqoop.git
synced 2025-05-03 22:34:30 +08:00
SQOOP-1362: TestImportJob getContent method doesn't work'
(Abraham Elmahrek via Jarek Jarcec Cecho)
This commit is contained in:
parent
6bfaa9d653
commit
c0831f20c0
@ -45,6 +45,8 @@
|
|||||||
import com.cloudera.sqoop.testutil.InjectableManagerFactory;
|
import com.cloudera.sqoop.testutil.InjectableManagerFactory;
|
||||||
import com.cloudera.sqoop.testutil.InjectableConnManager;
|
import com.cloudera.sqoop.testutil.InjectableConnManager;
|
||||||
import com.cloudera.sqoop.tool.ImportTool;
|
import com.cloudera.sqoop.tool.ImportTool;
|
||||||
|
import org.apache.sqoop.SqoopOptions;
|
||||||
|
import org.apache.sqoop.util.ClassLoaderStack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test aspects of the DataDrivenImportJob class' failure reporting.
|
* Test aspects of the DataDrivenImportJob class' failure reporting.
|
||||||
@ -55,7 +57,6 @@
|
|||||||
* SQOOP_RETHROW_PROPERTY = "sqoop.throwOnError".
|
* SQOOP_RETHROW_PROPERTY = "sqoop.throwOnError".
|
||||||
*/
|
*/
|
||||||
public class TestImportJob extends ImportJobTestCase {
|
public class TestImportJob extends ImportJobTestCase {
|
||||||
|
|
||||||
public void testFailedImportDueToIOException() throws IOException {
|
public void testFailedImportDueToIOException() throws IOException {
|
||||||
// Make sure that if a MapReduce job to do the import fails due
|
// Make sure that if a MapReduce job to do the import fails due
|
||||||
// to an IOException, we tell the user about it.
|
// to an IOException, we tell the user about it.
|
||||||
@ -246,21 +247,26 @@ public void testDuplicateColumns() throws IOException {
|
|||||||
|
|
||||||
// helper method to get contents of a given dir containing sequence files
|
// helper method to get contents of a given dir containing sequence files
|
||||||
private String[] getContent(Configuration conf, Path path) throws Exception {
|
private String[] getContent(Configuration conf, Path path) throws Exception {
|
||||||
|
ClassLoader prevClassLoader = ClassLoaderStack.addJarFile(
|
||||||
|
new Path(new Path(new SqoopOptions().getJarOutputDir()), getTableName() + ".jar").toString(),
|
||||||
|
getTableName());
|
||||||
|
|
||||||
FileSystem fs = FileSystem.getLocal(conf);
|
FileSystem fs = FileSystem.getLocal(conf);
|
||||||
FileStatus[] stats = fs.listStatus(path);
|
FileStatus[] stats = fs.listStatus(path);
|
||||||
String [] fileNames = new String[stats.length];
|
Path[] paths = new Path[stats.length];
|
||||||
for (int i = 0; i < stats.length; i++) {
|
for (int i = 0; i < stats.length; i++) {
|
||||||
fileNames[i] = stats[i].getPath().toString();
|
paths[i] = stats[i].getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read all the files adding the value lines to the list.
|
// Read all the files adding the value lines to the list.
|
||||||
List<String> strings = new ArrayList<String>();
|
List<String> strings = new ArrayList<String>();
|
||||||
for (String fileName : fileNames) {
|
for (Path filePath : paths) {
|
||||||
if (fileName.startsWith("_") || fileName.startsWith(".")) {
|
if (filePath.getName().startsWith("_") || filePath.getName().startsWith(".")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, conf);
|
// Need to use new configuration object so that it has the proper classloaders.
|
||||||
|
SequenceFile.Reader reader = new SequenceFile.Reader(fs, filePath, new Configuration());
|
||||||
WritableComparable key = (WritableComparable)
|
WritableComparable key = (WritableComparable)
|
||||||
reader.getKeyClass().newInstance();
|
reader.getKeyClass().newInstance();
|
||||||
Writable value = (Writable) reader.getValueClass().newInstance();
|
Writable value = (Writable) reader.getValueClass().newInstance();
|
||||||
@ -268,6 +274,8 @@ private String[] getContent(Configuration conf, Path path) throws Exception {
|
|||||||
strings.add(value.toString());
|
strings.add(value.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
|
||||||
return strings.toArray(new String[0]);
|
return strings.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +308,7 @@ public void testDeleteTargetDir() throws Exception {
|
|||||||
assertTrue("Expecting two files in the directory.",
|
assertTrue("Expecting two files in the directory.",
|
||||||
fs.listStatus(outputPath).length == 2);
|
fs.listStatus(outputPath).length == 2);
|
||||||
String[] output = getContent(conf, outputPath);
|
String[] output = getContent(conf, outputPath);
|
||||||
assertEquals("Expected output and actual output should be same.", "meep",
|
assertEquals("Expected output and actual output should be same.", "meep\n",
|
||||||
output[0]);
|
output[0]);
|
||||||
|
|
||||||
ret = Sqoop.runSqoop(importer, argv);
|
ret = Sqoop.runSqoop(importer, argv);
|
||||||
@ -311,12 +319,11 @@ public void testDeleteTargetDir() throws Exception {
|
|||||||
assertTrue("Expecting two files in the directory.",
|
assertTrue("Expecting two files in the directory.",
|
||||||
fs.listStatus(outputPath).length == 2);
|
fs.listStatus(outputPath).length == 2);
|
||||||
output = getContent(conf, outputPath);
|
output = getContent(conf, outputPath);
|
||||||
assertEquals("Expected output and actual output should be same.", "meep",
|
assertEquals("Expected output and actual output should be same.", "meep\n",
|
||||||
output[0]);
|
output[0]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// In debug mode, ImportException is wrapped in RuntimeException.
|
// In debug mode, ImportException is wrapped in RuntimeException.
|
||||||
LOG.info("Got exceptional return (expected: ok). msg is: " + e);
|
LOG.info("Got exceptional return (expected: ok). msg is: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user