2012-09-06 50 views
1

我们使用的是cdh3u4,Hadoop和HBase。我试图运行一个单元测试,在启动HBaseTestingUtility提供的miniMapReduceCluster后启动MapReduce作业。如何让HBaseTestingUtility在地图缩减作业中查找类?

作业失败,这在地图和减速器任务标准错误日志:

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。 我的测试设置的代码如下所示(借口拼写错误,因为这是从斯卡拉翻译):

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 

在这种情况下,重要的是,我们使用的播放!框架2.0(使用SBT)和Specs2测试框架和Scala。我认为这不重要(我们没有使用Java + JUnit)。

有没有人见过这个?任何指向哪里看?

由于提前,

马克

回答

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 
+0

马克,你也许想看看Scoobi:http://nicta.github.com/scoobi。在运行Hadoop作业时,有一些测试特征可能会让您的生活更轻松:http://nicta.github.com/scoobi/guide/Testing%20guide.html#Testing+guide – Eric

相关问题