Last active
September 15, 2017 07:47
-
-
Save angelcervera/d4e878cb63a021ad039d5db65aa5f253 to your computer and use it in GitHub Desktop.
Example of common Spark Test setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.apache.spark.{SparkConf, SparkContext} | |
| import org.scalatest.{BeforeAndAfterAll, Suite} | |
| trait SparkTestSetup extends BeforeAndAfterAll { this: Suite => | |
| // Overwrite if it is neccesary | |
| def master = "local[4]" | |
| def appName: String | |
| def defaultSparkConf = new SparkConf().setAppName(appName).setMaster(master) | |
| var sc: SparkContext = _ | |
| override def beforeAll(): Unit = { | |
| sc = new SparkContext(defaultSparkConf) | |
| super.beforeAll() | |
| } | |
| override def afterAll(): Unit = { | |
| try { | |
| super.afterAll() | |
| } | |
| finally { | |
| if(!sc.isStopped) sc.stop() | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment