当前位置: 首页>>代码示例>>Java>>正文


Java ClassLoaderStack.setCurrentClassLoader方法代码示例

本文整理汇总了Java中com.cloudera.sqoop.util.ClassLoaderStack.setCurrentClassLoader方法的典型用法代码示例。如果您正苦于以下问题:Java ClassLoaderStack.setCurrentClassLoader方法的具体用法?Java ClassLoaderStack.setCurrentClassLoader怎么用?Java ClassLoaderStack.setCurrentClassLoader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.cloudera.sqoop.util.ClassLoaderStack的用法示例。


在下文中一共展示了ClassLoaderStack.setCurrentClassLoader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:10,代码来源:ImportTool.java

示例2: 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);
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:10,代码来源:JobBase.java

示例3: 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);
    }
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:75,代码来源:SQLServerQueryManualTest.java

示例4: 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);
    }
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:67,代码来源:SQLServerSplitByManualTest.java

示例5: 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

示例6: 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);
    }
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:78,代码来源:SQLServerMultiMapsManualTest.java

示例7: 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);
  }
 }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:77,代码来源:SQLServerWhereManualTest.java

示例8: 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);
    }
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:69,代码来源:TestQuery.java

示例9: 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);
    }
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:67,代码来源:TestBoundaryQuery.java

示例10: 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);
    }
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:69,代码来源:TestWhere.java

示例11: 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);
    }
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:65,代码来源:TestExport.java

示例12: runSplitByTest

import com.cloudera.sqoop.util.ClassLoaderStack; //导入方法依赖的package包/类
public void runSplitByTest(String splitByCol, int expectedSum)
    throws IOException {

  String [] columns = HsqldbTestServer.getFieldNames();
  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());
    }

    assertEquals("Total sum of first db column mismatch", expectedSum,
        curSum);
  } catch (InvalidOptionsException ioe) {
    fail(ioe.toString());
  } catch (ParseException pe) {
    fail(pe.toString());
  } finally {
    IOUtils.closeStream(reader);

    if (null != prevClassLoader) {
      ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
    }
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:57,代码来源:TestSplitBy.java

示例13: runMultiMapTest

import com.cloudera.sqoop.util.ClassLoaderStack; //导入方法依赖的package包/类
public void runMultiMapTest(String splitByCol, int expectedSum)
    throws IOException {

  String [] columns = HsqldbTestServer.getFieldNames();
  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);

    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) {
    fail(ioe.toString());
  } catch (ParseException pe) {
    fail(pe.toString());
  } finally {
    IOUtils.closeStream(reader);

    if (null != prevClassLoader) {
      ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
    }
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:66,代码来源:TestMultiMaps.java

示例14: testCloningTableWithVarbinaryDoesNotThrowNPE

import com.cloudera.sqoop.util.ClassLoaderStack; //导入方法依赖的package包/类
@Test
public void testCloningTableWithVarbinaryDoesNotThrowNPE() throws SQLException,
    IOException, ClassNotFoundException, NoSuchMethodException,
    SecurityException, InstantiationException, IllegalAccessException,
    IllegalArgumentException, InvocationTargetException {
  String tableName = HsqldbTestServer.getTableName();
  Connection connection = testServer.getConnection();
  Statement st = connection.createStatement();
  try {
    st.executeUpdate("DROP TABLE " + tableName + " IF EXISTS");
    st.executeUpdate("CREATE TABLE " + tableName
        + " (id INT, test VARBINARY(10))");
    connection.commit();
  } finally {
    st.close();
    connection.close();
  }

  String [] argv = {
    "--bindir",
    JAR_GEN_DIR,
    "--outdir",
    CODE_GEN_DIR,
    "--package-name",
    OVERRIDE_PACKAGE_NAME,
  };

  String className = OVERRIDE_PACKAGE_NAME + "."
      + HsqldbTestServer.getTableName();
  File ormJarFile = runGenerationTest(argv, className);

  ClassLoader prevClassLoader = ClassLoaderStack.addJarFile(
      ormJarFile.getCanonicalPath(), className);
  Class tableClass = Class.forName(className, true,
      Thread.currentThread().getContextClassLoader());
  Method cloneImplementation = tableClass.getMethod("clone");

  Object instance = tableClass.newInstance();

  assertTrue(cloneImplementation.invoke(instance).getClass().
      getCanonicalName().equals(className));

  if (null != prevClassLoader) {
    ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:47,代码来源:TestClassWriter.java

示例15: testEqualsMethod

import com.cloudera.sqoop.util.ClassLoaderStack; //导入方法依赖的package包/类
/**
 * Test the generated equals method.
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws NoSuchMethodException
 * @throws SecurityException
 * @throws InvocationTargetException
 * @throws IllegalArgumentException
 */
@Test
public void testEqualsMethod() throws IOException, ClassNotFoundException,
    InstantiationException, IllegalAccessException, NoSuchMethodException,
    InvocationTargetException {

  // Set the option strings in an "argv" to redirect our srcdir and bindir
  String [] argv = {
    "--bindir",
    JAR_GEN_DIR,
    "--outdir",
    CODE_GEN_DIR,
    "--class-name",
    OVERRIDE_CLASS_AND_PACKAGE_NAME,
  };

  File ormJarFile = runGenerationTest(argv, OVERRIDE_CLASS_AND_PACKAGE_NAME);
  ClassLoader prevClassLoader = ClassLoaderStack.addJarFile(
      ormJarFile.getCanonicalPath(),
      OVERRIDE_CLASS_AND_PACKAGE_NAME);
  Class tableClass = Class.forName(
      OVERRIDE_CLASS_AND_PACKAGE_NAME,
      true,
      Thread.currentThread().getContextClassLoader());
  Method setterIntField1 =
      tableClass.getMethod("set_INTFIELD1", Integer.class);
  Method setterIntField2 =
      tableClass.getMethod("set_INTFIELD2", Integer.class);
  Method equalsImplementation = tableClass.getMethod("equals", Object.class);

  Object instance1 = tableClass.newInstance();
  Object instance2 = tableClass.newInstance();

  // test reflexivity
  assertTrue((Boolean) equalsImplementation.invoke(instance1, instance1));

  // test equality for uninitialized fields
  assertTrue((Boolean) equalsImplementation.invoke(instance1, instance2));

  // test symmetry
  assertTrue((Boolean) equalsImplementation.invoke(instance2, instance1));

  // test reflexivity with initialized fields
  setterIntField1.invoke(instance1, new Integer(1));
  setterIntField2.invoke(instance1, new Integer(2));
  assertTrue((Boolean) equalsImplementation.invoke(instance1, instance1));

  // test difference in both fields
  setterIntField1.invoke(instance2, new Integer(3));
  setterIntField2.invoke(instance2, new Integer(4));
  assertFalse((Boolean) equalsImplementation.invoke(instance1, instance2));

  // test difference in second field
  setterIntField1.invoke(instance2, new Integer(1));
  setterIntField2.invoke(instance2, new Integer(3));
  assertFalse((Boolean) equalsImplementation.invoke(instance1, instance2));

  // test difference in first field
  setterIntField1.invoke(instance2, new Integer(3));
  setterIntField2.invoke(instance2, new Integer(2));
  assertFalse((Boolean) equalsImplementation.invoke(instance1, instance2));

  // test equality for initialized fields
  setterIntField1.invoke(instance2, new Integer(1));
  setterIntField2.invoke(instance2, new Integer(2));
  assertTrue((Boolean) equalsImplementation.invoke(instance1, instance2));

  if (null != prevClassLoader) {
    ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:82,代码来源:TestClassWriter.java


注:本文中的com.cloudera.sqoop.util.ClassLoaderStack.setCurrentClassLoader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。