2012-09-06 47 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

相關問題