本文整理汇总了Java中com.cloudera.sqoop.util.ClassLoaderStack类的典型用法代码示例。如果您正苦于以下问题:Java ClassLoaderStack类的具体用法?Java ClassLoaderStack怎么用?Java ClassLoaderStack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassLoaderStack类属于com.cloudera.sqoop.util包,在下文中一共展示了ClassLoaderStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadJars
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
/**
* If jars must be loaded into the local environment, do so here.
*/
private void loadJars(Configuration conf, String ormJarFile,
String tableClassName) throws IOException {
boolean isLocal = "local".equals(conf.get("mapreduce.jobtracker.address"))
|| "local".equals(conf.get("mapred.job.tracker"));
if (isLocal) {
// If we're using the LocalJobRunner, then instead of using the compiled
// jar file as the job source, we're running in the current thread. Push
// on another classloader that loads from that jar in addition to
// everything currently on the classpath.
this.prevClassLoader = ClassLoaderStack.addJarFile(ormJarFile,
tableClassName);
}
}
示例2: unloadJars
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
/**
* If any classloader was invoked by loadJars, free it here.
*/
private void unloadJars() {
if (null != this.prevClassLoader) {
// unload the special classloader for this jar.
ClassLoaderStack.setCurrentClassLoader(this.prevClassLoader);
}
}
示例3: loadJars
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
/**
* If jars must be loaded into the local environment, do so here.
*/
protected void loadJars(Configuration conf, String ormJarFile,
String tableClassName) throws IOException {
boolean isLocal = "local".equals(conf.get("mapreduce.jobtracker.address"))
|| "local".equals(conf.get("mapred.job.tracker"));
if (isLocal) {
// If we're using the LocalJobRunner, then instead of using the compiled
// jar file as the job source, we're running in the current thread. Push
// on another classloader that loads from that jar in addition to
// everything currently on the classpath.
this.prevClassLoader = ClassLoaderStack.addJarFile(ormJarFile,
tableClassName);
}
}
示例4: unloadJars
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
/**
* If any classloader was invoked by loadJars, free it here.
*/
protected void unloadJars() {
if (null != this.prevClassLoader) {
// unload the special classloader for this jar.
ClassLoaderStack.setCurrentClassLoader(this.prevClassLoader);
}
}
示例5: loadJars
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
/**
* If jars must be loaded into the local environment, do so here.
*/
protected void loadJars(Configuration conf, String ormJarFile,
String tableClassName) throws IOException {
boolean isLocal = "local".equals(conf.get("mapreduce.jobtracker.address"))
|| "local".equals(conf.get("mapred.job.tracker"));
if (isLocal) {
// If we're using the LocalJobRunner, then instead of using the compiled
// jar file as the job source, we're running in the current thread. Push
// on another classloader that loads from that jar in addition to
// everything currently on the classpath.
this.prevClassLoader = ClassLoaderStack.addJarFile(ormJarFile,
tableClassName);
}
}
示例6: runQueryTest
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
public void runQueryTest(String query, String firstValStr,
int numExpectedResults, int expectedSum, String targetDir)
throws IOException {
ClassLoader prevClassLoader = null;
SequenceFile.Reader reader = null;
String[] argv = getArgv(true, query, targetDir, false);
runImport(argv);
try {
SqoopOptions opts = new ImportTool().parseArguments(getArgv(false,
query, targetDir, false), null, null, true);
CompilationManager compileMgr = new CompilationManager(opts);
String jarFileName = compileMgr.getJarFilename();
prevClassLoader = ClassLoaderStack.addJarFile(jarFileName,
getTableName());
reader = SeqFileReader.getSeqFileReader(getDataFilePath()
.toString());
// here we can actually instantiate (k, v) pairs.
Configuration conf = new Configuration();
Object key = ReflectionUtils
.newInstance(reader.getKeyClass(), conf);
Object val = ReflectionUtils.newInstance(reader.getValueClass(),
conf);
if (reader.next(key) == null) {
fail("Empty SequenceFile during import");
}
// make sure that the value we think should be at the top, is.
reader.getCurrentValue(val);
assertEquals("Invalid ordering within sorted SeqFile", firstValStr,
val.toString());
// We know that these values are two ints separated by a ','
// character.
// Since this is all dynamic, though, we don't want to actually link
// against the class and use its methods. So we just parse this back
// into int fields manually. Sum them up and ensure that we get the
// expected total for the first column, to verify that we got all
// the
// results from the db into the file.
int curSum = getFirstInt(val.toString());
int totalResults = 1;
// now sum up everything else in the file.
while (reader.next(key) != null) {
reader.getCurrentValue(val);
curSum += getFirstInt(val.toString());
totalResults++;
}
assertEquals("Total sum of first db column mismatch", expectedSum,
curSum);
assertEquals("Incorrect number of results for query",
numExpectedResults, totalResults);
} catch (InvalidOptionsException ioe) {
LOG.error(StringUtils.stringifyException(ioe));
fail(ioe.toString());
} catch (ParseException pe) {
LOG.error(StringUtils.stringifyException(pe));
fail(pe.toString());
} finally {
IOUtils.closeStream(reader);
if (null != prevClassLoader) {
ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
}
}
}
示例7: runSplitByTest
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
public void runSplitByTest(String splitByCol, int expectedSum)
throws IOException {
String[] columns = new String[] { "L_ORDERKEY", "L_PARTKEY",
"L_SUPPKEY", "L_LINENUMBER", "L_QUANTITY", "L_EXTENDEDPRICE",
"L_DISCOUNT", "L_TAX", "L_RETURNFLAG", "L_LINESTATUS",
"L_SHIPDATE", "L_COMMITDATE", "L_RECEIPTDATE",
"L_SHIPINSTRUCT", "L_SHIPMODE", "L_COMMENT", };
ClassLoader prevClassLoader = null;
SequenceFile.Reader reader = null;
String[] argv = getArgv(true, columns, splitByCol);
runImport(argv);
try {
SqoopOptions opts = new ImportTool().parseArguments(getArgv(false,
columns, splitByCol), null, null, true);
CompilationManager compileMgr = new CompilationManager(opts);
String jarFileName = compileMgr.getJarFilename();
LOG.debug("Got jar from import job: " + jarFileName);
prevClassLoader = ClassLoaderStack.addJarFile(jarFileName,
getTableName());
reader = SeqFileReader.getSeqFileReader(getDataFilePath()
.toString());
// here we can actually instantiate (k, v) pairs.
Configuration conf = new Configuration();
Object key = ReflectionUtils
.newInstance(reader.getKeyClass(), conf);
Object val = ReflectionUtils.newInstance(reader.getValueClass(),
conf);
// We know that these values are two ints separated by a ','
// character.
// Since this is all dynamic, though, we don't want to actually link
// against the class and use its methods. So we just parse this back
// into int fields manually. Sum them up and ensure that we get the
// expected total for the first column, to verify that we got all
// the
// results from the db into the file.
// Sum up everything in the file.
int curSum = 0;
while (reader.next(key) != null) {
reader.getCurrentValue(val);
curSum += getFirstInt(val.toString());
}
System.out.println("Sum : e,c" + expectedSum + " : " + curSum);
assertEquals("Total sum of first db column mismatch", expectedSum,
curSum);
} catch (InvalidOptionsException ioe) {
LOG.error(StringUtils.stringifyException(ioe));
fail(ioe.toString());
} catch (ParseException pe) {
LOG.error(StringUtils.stringifyException(pe));
fail(pe.toString());
} finally {
IOUtils.closeStream(reader);
if (null != prevClassLoader) {
ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
}
}
}
示例8: runParseTest
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
public void runParseTest(String fieldTerminator, String lineTerminator,
String encloser, String escape, boolean encloseRequired)
throws IOException {
ClassLoader prevClassLoader = null;
String[] argv = getArgv(true, fieldTerminator, lineTerminator,
encloser, escape, encloseRequired);
runImport(argv);
try {
String tableClassName = getTableName();
argv = getArgv(false, fieldTerminator, lineTerminator, encloser,
escape, encloseRequired);
SqoopOptions opts = new ImportTool().parseArguments(argv, null,
null, true);
CompilationManager compileMgr = new CompilationManager(opts);
String jarFileName = compileMgr.getJarFilename();
// Make sure the user's class is loaded into our address space.
prevClassLoader = ClassLoaderStack.addJarFile(jarFileName,
tableClassName);
JobConf job = new JobConf();
job.setJar(jarFileName);
// Tell the job what class we're testing.
job.set(ReparseMapper.USER_TYPE_NAME_KEY, tableClassName);
// use local mode in the same JVM.
ConfigurationHelper.setJobtrackerAddr(job, "local");
job.set("fs.default.name", "file:///");
String warehouseDir = getWarehouseDir();
Path warehousePath = new Path(warehouseDir);
Path inputPath = new Path(warehousePath, getTableName());
Path outputPath = new Path(warehousePath, getTableName() + "-out");
job.setMapperClass(ReparseMapper.class);
job.setNumReduceTasks(0);
FileInputFormat.addInputPath(job, inputPath);
FileOutputFormat.setOutputPath(job, outputPath);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(NullWritable.class);
JobClient.runJob(job);
} catch (InvalidOptionsException ioe) {
LOG.error(StringUtils.stringifyException(ioe));
fail(ioe.toString());
} catch (ParseException pe) {
LOG.error(StringUtils.stringifyException(pe));
fail(pe.toString());
} finally {
if (null != prevClassLoader) {
ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
}
}
}
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:61,代码来源:SQLServerParseMethodsManualTest.java
示例9: runMultiMapTest
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
public void runMultiMapTest(String splitByCol, int expectedSum)
throws IOException {
String[] columns = MSSQLTestUtils.getColumns();
ClassLoader prevClassLoader = null;
SequenceFile.Reader reader = null;
String[] argv = getArgv(true, columns, splitByCol);
runImport(argv);
try {
ImportTool importTool = new ImportTool();
SqoopOptions opts = importTool.parseArguments(getArgv(false,
columns, splitByCol), null, null, true);
String username = MSSQLTestUtils.getDBUserName();
String password = MSSQLTestUtils.getDBPassWord();
opts.setUsername(username);
opts.setPassword(password);
CompilationManager compileMgr = new CompilationManager(opts);
String jarFileName = compileMgr.getJarFilename();
prevClassLoader = ClassLoaderStack.addJarFile(jarFileName,
getTableName());
List<Path> paths = getDataFilePaths();
Configuration conf = new Configuration();
int curSum = 0;
// We expect multiple files. We need to open all the files and sum
// up the
// first column across all of them.
for (Path p : paths) {
reader = SeqFileReader.getSeqFileReader(p.toString());
// here we can actually instantiate (k, v) pairs.
Object key = ReflectionUtils.newInstance(reader.getKeyClass(),
conf);
Object val = ReflectionUtils.newInstance(
reader.getValueClass(), conf);
// We know that these values are two ints separated by a ','
// character. Since this is all dynamic, though, we don't want
// to
// actually link against the class and use its methods. So we
// just
// parse this back into int fields manually. Sum them up and
// ensure
// that we get the expected total for the first column, to
// verify that
// we got all the results from the db into the file.
// now sum up everything in the file.
while (reader.next(key) != null) {
reader.getCurrentValue(val);
curSum += getFirstInt(val.toString());
}
IOUtils.closeStream(reader);
reader = null;
}
assertEquals("Total sum of first db column mismatch", expectedSum,
curSum);
} catch (InvalidOptionsException ioe) {
LOG.error(StringUtils.stringifyException(ioe));
fail(ioe.toString());
} catch (ParseException pe) {
LOG.error(StringUtils.stringifyException(pe));
fail(pe.toString());
} finally {
IOUtils.closeStream(reader);
if (null != prevClassLoader) {
ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
}
}
}
示例10: runWhereTest
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
public void runWhereTest(String whereClause, String firstValStr,
int numExpectedResults, int expectedSum) throws IOException {
String[] columns = MSSQLTestUtils.getColumns();
ClassLoader prevClassLoader = null;
SequenceFile.Reader reader = null;
String[] argv = getArgv(true, columns, whereClause);
runImport(argv);
try {
String username = MSSQLTestUtils.getDBUserName();
String password = MSSQLTestUtils.getDBPassWord();
SqoopOptions opts = new ImportTool().parseArguments(getArgv(false,
columns, whereClause), null, null, true);
opts.setUsername(username);
opts.setPassword(password);
CompilationManager compileMgr = new CompilationManager(opts);
String jarFileName = compileMgr.getJarFilename();
prevClassLoader = ClassLoaderStack.addJarFile(jarFileName,
getTableName());
reader = SeqFileReader.getSeqFileReader(getDataFilePath()
.toString());
// here we can actually instantiate (k, v) pairs.
Configuration conf = new Configuration();
Object key = ReflectionUtils
.newInstance(reader.getKeyClass(), conf);
Object val = ReflectionUtils.newInstance(reader.getValueClass(),
conf);
if (reader.next(key) == null) {
fail("Empty SequenceFile during import");
}
// make sure that the value we think should be at the top, is.
reader.getCurrentValue(val);
assertEquals("Invalid ordering within sorted SeqFile", firstValStr,
val.toString());
// We know that these values are two ints separated by a ','
// character.
// Since this is all dynamic, though, we don't want to actually link
// against the class and use its methods. So we just parse this back
// into int fields manually. Sum them up and ensure that we get the
// expected total for the first column, to verify that we got all
// the
// results from the db into the file.
int curSum = getFirstInt(val.toString());
int totalResults = 1;
// now sum up everything else in the file.
while (reader.next(key) != null) {
reader.getCurrentValue(val);
curSum += getFirstInt(val.toString());
totalResults++;
}
assertEquals("Total sum of first db column mismatch", expectedSum,
curSum);
assertEquals("Incorrect number of results for query",
numExpectedResults, totalResults);
} catch (InvalidOptionsException ioe) {
fail(ioe.toString());
} catch (ParseException pe) {
fail(pe.toString());
} finally {
IOUtils.closeStream(reader);
if (null != prevClassLoader) {
ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
}
}
}
示例11: runMergeTest
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
public void runMergeTest(SqoopOptions.FileLayout fileLayout) throws Exception {
createTable(initRecords);
// Create a jar to use for the merging process; we'll load it
// into the current thread CL for when this runs. This needs
// to contain a different class name than used for the imports
// due to classloaderstack issues in the same JVM.
final String MERGE_CLASS_NAME = "ClassForMerging";
SqoopOptions options = getSqoopOptions(newConf());
options.setTableName(TABLE_NAME);
options.setClassName(MERGE_CLASS_NAME);
CodeGenTool codeGen = new CodeGenTool();
Sqoop codeGenerator = new Sqoop(codeGen, options.getConf(), options);
int ret = Sqoop.runSqoop(codeGenerator, new String[0]);
if (0 != ret) {
fail("Nonzero exit from codegen: " + ret);
}
List<String> jars = codeGen.getGeneratedJarFiles();
String jarFileName = jars.get(0);
// Now do the imports.
importData(OLD_PATH, fileLayout);
// Check that we got records that meet our expected values.
checkData(OLD_PATH, initRecords, fileLayout);
Thread.sleep(25);
// Modify the data in the warehouse.
createTable(newRecords);
Thread.sleep(25);
// Do another import, into the "new" dir.
importData(NEW_PATH, fileLayout);
checkData(NEW_PATH, newRecords, fileLayout);
// Now merge the results!
ClassLoaderStack.addJarFile(jarFileName, MERGE_CLASS_NAME);
Path warehouse = new Path(BaseSqoopTestCase.LOCAL_WAREHOUSE_DIR);
options = getSqoopOptions(newConf());
options.setMergeOldPath(new Path(warehouse, OLD_PATH).toString());
options.setMergeNewPath(new Path(warehouse, NEW_PATH).toString());
options.setMergeKeyCol("ID");
options.setTargetDir(new Path(warehouse, FINAL_PATH).toString());
options.setClassName(MERGE_CLASS_NAME);
options.setExistingJarName(jarFileName);
MergeTool mergeTool = new MergeTool();
Sqoop merger = new Sqoop(mergeTool, options.getConf(), options);
ret = Sqoop.runSqoop(merger, new String[0]);
if (0 != ret) {
fail("Merge failed with exit code " + ret);
}
checkData(FINAL_PATH, mergedRecords, fileLayout);
}
示例12: runQueryTest
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
public void runQueryTest(String query, String firstValStr,
int numExpectedResults, int expectedSum, String targetDir)
throws IOException {
ClassLoader prevClassLoader = null;
SequenceFile.Reader reader = null;
String [] argv = getArgv(true, query, targetDir, false);
runImport(argv);
try {
SqoopOptions opts = new ImportTool().parseArguments(
getArgv(false, query, targetDir, false),
null, null, true);
CompilationManager compileMgr = new CompilationManager(opts);
String jarFileName = compileMgr.getJarFilename();
prevClassLoader = ClassLoaderStack.addJarFile(jarFileName,
getTableName());
reader = SeqFileReader.getSeqFileReader(getDataFilePath().toString());
// here we can actually instantiate (k, v) pairs.
Configuration conf = new Configuration();
Object key = ReflectionUtils.newInstance(reader.getKeyClass(), conf);
Object val = ReflectionUtils.newInstance(reader.getValueClass(), conf);
if (reader.next(key) == null) {
fail("Empty SequenceFile during import");
}
// make sure that the value we think should be at the top, is.
reader.getCurrentValue(val);
assertEquals("Invalid ordering within sorted SeqFile", firstValStr,
val.toString());
// We know that these values are two ints separated by a ',' character.
// Since this is all dynamic, though, we don't want to actually link
// against the class and use its methods. So we just parse this back
// into int fields manually. Sum them up and ensure that we get the
// expected total for the first column, to verify that we got all the
// results from the db into the file.
int curSum = getFirstInt(val.toString());
int totalResults = 1;
// now sum up everything else in the file.
while (reader.next(key) != null) {
reader.getCurrentValue(val);
curSum += getFirstInt(val.toString());
totalResults++;
}
assertEquals("Total sum of first db column mismatch", expectedSum,
curSum);
assertEquals("Incorrect number of results for query", numExpectedResults,
totalResults);
} catch (InvalidOptionsException ioe) {
fail(ioe.toString());
} catch (ParseException pe) {
fail(pe.toString());
} finally {
IOUtils.closeStream(reader);
if (null != prevClassLoader) {
ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
}
}
}
示例13: runQueryTest
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
public void runQueryTest(String query, boolean tableImport,
int numExpectedResults, int expectedSum, String targetDir,
String... extraArgs) throws IOException {
ClassLoader prevClassLoader = null;
SequenceFile.Reader reader = null;
String [] argv = getArgv(true, tableImport, query, targetDir, extraArgs);
runImport(argv);
try {
SqoopOptions opts = new ImportTool().parseArguments(
getArgv(false, tableImport, query, targetDir, extraArgs),
null, null, true);
CompilationManager compileMgr = new CompilationManager(opts);
String jarFileName = compileMgr.getJarFilename();
prevClassLoader = ClassLoaderStack.addJarFile(jarFileName,
getTableName());
reader = SeqFileReader.getSeqFileReader(getDataFilePath().toString());
// here we can actually instantiate (k, v) pairs.
Configuration conf = new Configuration();
Object key = ReflectionUtils.newInstance(reader.getKeyClass(), conf);
Object val = ReflectionUtils.newInstance(reader.getValueClass(), conf);
if (reader.next(key) == null) {
fail("Empty SequenceFile during import");
}
// make sure that the value we think should be at the top, is.
reader.getCurrentValue(val);
// We know that these values are two ints separated by a ',' character.
// Since this is all dynamic, though, we don't want to actually link
// against the class and use its methods. So we just parse this back
// into int fields manually. Sum them up and ensure that we get the
// expected total for the first column, to verify that we got all the
// results from the db into the file.
int curSum = getFirstInt(val.toString());
int totalResults = 1;
// now sum up everything else in the file.
while (reader.next(key) != null) {
reader.getCurrentValue(val);
curSum += getFirstInt(val.toString());
totalResults++;
}
assertEquals("Total sum of first db column mismatch", expectedSum,
curSum);
assertEquals("Incorrect number of results for query", numExpectedResults,
totalResults);
} catch (InvalidOptionsException ioe) {
fail(ioe.toString());
} catch (ParseException pe) {
fail(pe.toString());
} finally {
IOUtils.closeStream(reader);
if (null != prevClassLoader) {
ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
}
}
}
示例14: runWhereTest
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
public void runWhereTest(String whereClause, String firstValStr,
int numExpectedResults, int expectedSum) throws IOException {
String [] columns = HsqldbTestServer.getFieldNames();
ClassLoader prevClassLoader = null;
SequenceFile.Reader reader = null;
String [] argv = getArgv(true, columns, whereClause);
runImport(argv);
try {
SqoopOptions opts = new ImportTool().parseArguments(
getArgv(false, columns, whereClause),
null, null, true);
CompilationManager compileMgr = new CompilationManager(opts);
String jarFileName = compileMgr.getJarFilename();
prevClassLoader = ClassLoaderStack.addJarFile(jarFileName,
getTableName());
reader = SeqFileReader.getSeqFileReader(getDataFilePath().toString());
// here we can actually instantiate (k, v) pairs.
Configuration conf = new Configuration();
Object key = ReflectionUtils.newInstance(reader.getKeyClass(), conf);
Object val = ReflectionUtils.newInstance(reader.getValueClass(), conf);
if (reader.next(key) == null) {
fail("Empty SequenceFile during import");
}
// make sure that the value we think should be at the top, is.
reader.getCurrentValue(val);
assertEquals("Invalid ordering within sorted SeqFile", firstValStr,
val.toString());
// We know that these values are two ints separated by a ',' character.
// Since this is all dynamic, though, we don't want to actually link
// against the class and use its methods. So we just parse this back
// into int fields manually. Sum them up and ensure that we get the
// expected total for the first column, to verify that we got all the
// results from the db into the file.
int curSum = getFirstInt(val.toString());
int totalResults = 1;
// now sum up everything else in the file.
while (reader.next(key) != null) {
reader.getCurrentValue(val);
curSum += getFirstInt(val.toString());
totalResults++;
}
assertEquals("Total sum of first db column mismatch", expectedSum,
curSum);
assertEquals("Incorrect number of results for query", numExpectedResults,
totalResults);
} catch (InvalidOptionsException ioe) {
fail(ioe.toString());
} catch (ParseException pe) {
fail(pe.toString());
} finally {
IOUtils.closeStream(reader);
if (null != prevClassLoader) {
ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
}
}
}
示例15: testSequenceFileExport
import com.cloudera.sqoop.util.ClassLoaderStack; //导入依赖的package包/类
/** Export some rows from a SequenceFile, make sure they import correctly. */
public void testSequenceFileExport() throws Exception {
final int TOTAL_RECORDS = 10;
// First, generate class and jar files that represent the table
// we're exporting to.
LOG.info("Creating initial schema for SeqFile test");
createTable();
LOG.info("Generating code...");
CodeGenTool codeGen = new CodeGenTool();
String [] codeGenArgs = getCodeGenArgv();
SqoopOptions options = codeGen.parseArguments(
codeGenArgs, null, null, true);
codeGen.validateOptions(options);
int ret = codeGen.run(options);
assertEquals(0, ret);
List<String> generatedJars = codeGen.getGeneratedJarFiles();
// Now, wipe the created table so we can export on top of it again.
LOG.info("Resetting schema and data...");
createTable();
// Wipe the directory we use when creating files to export to ensure
// it's ready for new SequenceFiles.
removeTablePath();
assertNotNull(generatedJars);
assertEquals("Expected 1 generated jar file", 1, generatedJars.size());
String jarFileName = generatedJars.get(0);
// Sqoop generates jars named "foo.jar"; by default, this should contain a
// class named 'foo'. Extract the class name.
Path jarPath = new Path(jarFileName);
String jarBaseName = jarPath.getName();
assertTrue(jarBaseName.endsWith(".jar"));
assertTrue(jarBaseName.length() > ".jar".length());
String className = jarBaseName.substring(0, jarBaseName.length()
- ".jar".length());
LOG.info("Using jar filename: " + jarFileName);
LOG.info("Using class name: " + className);
ClassLoader prevClassLoader = null;
try {
if (null != jarFileName) {
prevClassLoader = ClassLoaderStack.addJarFile(jarFileName, className);
}
// Now use this class and jar name to create a sequence file.
LOG.info("Writing data to SequenceFiles");
createSequenceFile(0, TOTAL_RECORDS, className);
// Now run and verify the export.
LOG.info("Exporting SequenceFile-based data");
runExport(getArgv(true, 10, 10, "--class-name", className,
"--jar-file", jarFileName));
verifyExport(TOTAL_RECORDS);
} finally {
if (null != prevClassLoader) {
ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
}
}
}