2015-12-11 18 views
6

をテスト:単位でTestHiveContext/HiveContextを使用すると、私はユニットテストでこれをやろうとしている

val sConf = new SparkConf() 
    .setAppName("RandomAppName") 
    .setMaster("local") 
val sc = new SparkContext(sConf) 
val sqlContext = new TestHiveContext(sc) // tried new HiveContext(sc) as well 

しかし、私はこの取得:私は火花防止型を使用して実行すると、コードは完璧に動作

[scalatest] Exception encountered when invoking run on a nested suite - java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient *** ABORTED *** 
[scalatest] java.lang.RuntimeException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient 
[scalatest] at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:346) 
[scalatest] at org.apache.spark.sql.hive.client.ClientWrapper.<init>(ClientWrapper.scala:120) 
[scalatest] at org.apache.spark.sql.hive.HiveContext.executionHive$lzycompute(HiveContext.scala:163) 
[scalatest] at org.apache.spark.sql.hive.HiveContext.executionHive(HiveContext.scala:161) 
[scalatest] at org.apache.spark.sql.hive.HiveContext.<init>(HiveContext.scala:168) 
[scalatest] at org.apache.spark.sql.hive.test.TestHiveContext.<init>(TestHive.scala:72) 
[scalatest] at mypackage.NewHiveTest.beforeAll(NewHiveTest.scala:48) 
[scalatest] at org.scalatest.BeforeAndAfterAll$class.beforeAll(BeforeAndAfterAll.scala:187) 
[scalatest] at mypackage.NewHiveTest.beforeAll(NewHiveTest.scala:35) 
[scalatest] at org.scalatest.BeforeAndAfterAll$class.run(BeforeAndAfterAll.scala:253) 
[scalatest] at mypackage.NewHiveTest.run(NewHiveTest.scala:35) 
[scalatest] at org.scalatest.Suite$class.callExecuteOnSuite$1(Suite.scala:1491) 

を提出するが、単体テストではない。 単体テストでこれを修正するにはどうすればよいですか?

答えて

2

私はspark-testing-baseを使用して終了、それは古い質問ですが、私は同様の問題に遭遇した:

import com.holdenkarau.spark.testing.SharedSparkContext 
import org.apache.spark.sql.hive.test.TestHiveContext 
import org.scalatest.FunSuite 

class RowToProtoMapper$Test extends FunSuite with SharedSparkContext { 

    test("route mapping") { 
     val hc = new TestHiveContext(sc) 
     /* Some test */ 
    } 
} 
+0

私の場合、私は 'ヴァルHC =新しいTestHiveContext(SC)が行でnullポインタ例外を取得' – Explorer

関連する問題