object SparkSpecs extends MustMatchers {
import SparkUtils._
def main(args: Array[String]) {
val data = < read file from hdfs>
val output = data.flatMap { record =>
val spec = new DataSpec(record)
val (message, result) = spec.executeItNow // <- I want to execute this now and get the result
if (result.isFailure) {
Some(record, message)
} else {
None
}
}
sc.writeAsTextFile("bla")
}
}
class DataSpec(record: Record) extends org.specs2.Specification {
def is = s2"""
a record
must have a non-empty cidd $e1
tt must be 2 $e2
"""
def e1 = record.ciid must beSome
def e2 = record.tt must_== 2
}
Thank!
Alex
import org.specs2.specification.core.{Fragment, Env, Fragments}
val fs: Fragments =
s2"""|
|The record must have a non-empty cid
| ${record.ciid must beSome}
|
|tt must be 2 ${record.tt must_== 2}
|""".stripMargin
def report(f: Fragment): Option[String] = {
val result = f.executionResult
if (result.isSuccess) None
else Some(s"[fail] ${f.description.show}: ${result.message}")
}
println {
fs.examples.map(_.updateExecution(_.execute(Env()))).map(report).flatten.mkString("\n")
}