我们使用的是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)。
以前有没有人见过这个?你有什么建议去哪里找吗?
提前谢谢你,
标记
发布于 2012-09-10 23:11:21
事实证明,我们必须在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-13 14:36:55
我编辑了一个博客:http://mevivs.wordpress.com/2012/05/03/perform-crud-over-hbase-using-hbasetestingutilityembeddedhbase/
看看这个。
希望能有所帮助。
-Vivek
https://stackoverflow.com/questions/12308980
复制相似问题