1

我们正在使用 cdh3u4、Hadoop 和 HBase。我正在尝试运行一个单元测试,在启动 HBaseTestingUtility 提供的 miniMapReduceCluster 后启动 MapReduce 作业。

作业在 map 和 reducer 任务 stderr 日志中失败:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/mapred/Child
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.mapred.Child
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
 Could not find the main class: org.apache.hadoop.mapred.Child.  Program will exit.
java.lang.Throwable: Child Error

这几天我一直在想办法解决这个问题。我猜这是一个错误的配置,并且由于 fs / hdfs 配置值配置错误,集群没有找到我的任何 jar。我的测试设置代码如下所示(请原谅拼写错误,因为这是从 Scala 翻译的):

HBaseTestingUtility htest = new HBaseTestingUtility();
Configuration c = htest.getConfiguration();
c.set("hadoop.log.dir", "/tmp/hadoop-test-logs"); // required or else can't start the miniMapReduceCluster
htest.startMiniCluster();
htest.startMiniMapReduceCluster();

// create and run a MapReduce job that works in production but not in test

如果这很重要,我们正在使用 Play!带有 Specs2 测试框架和 Scala 的框架 2.0(使用 SBT)。我认为这无关紧要(我们没有使用 Java + JUnit)。

有没有人见过这个?关于在哪里看的任何指示?

提前致谢,

标记

4

2 回答 2

0

事实证明,我们必须在 minicuster 上手动设置类路径。这可能是 SBT / Ivy 的事情 - 因为我见过的所有示例都不必这样做,并且可能使用 Maven(和 Java)。

这是我解决类路径问题的方法(在 Scala 中):

// unit test setup:
val htest = new HBaseTestingUtility
htest.startMiniCluster()

val conf = htest.getConfiguration
conf.set("hadoop.log.dir", "/tmp/hadoop-test-logs") // required to prevent NPE when starting miniMapReduceCluster
htest.startMiniMapReduceCluster()

// Set up cluster classpath:
val fs = FileSystem.get(conf)
val jarsDir = new Path("/tmp/hadoop-test-lib")
fs.mkdirs(jarsDir)

// copy jars over to hdfs and add to classpath:
for (jar <- myjars) {
    val localJarPath = new Path("file://%s".format(jar.getAbsolutePath))
    val hdfsJarPath = new Path("/tmp/hadoop-test-lib/%s".format(jar.getName))
    fs.copyFromLocalFile(localJarPath, hdfsJarPath)
    DistributedCache.addFileToClassPath(hdfsJarPath)
}

// now Map and Reduce tasks can find classes
于 2012-09-10T15:11:20.957 回答
0

我确实编译了一个博客: http: //mevivs.wordpress.com/2012/05/03/perform-crud-over-hbase-using-hbasetestingutilityembeddedhbase/

看看这个。

希望能帮助到你。

-维维克

于 2012-09-13T06:36:54.917 回答