首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让HBaseTestingUtility在map reduce作业中查找类?

如何让HBaseTestingUtility在map reduce作业中查找类?
EN

Stack Overflow用户
提问于 2012-09-07 05:56:18
回答 2查看 2.4K关注 0票数 1

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

作业失败,并在map和reducer任务stderr日志中显示以下内容:

代码语言:javascript
复制
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翻译过来的):

代码语言:javascript
复制
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)。

以前有没有人见过这个?你有什么建议去哪里找吗?

提前谢谢你,

标记

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-10 23:11:21

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

下面是我是如何解决类路径问题的(在Scala中):

代码语言:javascript
复制
// 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
票数 0
EN

Stack Overflow用户

发布于 2012-09-13 14:36:55

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

看看这个。

希望能有所帮助。

-Vivek

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12308980

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档