package com.chapter16.SparkTesting import org.scalatest.{ BeforeAndAfterAll, FunSuite } import org.scalatest.Assertions._ import org.apache.spark.sql.SparkSession import org.apache.spark.rdd.RDD class wordCountTest2 extends FunSuite with BeforeAndAfterAll { var spark: SparkSession = null def tokenize(line: RDD[String]) = { line.map(x => x.split(' ')).collect() } override def beforeAll() { spark = SparkSession .builder .master("local[*]") .config("spark.sql.warehouse.dir", "E:/Exp/") .appName(s"OneVsRestExample") .getOrCreate() } test("Test if two RDDs are equal") { val input = List("To be,", "or not to be:", "that is the question-", "William Shakespeare") val expected = Array(Array("To", "be,"), Array("or", "not", "to", "be:"), Array("that", "is", "the", "question-"), Array("William", "Shakespeare")) val transformed = tokenize(spark.sparkContext.parallelize(input)) assert(transformed === expected) } test("Test for word count RDD") { val fileName = "C:/Users/rezkar/Downloads/words.txt" val obj = new wordCountRDD val result = obj.prepareWordCountRDD(fileName, spark) assert(result.count() === 214) } override def afterAll() { spark.stop() } }
No comments:
Post a Comment